Skip to content

Commit

Permalink
lib,src: remove vm.runInDebugContext()
Browse files Browse the repository at this point in the history
The V8 API it is based on is deprecated and scheduled for removal later
this year.  Remove it.

PR-URL: nodejs#13295
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Robert Jefe Lindstaedt <robert.lindstaedt@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
  • Loading branch information
bnoordhuis authored and blattersturm committed Apr 21, 2018
1 parent 8d5360e commit 3192749
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 79 deletions.
5 changes: 2 additions & 3 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,9 @@ a V8-inspector based CLI debugger available through `node inspect`.
<a id="DEP0069"></a>
### DEP0069: vm.runInDebugContext(string)

Type: Documentation-only
Type: End-of-Life

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

*Note*: DebugContext was an experimental API.

Expand Down
26 changes: 0 additions & 26 deletions doc/api/vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,31 +333,6 @@ console.log(util.inspect(sandbox));
// { globalVar: 1024 }
```

## vm.runInDebugContext(code)
<!-- YAML
added: v0.11.14
-->

> Stability: 0 - Deprecated. An alternative is in development.
* `code` {string} The JavaScript code to compile and run.

The `vm.runInDebugContext()` method compiles and executes `code` inside the V8
debug context. The primary use case is to gain access to the V8 `Debug` object:

```js
const vm = require('vm');
const Debug = vm.runInDebugContext('Debug');
console.log(Debug.findScript(process.emit).name); // 'events.js'
console.log(Debug.findScript(process.exit).name); // 'internal/process.js'
```

*Note*: The debug context and object are intrinsically tied to V8's debugger
implementation and may change (or even be removed) without prior warning.

The `Debug` object can also be made available using the V8-specific
`--expose_debug_as=` [command line option][].

## vm.runInNewContext(code[, sandbox][, options])
<!-- YAML
added: v0.3.1
Expand Down Expand Up @@ -511,7 +486,6 @@ associating it with the `sandbox` object is what this document refers to as
[`vm.runInContext()`]: #vm_vm_runincontext_code_contextifiedsandbox_options
[`vm.runInThisContext()`]: #vm_vm_runinthiscontext_code_options
[V8 Embedder's Guide]: /~https://github.com/v8/v8/wiki/Embedder's%20Guide#contexts
[command line option]: cli.html
[contextified]: #vm_what_does_it_mean_to_contextify_an_object
[global object]: https://es5.github.io/#x15.1
[indirect `eval()` call]: https://es5.github.io/#x10.4.2
4 changes: 0 additions & 4 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,6 @@ Module.prototype._compile = function(content, filename) {
if (filename === resolvedArgv) {
delete process._breakFirstLine;
inspectorWrapper = process.binding('inspector').callAndPauseOnStart;
if (!inspectorWrapper) {
const Debug = vm.runInDebugContext('Debug');
Debug.setBreakPoint(compiledWrapper, 0, 0);
}
}
}
var dirname = path.dirname(filename);
Expand Down
2 changes: 0 additions & 2 deletions lib/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const {

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

// The binding provides a few useful primitives:
Expand Down Expand Up @@ -143,7 +142,6 @@ module.exports = {
Script,
createContext,
createScript,
runInDebugContext,
runInContext,
runInNewContext,
runInThisContext,
Expand Down
35 changes: 1 addition & 34 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@

#include "node_internals.h"
#include "node_watchdog.h"
#include "base-object-inl.h"
#include "v8-debug.h"
#include "base_object-inl.h"

namespace node {

using v8::Array;
using v8::ArrayBuffer;
using v8::Boolean;
using v8::Context;
using v8::Debug;
using v8::EscapableHandleScope;
using v8::External;
using v8::Function;
Expand Down Expand Up @@ -265,42 +263,11 @@ class ContextifyContext {
function_template->InstanceTemplate()->SetInternalFieldCount(1);
env->set_script_data_constructor_function(function_template->GetFunction());

env->SetMethod(target, "runInDebugContext", RunInDebugContext);
env->SetMethod(target, "makeContext", MakeContext);
env->SetMethod(target, "isContext", IsContext);
}


static void RunInDebugContext(const FunctionCallbackInfo<Value>& args) {
Local<String> script_source(args[0]->ToString(args.GetIsolate()));
if (script_source.IsEmpty())
return; // Exception pending.
Local<Context> debug_context = Debug::GetDebugContext(args.GetIsolate());
Environment* env = Environment::GetCurrent(args);
if (debug_context.IsEmpty()) {
// Force-load the debug context.
auto dummy_event_listener = [] (const Debug::EventDetails&) {};
Debug::SetDebugEventListener(args.GetIsolate(), dummy_event_listener);
debug_context = Debug::GetDebugContext(args.GetIsolate());
CHECK(!debug_context.IsEmpty());
// Ensure that the debug context has an Environment assigned in case
// a fatal error is raised. The fatal exception handler in node.cc
// is not equipped to deal with contexts that don't have one and
// can't easily be taught that due to a deficiency in the V8 API:
// there is no way for the embedder to tell if the data index is
// in use.
const int index = Environment::kContextEmbedderDataIndex;
debug_context->SetAlignedPointerInEmbedderData(index, env);
}

Context::Scope context_scope(debug_context);
MaybeLocal<Script> script = Script::Compile(debug_context, script_source);
if (script.IsEmpty())
return; // Exception pending.
args.GetReturnValue().Set(script.ToLocalChecked()->Run());
}


static void MakeContext(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Expand Down
4 changes: 0 additions & 4 deletions test/fixtures/vm-run-in-debug-context.js

This file was deleted.

6 changes: 3 additions & 3 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

// Flags: --expose_internals
'use strict';
require('../common');
const assert = require('assert');
const JSStream = process.binding('js_stream').JSStream;
const util = require('util');
const vm = require('vm');
const { previewMapIterator } = require('internal/v8');

/* eslint-disable accessor-pairs */

Expand Down Expand Up @@ -434,11 +436,9 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');

// test for Array constructor in different context
{
const Debug = vm.runInDebugContext('Debug');
const map = new Map();
map.set(1, 2);
const mirror = Debug.MakeMirror(map.entries(), true);
const vals = mirror.preview();
const vals = previewMapIterator(map.entries(), 100);
const valsOutput = [];
for (const o of vals) {
valsOutput.push(o);
Expand Down
4 changes: 2 additions & 2 deletions test/tick-processor/test-tick-processor-cpp-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ if (common.isWindows ||
const base = require('./tick-processor-base.js');

base.runTest({
pattern: /RunInDebugContext/,
pattern: /MakeContext/,
code: `function f() {
require('vm').runInDebugContext('Debug');
require('vm').createContext({});
setImmediate(function() { f(); });
};
f();`
Expand Down
2 changes: 1 addition & 1 deletion test/tick-processor/test-tick-processor-preprocess-flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const base = require('./tick-processor-base.js');
base.runTest({
pattern: /^{/,
code: `function f() {
require('vm').runInDebugContext('Debug');
require('vm').createContext({});
setImmediate(function() { f(); });
};
f();`,
Expand Down

0 comments on commit 3192749

Please sign in to comment.