Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: deprecate vm.runInDebugContext #12815

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ a V8-inspector based CLI debugger available through `node inspect`.
<a id="DEP0069"></a>
### 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+.
Expand Down
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should go in separately with v8.x.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be REPLACEME rather than listing a specific version here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyGu Done (but deprecated: v8.0.0 is correct since that’s when we docs-deprecated)

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