Skip to content

Commit 88e55fe

Browse files
joshgavaddaleax
authored andcommitted
vm: deprecate vm.runInDebugContext
PR-URL: #12815 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 3e25e4d commit 88e55fe

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

doc/api/deprecations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ a V8-inspector based CLI debugger available through `node inspect`.
598598
<a id="DEP0069"></a>
599599
### DEP0069: vm.runInDebugContext(string)
600600

601-
Type: Documentation-only
601+
Type: Runtime
602602

603603
The DebugContext will be removed in V8 soon and will not be available in Node
604604
10+.

doc/api/vm.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ console.log(util.inspect(sandbox));
313313
## vm.runInDebugContext(code)
314314
<!-- YAML
315315
added: v0.11.14
316+
deprecated: v8.0.0
317+
changes:
318+
- version: REPLACEME
319+
pr-url: https://github.com/nodejs/node/pull/12815
320+
description: Calling this function now emits a deprecation warning.
316321
-->
317322

318323
> Stability: 0 - Deprecated. An alternative is in development.

lib/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,11 @@ function stylizeNoColor(str, styleType) {
385385
function ensureDebugIsInitialized() {
386386
if (Debug === undefined) {
387387
const runInDebugContext = require('vm').runInDebugContext;
388+
// a workaround till this entire method is removed
389+
const originalValue = process.noDeprecation;
390+
process.noDeprecation = true;
388391
Debug = runInDebugContext('Debug');
392+
process.noDeprecation = originalValue;
389393
}
390394
}
391395

lib/vm.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const {
2727

2828
makeContext,
2929
isContext,
30-
runInDebugContext
30+
runInDebugContext: runInDebugContext_
3131
} = process.binding('contextify');
3232

3333
// The binding provides a few useful primitives:
@@ -105,6 +105,19 @@ function sigintHandlersWrap(fn, thisArg, argsArray) {
105105
}
106106
}
107107

108+
let runInDebugContextWarned = false;
109+
function runInDebugContext(code) {
110+
if (runInDebugContextWarned === false) {
111+
runInDebugContextWarned = true;
112+
process.emitWarning(
113+
'DebugContext has been deprecated and will be removed in a ' +
114+
'future version.',
115+
'DeprecationWarning',
116+
'DEP0069');
117+
}
118+
return runInDebugContext_(code);
119+
}
120+
108121
function runInContext(code, contextifiedSandbox, options) {
109122
if (typeof options === 'string') {
110123
options = {

test/parallel/test-vm-debug-context.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ const vm = require('vm');
2727
const { spawn } = require('child_process');
2828
const fixtures = require('../common/fixtures');
2929

30+
const msg = 'DebugContext has been deprecated and will be removed in ' +
31+
'a future version.';
32+
common.expectWarning('DeprecationWarning', msg);
33+
vm.runInDebugContext();
34+
3035
assert.throws(function() {
3136
vm.runInDebugContext('*');
3237
}, /SyntaxError/);

0 commit comments

Comments
 (0)