|
18 | 18 |
|
19 | 19 | /** @const */ var vm = require('vm'); |
20 | 20 | /** @const */ var path = require('path'); |
21 | | -/** @const */ //var util = require('util'); |
| 21 | +/** @const */ var semver = require('semver'); |
22 | 22 |
|
23 | 23 | /** @const */ var state = require('./state.js'); |
24 | 24 | /** @const */ var logModule = require('@google/cloud-diagnostics-common').logger; |
@@ -61,29 +61,23 @@ module.exports.create = function(logger_, config_, fileStats_) { |
61 | 61 | var breakpoints = {}; |
62 | 62 | var listeners = {}; |
63 | 63 | var numBreakpoints = 0; |
64 | | - var usePermanentListener = true; |
| 64 | + // Before V8 4.5, having a debug listener active disables optimization. To |
| 65 | + // deal with this we only activate the listener when there is a breakpoint |
| 66 | + // active, and remote it as soon as the snapshot is taken. Furthermore, 4.5 |
| 67 | + // changes the API such that Debug.scripts() crashes unless a listener is |
| 68 | + // active. We use a permanent listener on V8 4.5+. |
| 69 | + var v8_version = /(\d+\.\d+\.\d+)\.\d+/.exec(process.versions.v8); |
| 70 | + if (!v8_version || v8_version.length < 2) { |
| 71 | + return null; |
| 72 | + } |
| 73 | + var usePermanentListener = semver.satisfies(v8_version[1], '>=4.5'); |
65 | 74 |
|
66 | 75 | // Node.js v0.11+ have the runInDebugContext method that can be used to fetch |
67 | 76 | // the API object. |
68 | 77 | if (!vm.runInDebugContext) { |
69 | 78 | return null; |
70 | 79 | } |
71 | 80 |
|
72 | | - // Before V8 4.6, having a debug listener active disables optimization. To |
73 | | - // deal with this we only activate the listener when there is a breakpoint |
74 | | - // active, and remote it as soon as the snapshot is taken. Furthermore, 4.6 |
75 | | - // changes the API such that Debug.scripts() crashes unless a listener is |
76 | | - // active. We use a permanent listener on V8 4.6+. |
77 | | - var result = /(\d+)\.(\d+)\.\d+\.\d+/.exec(process.versions.v8); |
78 | | - if (!result) { |
79 | | - // malformed V8 version? |
80 | | - return null; |
81 | | - } |
82 | | - if (parseInt(result[1], 10) < 4 || |
83 | | - parseInt(result[2], 10) < 5) { |
84 | | - usePermanentListener = false; |
85 | | - } |
86 | | - |
87 | 81 | v8 = vm.runInDebugContext('Debug'); |
88 | 82 | logger = logger_; |
89 | 83 | config = config_; |
|
0 commit comments