Skip to content

vm: support parsing a script in a specific context - #14888

Merged
TimothyGu merged 1 commit into
nodejs:masterfrom
TimothyGu:vm-inspector-script
Sep 5, 2017
Merged

vm: support parsing a script in a specific context#14888
TimothyGu merged 1 commit into
nodejs:masterfrom
TimothyGu:vm-inspector-script

Conversation

@TimothyGu

Copy link
Copy Markdown
Member

Differences are only observable through Inspector's Debugger.scriptParsed event (hence the Dev Tools frontend).

Before when executing vm.runInNewContext('debugger'):

screenshot from 2017-08-17 13-39-06

After:

screenshot from 2017-08-17 13-39-24

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

@TimothyGuTimothyGu added inspector Issues and PRs related to the V8 inspector protocol vm Issues and PRs related to the vm subsystem. labels Aug 17, 2017
@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. vm Issues and PRs related to the vm subsystem. labels Aug 17, 2017
@TimothyGu

Copy link
Copy Markdown
MemberAuthor

/cc @nodejs/v8-inspector

@bnoordhuisbnoordhuis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I suppose, although it feels a bit like a workaround rather than a proper fix, and since it adds a public property, we might come to regret that later.

Comment threadsrc/node_contextify.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Four space indent.

@TimothyGu

Copy link
Copy Markdown
MemberAuthor

@bnoordhuis Would you be more satisfied had I made the option an "internal" one through unexposed symbols?

@bnoordhuis

Copy link
Copy Markdown
Member

I think that would be best. We can always make it public later if a good use case presents itself.

@TimothyGu
TimothyGuforce-pushed the vm-inspector-script branch 3 times, most recently from 330e27b to ce77785CompareAugust 18, 2017 01:43
@TimothyGu

Copy link
Copy Markdown
MemberAuthor

Comment threadlib/vm.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like over-complicating it. You can create the symbol in InitContextify() or ContextifyScript::Init() and set it on target and then use it directly from the binding object, no need for a new file in lib/internal.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... not sure what got into my head. Will do.

Comment threadsrc/node_contextify.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You won't need this check if you do.

Comment threadsrc/node_contextify.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, it's possible to condense this to:

Local<Value> value;
if (!obj->Get(context, key).ToLocal(&value)) return MaybeLocal<Context>();

Comment threadsrc/node_contextify.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch cannot realistically be taken, can it?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but the same check is in a couple of other places in the file so I wouldn't touch them in this PR.

@TimothyGu

Copy link
Copy Markdown
MemberAuthor

@bnoordhuis would you mind taking another look? Thanks!

@TimothyGu

Copy link
Copy Markdown
MemberAuthor

I'll apply this early next week if I don't see any comments.

@bnoordhuisbnoordhuis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but see comments.

Comment threadsrc/node_contextify.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be shortened to Context::Scope scope(maybe_context.FromMaybe(env->context()));.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Teeny tiny style nit but line continuations are indented by four spaces. (I don't know why the linter doesn't enforce that.)

PR-URL: nodejs#14888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
@TimothyGu

Copy link
Copy Markdown
MemberAuthor

@TimothyGu

Copy link
Copy Markdown
MemberAuthor

Landed in d932e80 with @bnoordhuis's comments fixed.

@TimothyGu
TimothyGu deleted the vm-inspector-script branch September 5, 2017 03:52
@TimothyGu
TimothyGu merged commit d932e80 into nodejs:masterSep 5, 2017
addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 5, 2017
PR-URL: nodejs/node#14888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
MylesBorins pushed a commit that referenced this pull request Sep 10, 2017
PR-URL: #14888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
@MylesBorinsMylesBorins mentioned this pull request Sep 10, 2017
MylesBorins pushed a commit that referenced this pull request Sep 11, 2017
PR-URL: #14888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
@MylesBorins

Copy link
Copy Markdown
Contributor

It appears that this change is breaking browserify

TAP version 13
# Subtest: yield
1..6
(node:71559) Warning: process.on(SIGPROF) is reserved while debugging
ok 1 - should not error
not ok 2 - TypeError: Cannot convert undefined or null to object
---
test: yield
message: 'TypeError: Cannot convert undefined or null to object'
stack: >
getOwnPropertyNames (<anonymous>)
Function.assign (eval at <anonymous>
(node_modules/traceur/src/node/traceur.js:24:17), <anonymous>:219:19)
Object.runInNewContext (vm.js:131:22)
test/yield.js:14:12
index.js:779:13
ConcatStream.<anonymous> (node_modules/concat-stream/index.js:36:43)
finishMaybe
(node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:475:14)
endWritable
(node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:485:3)
...
not ok 3 - missing test
not ok 4 - missing test
not ok 5 - missing test
not ok 6 - missing test
# failed 5 of 6 tests
not ok 1 - yield # time=216.95ms
---
at:
file: test/yield.js
line: 5
column: 1
results:
plan:
start: 1
end: 6
count: 6
pass: 1
ok: false
fail: 5
time: 216.95
source: |
test('yield', function (t) {
...
1..1
# failed 1 of 1 tests

I'm going to drop this from the 8.5.0 release and add semver-major for now

@TimothyGu

Copy link
Copy Markdown
MemberAuthor

@MylesBorins That sounds like a bug. I shall create a PR that fixes it.

@MylesBorins

Copy link
Copy Markdown
Contributor

@TimothyGu to confirm, a bug with node or with browserify / watchify?

@TimothyGu

Copy link
Copy Markdown
MemberAuthor

@MylesBorins Node.js (this PR specifically).

@TimothyGu

Copy link
Copy Markdown
MemberAuthor

@MylesBorins Upon a second look, it seems to me that this bug is with Browserify -- or more specifically, an old and buggy version of Traceur's Object.assign polyfill that doesn't handle undefined, null, or multiple sources, which is unconditionally added to the global environment during Browserify's test/yield.js:

// Object.assign (19.1.3.1)functionassign(target,source){varprops=$getOwnPropertyNames(source);varp,length=props.length;for(p=0;p<length;p++){target[props[p]]=source[props[p]];}returntarget;}

So, not a bug in Node.js after all...

jasnell pushed a commit that referenced this pull request Sep 20, 2017
PR-URL: #14888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
@MylesBorinsMylesBorins added the semver-major PRs that contain breaking changes and should be released in the next major version. label Oct 11, 2017
@MylesBorins

Copy link
Copy Markdown
Contributor

Marking this Semver-Major until it is not longer breaking the browserify test suite

MylesBorins added a commit to MylesBorins/citgm that referenced this pull request Oct 31, 2017
bug in traceur compiler polyfill in browserify is causing errors
in 8.x and above. This needs to be fixed in browserify.
Refs: nodejs/node#14888 (comment)
Sign up for freeto 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++.inspectorIssues and PRs related to the V8 inspector protocolsemver-majorPRs that contain breaking changes and should be released in the next major version.vmIssues and PRs related to the vm subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@TimothyGu@bnoordhuis@MylesBorins@eugeneo@jasnell@nodejs-github-bot