Skip to content

Commit

Permalink
vm: deprecate vm.runInDebugContext
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgav authored and addaleax committed Oct 22, 2017
1 parent 438e7fd commit 66fa03d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions doc/api/vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ console.log(util.inspect(sandbox));
## vm.runInDebugContext(code)
<!-- YAML
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.
Expand Down
4 changes: 4 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
15 changes: 14 additions & 1 deletion lib/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const {

makeContext,
isContext,
runInDebugContext
runInDebugContext: runInDebugContext_
} = process.binding('contextify');

// The binding provides a few useful primitives:
Expand Down Expand Up @@ -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) {
if (typeof options === 'string') {
options = {
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-vm-debug-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down

0 comments on commit 66fa03d

Please sign in to comment.