-
Notifications
You must be signed in to change notification settings - Fork 30k
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
vm: allow modifying context name in inspector #17720
Conversation
doc/api/vm.md
Outdated
**Default:** `'VM Context i'`, where `i` is an ascending numerical index of | ||
the created context. | ||
* `contextOrigin` {string} [Origin][origin] corresponding to the newly | ||
created context for display purposes. **Default:** the empty string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the empty string
-> an empty string
or just empty string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used ''
instead.
doc/api/vm.md
Outdated
**Default:** `'VM Context i'`, where `i` is an ascending numerical index of | ||
the created context. | ||
* `contextOrigin` {string} [Origin][origin] corresponding to the newly | ||
created context for display purposes. **Default:** the empty string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -242,12 +247,18 @@ console.log(globalVar); | |||
// 1000 | |||
``` | |||
|
|||
## vm.createContext([sandbox]) | |||
## vm.createContext([sandbox[, options]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this bottom reference (line 505) needs to be updated now:
[`vm.createContext()`]: #vm_vm_createcontext_sandbox
into the
[`vm.createContext()`]: #vm_vm_createcontext_sandbox_options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small stylistic comment
cc @jasnell, should/has a formal guide been written up for internal errors JS/C++ interactions?
lib/vm.js
Outdated
@@ -73,18 +75,57 @@ Script.prototype.runInContext = function(contextifiedSandbox, options) { | |||
}; | |||
|
|||
Script.prototype.runInNewContext = function(sandbox, options) { | |||
var context = createContext(sandbox); | |||
const contextOptions = options ? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a super big deal, but should this code section be extracted into a separate function, since it's also used below?
src/node_contextify.cc
Outdated
env->AssignToContext(ctx); | ||
Local<Value> name = | ||
options_obj->Get(env->context(), | ||
FIXED_ONE_BYTE_STRING(env->isolate(), "name")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
env->name_string()
doc/api/vm.md
Outdated
**Default:** `'VM Context i'`, where `i` is an ascending numerical index of | ||
the created context. | ||
* `contextOrigin` {string} [Origin][origin] corresponding to the newly | ||
created context for display purposes. **Default:** `''`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider documenting that it's a (file?) URL? The linked page doesn't do a great job at describing what it is and mentions things that aren't relevant (e.g. CORS.)
src/inspector_agent.cc
Outdated
std::unique_ptr<StringBuffer> ToProtocolString(Isolate* isolate, | ||
Local<Value> value) { | ||
Local<T> value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary, as far as I can tell. A Local<String>
is a Local<Value>
.
src/inspector_agent.cc
Outdated
ContextInfo info( | ||
String::NewFromUtf8(env->isolate(), | ||
GetHumanReadableProcessName().c_str(), | ||
NewStringType::kNormal).ToLocalChecked()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if ContextInfo used std::string
because then you don't have to worry whether it's safe to call into V8 from here and what the lifetime of the Local<String>
is (and also because it's a bit awkward to create a JS string here, only to unpack it almost immediately again.)
@vsemozhetbyt @maclover7 @bnoordhuis Comments addressed; PTAL. |
src/env.h
Outdated
} | ||
v8::Local<v8::String> name; | ||
v8::Local<v8::String> origin; | ||
explicit ContextInfo(std::string name) : name(name) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const std::string&
since you're making a copy.
src/env.h
Outdated
v8::Local<v8::String> name; | ||
v8::Local<v8::String> origin; | ||
explicit ContextInfo(std::string name) : name(name) {} | ||
std::string name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make this const
.
@bnoordhuis Done and done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as far as docs and JS code goes. Can't really to speak to C++ side
Landed in 2cb2145. |
The `auxData` field is not exposed to JavaScript, as DevTools uses it for its `isDefault` parameter, which is implemented faithfully, contributing to the nice indentation in the context selection panel. Without the indentation, when `Target` domain gets implemented (along with a single Inspector for cluster) in #16627, subprocesses and VM contexts will be mixed up, causing confusion. PR-URL: #17720 Refs: #14231 (comment) Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: James M Snell <jasnell@gmail.com>
The `auxData` field is not exposed to JavaScript, as DevTools uses it for its `isDefault` parameter, which is implemented faithfully, contributing to the nice indentation in the context selection panel. Without the indentation, when `Target` domain gets implemented (along with a single Inspector for cluster) in #16627, subprocesses and VM contexts will be mixed up, causing confusion. PR-URL: #17720 Refs: #14231 (comment) Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: James M Snell <jasnell@gmail.com>
The `auxData` field is not exposed to JavaScript, as DevTools uses it for its `isDefault` parameter, which is implemented faithfully, contributing to the nice indentation in the context selection panel. Without the indentation, when `Target` domain gets implemented (along with a single Inspector for cluster) in #16627, subprocesses and VM contexts will be mixed up, causing confusion. PR-URL: #17720 Refs: #14231 (comment) Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: James M Snell <jasnell@gmail.com>
The `auxData` field is not exposed to JavaScript, as DevTools uses it for its `isDefault` parameter, which is implemented faithfully, contributing to the nice indentation in the context selection panel. Without the indentation, when `Target` domain gets implemented (along with a single Inspector for cluster) in #16627, subprocesses and VM contexts will be mixed up, causing confusion. PR-URL: #17720 Refs: #14231 (comment) Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: James M Snell <jasnell@gmail.com>
The test for this fails when cherry-picking to v8.x: ▶▶▶ tools/test.py test/sequential/test-inspector-contexts.js ~/wrk/com/DANGER/node (⇡v8.x-staging✦)
=== release test-inspector-contexts ===
Path: sequential/test-inspector-contexts
Testing context created/destroyed notifications
/Users/gib/wrk/com/DANGER/node/test/common/index.js:822
(err) => process.nextTick(() => { throw err; }));
^
TypeError: Cannot read property 'isDefault' of undefined
at testContextCreatedAndDestroyed (/Users/gib/wrk/com/DANGER/node/test/sequential/test-inspector-contexts.js:39:25)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:686:11)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Command: out/Release/node --expose-gc /Users/gib/wrk/com/DANGER/node/test/sequential/test-inspector-contexts.js
[00:00|% 100|+ 0|- 1]: Done Could you either backport or change the label to dont-land (if it shouldn't land)? |
The
auxData
field is not exposed to JavaScript, as DevTools uses it for itsisDefault
parameter, which is implemented faithfully, contributing to the nice indentation in the context selection panel. Without the indentation, whenTarget
domain gets implemented (along with a single Inspector for cluster) in #16627, subprocesses and VM contexts will be mixed up, causing confusion.Refs: #14231 (comment)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
vm, inspector, src