Skip to content

Commit 6f724e1

Browse files
committed
lib,src: remove vm.runInDebugContext()
The V8 API it is based on is deprecated and scheduled for removal later this year. Remove it. PR-URL: #13295 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Robert Jefe Lindstaedt <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
1 parent 05948d8 commit 6f724e1

10 files changed

+8
-219
lines changed

doc/api/deprecations.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,9 @@ a V8-inspector based CLI debugger available through `node inspect`.
600600
<a id="DEP0069"></a>
601601
### DEP0069: vm.runInDebugContext(string)
602602

603-
Type: Runtime
603+
Type: End-of-Life
604604

605-
The DebugContext will be removed in V8 soon and will not be available in Node
606-
10+.
605+
DebugContext has been removed in V8 and is not available in Node 10+.
607606

608607
*Note*: DebugContext was an experimental API.
609608

doc/api/vm.md

-31
Original file line numberDiff line numberDiff line change
@@ -334,36 +334,6 @@ console.log(util.inspect(sandbox));
334334
// { globalVar: 1024 }
335335
```
336336

337-
## vm.runInDebugContext(code)
338-
<!-- YAML
339-
added: v0.11.14
340-
deprecated: v8.0.0
341-
changes:
342-
- version: v9.0.0
343-
pr-url: https://github.com/nodejs/node/pull/12815
344-
description: Calling this function now emits a deprecation warning.
345-
-->
346-
347-
> Stability: 0 - Deprecated. An alternative is in development.
348-
349-
* `code` {string} The JavaScript code to compile and run.
350-
351-
The `vm.runInDebugContext()` method compiles and executes `code` inside the V8
352-
debug context. The primary use case is to gain access to the V8 `Debug` object:
353-
354-
```js
355-
const vm = require('vm');
356-
const Debug = vm.runInDebugContext('Debug');
357-
console.log(Debug.findScript(process.emit).name); // 'events.js'
358-
console.log(Debug.findScript(process.exit).name); // 'internal/process.js'
359-
```
360-
361-
*Note*: The debug context and object are intrinsically tied to V8's debugger
362-
implementation and may change (or even be removed) without prior warning.
363-
364-
The `Debug` object can also be made available using the V8-specific
365-
`--expose_debug_as=` [command line option][].
366-
367337
## vm.runInNewContext(code[, sandbox][, options])
368338
<!-- YAML
369339
added: v0.3.1
@@ -517,7 +487,6 @@ associating it with the `sandbox` object is what this document refers to as
517487
[`vm.runInContext()`]: #vm_vm_runincontext_code_contextifiedsandbox_options
518488
[`vm.runInThisContext()`]: #vm_vm_runinthiscontext_code_options
519489
[V8 Embedder's Guide]: https://github.com/v8/v8/wiki/Embedder's%20Guide#contexts
520-
[command line option]: cli.html
521490
[contextified]: #vm_what_does_it_mean_to_contextify_an_object
522491
[global object]: https://es5.github.io/#x15.1
523492
[indirect `eval()` call]: https://es5.github.io/#x10.4.2

lib/module.js

-4
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,6 @@ Module.prototype._compile = function(content, filename) {
629629
if (filename === resolvedArgv) {
630630
delete process._breakFirstLine;
631631
inspectorWrapper = process.binding('inspector').callAndPauseOnStart;
632-
if (!inspectorWrapper) {
633-
const Debug = vm.runInDebugContext('Debug');
634-
Debug.setBreakPoint(compiledWrapper, 0, 0);
635-
}
636632
}
637633
}
638634
var dirname = path.dirname(filename);

lib/vm.js

-15
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const {
2727

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

3332
// The binding provides a few useful primitives:
@@ -105,19 +104,6 @@ function sigintHandlersWrap(fn, thisArg, argsArray) {
105104
}
106105
}
107106

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-
121107
function runInContext(code, contextifiedSandbox, options) {
122108
if (typeof options === 'string') {
123109
options = {
@@ -156,7 +142,6 @@ module.exports = {
156142
Script,
157143
createContext,
158144
createScript,
159-
runInDebugContext,
160145
runInContext,
161146
runInNewContext,
162147
runInThisContext,

src/node_contextify.cc

-33
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@
2222
#include "node_internals.h"
2323
#include "node_watchdog.h"
2424
#include "base_object-inl.h"
25-
#include "v8-debug.h"
2625

2726
namespace node {
2827

2928
using v8::Array;
3029
using v8::ArrayBuffer;
3130
using v8::Boolean;
3231
using v8::Context;
33-
using v8::Debug;
3432
using v8::EscapableHandleScope;
3533
using v8::External;
3634
using v8::Function;
@@ -218,42 +216,11 @@ class ContextifyContext {
218216
function_template->InstanceTemplate()->SetInternalFieldCount(1);
219217
env->set_script_data_constructor_function(function_template->GetFunction());
220218

221-
env->SetMethod(target, "runInDebugContext", RunInDebugContext);
222219
env->SetMethod(target, "makeContext", MakeContext);
223220
env->SetMethod(target, "isContext", IsContext);
224221
}
225222

226223

227-
static void RunInDebugContext(const FunctionCallbackInfo<Value>& args) {
228-
Local<String> script_source(args[0]->ToString(args.GetIsolate()));
229-
if (script_source.IsEmpty())
230-
return; // Exception pending.
231-
Local<Context> debug_context = Debug::GetDebugContext(args.GetIsolate());
232-
Environment* env = Environment::GetCurrent(args);
233-
if (debug_context.IsEmpty()) {
234-
// Force-load the debug context.
235-
auto dummy_event_listener = [] (const Debug::EventDetails&) {};
236-
Debug::SetDebugEventListener(args.GetIsolate(), dummy_event_listener);
237-
debug_context = Debug::GetDebugContext(args.GetIsolate());
238-
CHECK(!debug_context.IsEmpty());
239-
// Ensure that the debug context has an Environment assigned in case
240-
// a fatal error is raised. The fatal exception handler in node.cc
241-
// is not equipped to deal with contexts that don't have one and
242-
// can't easily be taught that due to a deficiency in the V8 API:
243-
// there is no way for the embedder to tell if the data index is
244-
// in use.
245-
const int index = Environment::kContextEmbedderDataIndex;
246-
debug_context->SetAlignedPointerInEmbedderData(index, env);
247-
}
248-
249-
Context::Scope context_scope(debug_context);
250-
MaybeLocal<Script> script = Script::Compile(debug_context, script_source);
251-
if (script.IsEmpty())
252-
return; // Exception pending.
253-
args.GetReturnValue().Set(script.ToLocalChecked()->Run());
254-
}
255-
256-
257224
static void MakeContext(const FunctionCallbackInfo<Value>& args) {
258225
Environment* env = Environment::GetCurrent(args);
259226

test/fixtures/vm-run-in-debug-context.js

-4
This file was deleted.

test/parallel/test-util-inspect.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22+
// Flags: --expose_internals
2223
'use strict';
2324
const common = require('../common');
2425
const assert = require('assert');
2526
const JSStream = process.binding('js_stream').JSStream;
2627
const util = require('util');
2728
const vm = require('vm');
29+
const { previewMapIterator } = require('internal/v8');
2830

2931
assert.strictEqual(util.inspect(1), '1');
3032
assert.strictEqual(util.inspect(false), 'false');
@@ -442,11 +444,9 @@ assert.strictEqual(util.inspect(-0), '-0');
442444

443445
// test for Array constructor in different context
444446
{
445-
const Debug = vm.runInDebugContext('Debug');
446447
const map = new Map();
447448
map.set(1, 2);
448-
const mirror = Debug.MakeMirror(map.entries(), true);
449-
const vals = mirror.preview();
449+
const vals = previewMapIterator(map.entries(), 100);
450450
const valsOutput = [];
451451
for (const o of vals) {
452452
valsOutput.push(o);

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

-123
This file was deleted.

test/tick-processor/test-tick-processor-cpp-core.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ if (common.isWindows ||
1414
const base = require('./tick-processor-base.js');
1515

1616
base.runTest({
17-
pattern: /RunInDebugContext/,
17+
pattern: /MakeContext/,
1818
code: `function f() {
19-
require('vm').runInDebugContext('Debug');
19+
require('vm').createContext({});
2020
setImmediate(function() { f(); });
2121
};
2222
f();`

test/tick-processor/test-tick-processor-preprocess-flag.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const base = require('./tick-processor-base.js');
1616
base.runTest({
1717
pattern: /^{/,
1818
code: `function f() {
19-
require('vm').runInDebugContext('Debug');
19+
require('vm').createContext({});
2020
setImmediate(function() { f(); });
2121
};
2222
f();`,

0 commit comments

Comments
 (0)