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: support parsing a script in a specific context #14888

Merged
merged 1 commit into from
Sep 5, 2017

Conversation

TimothyGu
Copy link
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

@TimothyGu TimothyGu 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-bot nodejs-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
Member Author

/cc @nodejs/v8-inspector

Copy link
Member

@bnoordhuis bnoordhuis left a 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.

return MaybeLocal<Context>();

MaybeLocal<Value> maybe_value =
options.As<Object>()->Get(
Copy link
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
Member Author

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

@bnoordhuis
Copy link
Member

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

@TimothyGu TimothyGu force-pushed the vm-inspector-script branch 3 times, most recently from 330e27b to ce77785 Compare August 18, 2017 01:43
@TimothyGu
Copy link
Member Author

lib/vm.js Outdated
@@ -21,6 +21,7 @@

'use strict';

const { kParsingContext } = require('internal/vm');
const binding = process.binding('contextify');
Copy link
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
Member Author

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.

return MaybeLocal<Context>();

// Symbol handle may be empty when initializing.
if (env->vm_parsing_context_symbol().IsEmpty())
Copy link
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.

if (maybe_value.IsEmpty())
return MaybeLocal<Context>();

Local<Value> value = maybe_value.ToLocalChecked();
Copy link
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>();


Local<Context> context = sandbox->context();
if (context.IsEmpty())
return MaybeLocal<Context>();
Copy link
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
Member Author

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
Member Author

@bnoordhuis would you mind taking another look? Thanks!

@TimothyGu
Copy link
Member Author

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

Copy link
Member

@bnoordhuis bnoordhuis left a 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.

Context::Scope scope(
maybe_context.IsEmpty() ?
env->context() :
maybe_context.ToLocalChecked());
Copy link
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()));.


async function getContext(session) {
const created =
await session.waitForNotification('Runtime.executionContextCreated');
Copy link
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
Member Author

@TimothyGu
Copy link
Member Author

Landed in d932e80 with @bnoordhuis's comments fixed.

@TimothyGu TimothyGu closed this Sep 5, 2017
@TimothyGu TimothyGu deleted the vm-inspector-script branch September 5, 2017 03:52
@TimothyGu TimothyGu merged commit d932e80 into nodejs:master Sep 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>
@MylesBorins MylesBorins 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
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
Member Author

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

@MylesBorins
Copy link
Contributor

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

@TimothyGu
Copy link
Member Author

@MylesBorins Node.js (this PR specifically).

@TimothyGu
Copy link
Member Author

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

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>
@MylesBorins MylesBorins 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
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 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 semver-major PRs that contain breaking changes and should be released in the next major version. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants