diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 75c5c0feb5..10db311e88 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -598,7 +598,7 @@ a V8-inspector based CLI debugger available through `node inspect`. ### DEP0069: vm.runInDebugContext(string) -Type: Documentation-only +Type: Runtime The DebugContext will be removed in V8 soon and will not be available in Node 10+. diff --git a/doc/api/vm.md b/doc/api/vm.md index 230054cba9..3dd7a3c8dc 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -313,6 +313,11 @@ console.log(util.inspect(sandbox)); ## vm.runInDebugContext(code) > Stability: 0 - Deprecated. An alternative is in development. diff --git a/lib/util.js b/lib/util.js index 2574c2dd66..b97b1ede0c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -385,7 +385,11 @@ function stylizeNoColor(str, styleType) { function ensureDebugIsInitialized() { if (Debug === undefined) { const runInDebugContext = require('vm').runInDebugContext; + // a workaround till this entire method is removed + const originalValue = process.noDeprecation; + process.noDeprecation = true; Debug = runInDebugContext('Debug'); + process.noDeprecation = originalValue; } } diff --git a/lib/vm.js b/lib/vm.js index f4a5d7443b..e083325483 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -27,7 +27,7 @@ const { makeContext, isContext, - runInDebugContext + runInDebugContext: runInDebugContext_ } = process.binding('contextify'); const { moveMessagePortToContext } = internalBinding('messaging'); @@ -107,6 +107,19 @@ function sigintHandlersWrap(fn, thisArg, argsArray) { } } +let runInDebugContextWarned = false; +function runInDebugContext(code) { + if (runInDebugContextWarned === false) { + runInDebugContextWarned = true; + process.emitWarning( + 'DebugContext has been deprecated and will be removed in a ' + + 'future version.', + 'DeprecationWarning', + 'DEP0069'); + } + return runInDebugContext_(code); +} + function runInContext(code, contextifiedSandbox, options) { if (typeof options === 'string') { options = { diff --git a/test/parallel/test-vm-debug-context.js b/test/parallel/test-vm-debug-context.js index 314c9fa065..ec6ddfa525 100644 --- a/test/parallel/test-vm-debug-context.js +++ b/test/parallel/test-vm-debug-context.js @@ -27,6 +27,11 @@ const vm = require('vm'); const { spawn } = require('child_process'); const fixtures = require('../common/fixtures'); +const msg = 'DebugContext has been deprecated and will be removed in ' + + 'a future version.'; +common.expectWarning('DeprecationWarning', msg); +vm.runInDebugContext(); + assert.throws(function() { vm.runInDebugContext('*'); }, /SyntaxError/);