-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: support parsing a script in a specific context #14888
Conversation
9a38ab7
to
1ea23ac
Compare
/cc @nodejs/v8-inspector |
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, 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.
src/node_contextify.cc
Outdated
return MaybeLocal<Context>(); | ||
|
||
MaybeLocal<Value> maybe_value = | ||
options.As<Object>()->Get( |
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.
Four space indent.
@bnoordhuis Would you be more satisfied had I made the option an "internal" one through unexposed symbols? |
I think that would be best. We can always make it public later if a good use case presents itself. |
330e27b
to
ce77785
Compare
@bnoordhuis Okay, done. |
lib/vm.js
Outdated
@@ -21,6 +21,7 @@ | |||
|
|||
'use strict'; | |||
|
|||
const { kParsingContext } = require('internal/vm'); | |||
const binding = process.binding('contextify'); |
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.
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.
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 sure what got into my head. Will do.
src/node_contextify.cc
Outdated
return MaybeLocal<Context>(); | ||
|
||
// Symbol handle may be empty when initializing. | ||
if (env->vm_parsing_context_symbol().IsEmpty()) |
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.
You won't need this check if you do.
src/node_contextify.cc
Outdated
if (maybe_value.IsEmpty()) | ||
return MaybeLocal<Context>(); | ||
|
||
Local<Value> value = maybe_value.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.
FWIW, it's possible to condense this to:
Local<Value> value;
if (!obj->Get(context, key).ToLocal(&value)) return MaybeLocal<Context>();
|
||
Local<Context> context = sandbox->context(); | ||
if (context.IsEmpty()) | ||
return MaybeLocal<Context>(); |
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.
This branch cannot realistically be taken, can it?
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 sure, but the same check is in a couple of other places in the file so I wouldn't touch them in this PR.
@bnoordhuis would you mind taking another look? Thanks! |
I'll apply this early next week if I don't see any comments. |
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 but see comments.
src/node_contextify.cc
Outdated
Context::Scope scope( | ||
maybe_context.IsEmpty() ? | ||
env->context() : | ||
maybe_context.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.
Could be shortened to Context::Scope scope(maybe_context.FromMaybe(env->context()));
.
|
||
async function getContext(session) { | ||
const created = | ||
await session.waitForNotification('Runtime.executionContextCreated'); |
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.
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>
f40774e
to
d932e80
Compare
Landed in d932e80 with @bnoordhuis's comments fixed. |
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>
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>
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>
It appears that this change is breaking
I'm going to drop this from the 8.5.0 release and add semver-major for now |
@MylesBorins That sounds like a bug. I shall create a PR that fixes it. |
@TimothyGu to confirm, a bug with node or with browserify / watchify? |
@MylesBorins Node.js (this PR specifically). |
@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 (19.1.3.1)
function assign(target, source) {
var props = $getOwnPropertyNames(source);
var p, length = props.length;
for (p = 0; p < length; p++) {
target[props[p]] = source[props[p]];
}
return target;
} So, not a bug in Node.js after all... |
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>
Marking this Semver-Major until it is not longer breaking the browserify test suite |
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)
Differences are only observable through Inspector's
Debugger.scriptParsed
event (hence the Dev Tools frontend).Before when executing
vm.runInNewContext('debugger')
:After:
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
vm