Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

TimothyGu
Copy link
Member

@TimothyGu TimothyGu commented Dec 17, 2017

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.

screenshot from 2017-12-17 12-25-39

Refs: #14231 (comment)

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

vm, inspector, src

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Dec 17, 2017
@TimothyGu TimothyGu added inspector Issues and PRs related to the V8 inspector protocol vm Issues and PRs related to the vm subsystem. labels Dec 17, 2017
@TimothyGu TimothyGu requested a review from addaleax December 17, 2017 23:14
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.
Copy link
Member

@devsnek devsnek Dec 17, 2017

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

Copy link
Member Author

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.
Copy link
Member

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]])
Copy link
Contributor

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

Copy link
Contributor

@maclover7 maclover7 left a 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 ? {
Copy link
Contributor

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?

env->AssignToContext(ctx);
Local<Value> name =
options_obj->Get(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "name"))
Copy link
Member

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:** `''`.
Copy link
Member

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.)

std::unique_ptr<StringBuffer> ToProtocolString(Isolate* isolate,
Local<Value> value) {
Local<T> value) {
Copy link
Member

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>.

ContextInfo info(
String::NewFromUtf8(env->isolate(),
GetHumanReadableProcessName().c_str(),
NewStringType::kNormal).ToLocalChecked());
Copy link
Member

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.)

@TimothyGu
Copy link
Member Author

@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) {}
Copy link
Member

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;
Copy link
Member

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.

@TimothyGu
Copy link
Member Author

@bnoordhuis Done and done.

Copy link
Contributor

@maclover7 maclover7 left a 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

@TimothyGu
Copy link
Member Author

@TimothyGu
Copy link
Member Author

Landed in 2cb2145.

@TimothyGu TimothyGu closed this Dec 23, 2017
TimothyGu added a commit that referenced this pull request Dec 23, 2017
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>
@TimothyGu TimothyGu deleted the vm-meta branch December 23, 2017 06:24
MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
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>
MylesBorins pushed a commit that referenced this pull request Jan 9, 2018
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>
MylesBorins pushed a commit that referenced this pull request Jan 9, 2018
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>
@gibfahn
Copy link
Member

gibfahn commented Jan 24, 2018

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)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol lib / src Issues and PRs related to general changes in the lib or src directory. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants