Skip to content
This repository was archived by the owner on Aug 31, 2018. It is now read-only.

Commit 09d80f2

Browse files
joshgavaddaleax
authored andcommitted
vm: deprecate vm.runInDebugContext
PR-URL: nodejs/node#12815 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 19ccb55 commit 09d80f2

5 files changed

Lines changed: 29 additions & 2 deletions

File tree

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
@@ -331,6 +331,11 @@ or receiving further messages.
331331
## vm.runInDebugContext(code)
332332
<!-- YAML
333333
added: v0.11.14
334+
deprecated: v8.0.0
335+
changes:
336+
- version: REPLACEME
337+
pr-url: https://github.com/nodejs/node/pull/12815
338+
description: Calling this function now emits a deprecation warning.
334339
-->
335340

336341
> 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
const { moveMessagePortToContext } = internalBinding('messaging');
@@ -107,6 +107,19 @@ function sigintHandlersWrap(fn, thisArg, argsArray) {
107107
}
108108
}
109109

110+
let runInDebugContextWarned = false;
111+
function runInDebugContext(code) {
112+
if (runInDebugContextWarned === false) {
113+
runInDebugContextWarned = true;
114+
process.emitWarning(
115+
'DebugContext has been deprecated and will be removed in a ' +
116+
'future version.',
117+
'DeprecationWarning',
118+
'DEP0069');
119+
}
120+
return runInDebugContext_(code);
121+
}
122+
110123
function runInContext(code, contextifiedSandbox, options) {
111124
if (typeof options === 'string') {
112125
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)