vm: deprecate vm.runInDebugContext

PR-URL: https://github.com/nodejs/node/pull/12815
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Josh Gavant 2017-05-03 12:02:03 -07:00 committed by Anna Henningsen
parent 3e25e4d00f
commit 88e55fe5e0
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
5 changed files with 29 additions and 2 deletions

View File

@ -598,7 +598,7 @@ a V8-inspector based CLI debugger available through `node inspect`.
<a id="DEP0069"></a> <a id="DEP0069"></a>
### DEP0069: vm.runInDebugContext(string) ### DEP0069: vm.runInDebugContext(string)
Type: Documentation-only Type: Runtime
The DebugContext will be removed in V8 soon and will not be available in Node The DebugContext will be removed in V8 soon and will not be available in Node
10+. 10+.

View File

@ -313,6 +313,11 @@ console.log(util.inspect(sandbox));
## vm.runInDebugContext(code) ## vm.runInDebugContext(code)
<!-- YAML <!-- YAML
added: v0.11.14 added: v0.11.14
deprecated: v8.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/12815
description: Calling this function now emits a deprecation warning.
--> -->
> Stability: 0 - Deprecated. An alternative is in development. > Stability: 0 - Deprecated. An alternative is in development.

View File

@ -385,7 +385,11 @@ function stylizeNoColor(str, styleType) {
function ensureDebugIsInitialized() { function ensureDebugIsInitialized() {
if (Debug === undefined) { if (Debug === undefined) {
const runInDebugContext = require('vm').runInDebugContext; const runInDebugContext = require('vm').runInDebugContext;
// a workaround till this entire method is removed
const originalValue = process.noDeprecation;
process.noDeprecation = true;
Debug = runInDebugContext('Debug'); Debug = runInDebugContext('Debug');
process.noDeprecation = originalValue;
} }
} }

View File

@ -27,7 +27,7 @@ const {
makeContext, makeContext,
isContext, isContext,
runInDebugContext runInDebugContext: runInDebugContext_
} = process.binding('contextify'); } = process.binding('contextify');
// The binding provides a few useful primitives: // The binding provides a few useful primitives:
@ -105,6 +105,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) { function runInContext(code, contextifiedSandbox, options) {
if (typeof options === 'string') { if (typeof options === 'string') {
options = { options = {

View File

@ -27,6 +27,11 @@ const vm = require('vm');
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const fixtures = require('../common/fixtures'); 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() { assert.throws(function() {
vm.runInDebugContext('*'); vm.runInDebugContext('*');
}, /SyntaxError/); }, /SyntaxError/);