Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Add support for Node.js v6
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Loring committed Apr 26, 2016
1 parent 225af35 commit 442e1bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ node_js:
- '0.12'
- '4'
- '5'
- '6'
script:
- ./bin/run-test.sh -c
28 changes: 11 additions & 17 deletions lib/v8debugapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/** @const */ var vm = require('vm');
/** @const */ var path = require('path');
/** @const */ //var util = require('util');
/** @const */ var semver = require('semver');

/** @const */ var state = require('./state.js');
/** @const */ var logModule = require('@google/cloud-diagnostics-common').logger;
Expand Down Expand Up @@ -61,29 +61,23 @@ module.exports.create = function(logger_, config_, fileStats_) {
var breakpoints = {};
var listeners = {};
var numBreakpoints = 0;
var usePermanentListener = true;
// Before V8 4.5, having a debug listener active disables optimization. To
// deal with this we only activate the listener when there is a breakpoint
// active, and remote it as soon as the snapshot is taken. Furthermore, 4.5
// changes the API such that Debug.scripts() crashes unless a listener is
// active. We use a permanent listener on V8 4.5+.
var v8_version = /(\d+\.\d+\.\d+)\.\d+/.exec(process.versions.v8);
if (!v8_version || v8_version.length < 2) {
return null;
}
var usePermanentListener = semver.satisfies(v8_version[1], '>=4.5');

// Node.js v0.11+ have the runInDebugContext method that can be used to fetch
// the API object.
if (!vm.runInDebugContext) {
return null;
}

// Before V8 4.6, having a debug listener active disables optimization. To
// deal with this we only activate the listener when there is a breakpoint
// active, and remote it as soon as the snapshot is taken. Furthermore, 4.6
// changes the API such that Debug.scripts() crashes unless a listener is
// active. We use a permanent listener on V8 4.6+.
var result = /(\d+)\.(\d+)\.\d+\.\d+/.exec(process.versions.v8);
if (!result) {
// malformed V8 version?
return null;
}
if (parseInt(result[1], 10) < 4 ||
parseInt(result[2], 10) < 5) {
usePermanentListener = false;
}

v8 = vm.runInDebugContext('Debug');
logger = logger_;
config = config_;
Expand Down

0 comments on commit 442e1bd

Please sign in to comment.