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

v8: fix new.target inheritance from c++ #9293

Merged
merged 0 commits into from
Mar 2, 2017

Conversation

bnoordhuis
Copy link
Member

See #9288. Cherry-pick two commits from V8 5.2. The actual fix is commit v8/v8@73ee794 but it depends on commit v8/v8@306c412 which might be something of an ABI change. Opinions welcome on whether we should do this.

cc @nodejs/v8

@bnoordhuis
Copy link
Member Author

CI: https://ci.nodejs.org/job/node-test-pull-request/4684/

I'll add a regression test if we decide to land this.

@mscdex mscdex added v8 engine Issues and PRs related to the V8 dependency. addons Issues and PRs related to native addons. labels Oct 26, 2016
internal::Object** implicit_args_;
internal::Object** values_;
int length_;
int is_construct_call_;
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, removing this field will definitely break addons compiled for the existing versions of node v6. Maybe the changes can be patched up to duplicate information, so that is_construct_call_ is always populated with a correct value? (I can look into that myself but I wouldn’t want to make any promises about time.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm in Germany for the next few days (Jena, in case you're wondering) so I probably won't have time to get back to it until next week.

Copy link
Member Author

Choose a reason for hiding this comment

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

It turned out to be a little more involved than just adding back the field because it's also set directly by generated code. I got it working locally and I'll push the changes shortly.

case JS_DATE_TYPE:
case JS_ARRAY_TYPE:
case JS_MESSAGE_OBJECT_TYPE:
case JS_API_OBJECT_TYPE:
Copy link
Member

Choose a reason for hiding this comment

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

This line should probably be dropped? (Right now this breaks compiling a debug build, there is no JS_API_OBJECT_TYPE).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Fixed, and I checked that the other fields do exist.

@bnoordhuis
Copy link
Member Author

bnoordhuis commented Nov 2, 2016

Updated, PTAL.

https://ci.nodejs.org/job/node-test-pull-request/4761/
https://ci.nodejs.org/job/node-test-commit-v8-linux/388/

EDIT: Le sigh, the node-test-commit-v8-linux job still has infrastructural issues...

@@ -3177,12 +3177,13 @@ class FunctionCallbackInfo {
Local<Function> Callee() const);
V8_INLINE Local<Object> This() const;
V8_INLINE Local<Object> Holder() const;
V8_INLINE Local<Value> NewTarget() const;
Copy link
Member Author

Choose a reason for hiding this comment

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

I can break out the new method into a separate commit in order to keep the meat of the pull request semver-patch.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: It might be a good idea to add the a DCHECK in IsConstructCall to make sure that the equivalence relationship between is_construct_call_ & 1 and !NewTarget->IsUndefined holds.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that a subsequent commit drops NewTarget. Feel free to ignore.

@rvagg
Copy link
Member

rvagg commented Nov 2, 2016

Did an earlier version of this include the ABI breaking changes because I don't think I see it in the current incarnation, at least I don't see the is_construct_call stuff in v8.h here. Is it safe to assume this is ABI stable now?

I quite like the idea of keeping the NewTarget() stuff separate so we don't end up holding this off until we're prepared to do a semver-minor in v6 (it'd be preferable to hold that off for as long as possible). Do we get the fix for #9288 without that addition?

@bnoordhuis
Copy link
Member Author

@rvagg Yes to both questions.

@rvagg
Copy link
Member

rvagg commented Nov 2, 2016

OK then, my vote goes for splitting this into a semver-patch so we can get a fix out in the next v6 release and a semver-minor so we can complete the API at some point after. Thanks for the hard work of making this fit nicely @bnoordhuis.

@thealphanerd this'll be a good one to try your new ABI compatibility tester on.

@mhdawson
Copy link
Member

mhdawson commented Nov 4, 2016

@MylesBorins
Copy link
Contributor

@bnoordhuis @nodejs/v8 do we want to try and get this in the next release?

@bnoordhuis
Copy link
Member Author

Updated with a commit that backs out NewTarget(). #9689 is the regression test, that should land in master first before it gets back-ported. I tested locally that the test fails with v6.x-staging and passes with this pull request applied.

CI: https://ci.nodejs.org/job/node-test-pull-request/4901/

@bnoordhuis
Copy link
Member Author

+ gmake lint-ci
./node tools/jslint.js -j 2 -f tap -o test-eslint.tap \
    benchmark lib test tools
gmake: *** [Makefile:709: jslint-ci] Error 1

No clue as to why this PR would trigger a lint error, it only touches code in deps/v8...

@bnoordhuis
Copy link
Member Author

Now with patches for s390, ppc and x87 applied. CI: https://ci.nodejs.org/job/node-test-pull-request/4902/

@bnoordhuis
Copy link
Member Author

bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request Nov 21, 2016
Add a test that checks that new.target inheritance works when inheriting
from a constructor defined in C++.

PR-URL: nodejs#9689
Refs: nodejs#9288
Refs: nodejs#9293
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@bnoordhuis
Copy link
Member Author

Added the regression test from #9689. New CI: https://ci.nodejs.org/job/node-test-pull-request/4920/

@MylesBorins
Copy link
Contributor

@bnoordhuis linting error is unrelated to this PR

@bnoordhuis
Copy link
Member Author

V8 CI is brilliantly green, node CI is... eh, nothing that's caused by this PR.

@addaleax @nodejs/v8 Perhaps one of you can review the last commit?

STATIC_ASSERT(FCA::kArgsLength == 8);

// new target
__ PushRoot(Heap::kUndefinedValueRootIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

For posterity, can you add a link to the commit where the s390 and x87 stubs come from.

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -3177,12 +3177,13 @@ class FunctionCallbackInfo {
Local<Function> Callee() const);
V8_INLINE Local<Object> This() const;
V8_INLINE Local<Object> Holder() const;
V8_INLINE Local<Value> NewTarget() const;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: It might be a good idea to add the a DCHECK in IsConstructCall to make sure that the equivalence relationship between is_construct_call_ & 1 and !NewTarget->IsUndefined holds.

@@ -3177,12 +3177,13 @@ class FunctionCallbackInfo {
Local<Function> Callee() const);
V8_INLINE Local<Object> This() const;
V8_INLINE Local<Object> Holder() const;
V8_INLINE Local<Value> NewTarget() const;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that a subsequent commit drops NewTarget. Feel free to ignore.

@bnoordhuis
Copy link
Member Author

Copy link
Contributor

@MylesBorins MylesBorins left a comment

Choose a reason for hiding this comment

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

LGTM

@bnoordhuis
Copy link
Member Author

@MylesBorins Should I land this or do you?

@jasnell
Copy link
Member

jasnell commented Feb 27, 2017

@bnoordhuis ... I'm not @MylesBorins of course, but feel free to land in the staging branch :-)

@bnoordhuis bnoordhuis closed this Mar 2, 2017
@bnoordhuis bnoordhuis merged commit 2ebceed into nodejs:v6.x-staging Mar 2, 2017
bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request Mar 2, 2017
Don't try to optimize known-unoptimizable functions when --always-opt
is specified on the command line, it makes Crankshaft emit wrong code.

This was fixed upstream when improved WASM support was introduced but
that specific change can't be back-ported because it depends on prior
work that doesn't exist in V8 5.1.  Ergo, I decided to redo the fix
from scratch.

PR-URL: nodejs#9293
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request Mar 2, 2017
The patch has been modified to maintain ABI compatibility.  The original
change removes the v8::FunctionCallbackInfo<T>::is_construct_call_ field
from deps/v8/include/v8.h.  The field is set directly by JIT-ted code so
the removal of those code paths has been backed out as well.

Original commit message:

    [api] Expose FunctionCallbackInfo::NewTarget

    This is needed by Blink to implement the Custom Elements spec.

    BUG=v8:4261
    LOG=y

    Review-Url: https://codereview.chromium.org/1910253005
    Cr-Commit-Position: refs/heads/master@{nodejs#35833}

Fixes: nodejs#9288
PR-URL: nodejs#9293
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request Mar 2, 2017
Original commit message:

    When instantiating a subclassed API function, the instance cache
    is avoided. There is currently no direct API yet to instantiate
    a Template while passing in a new.target. It probably makes sense
    to extend ObjectTemplate::NewInstance to accept a new.target, in
    line with Reflect.construct.

    BUG=v8:3330, v8:5001

    Review-Url: https://codereview.chromium.org/1972613002
    Cr-Commit-Position: refs/heads/master@{nodejs#36179}

Fixes: nodejs#9288
PR-URL: nodejs#9293
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request Mar 2, 2017
Remove the new method that was introduced in the back-port of
v8/v8@306c412c ("[api] Expose FunctionCallbackInfo::NewTarget")
so that the meat of the patch can land in a patch release.

This commit can be reverted again in the next minor release.

Fixes: nodejs#9288
PR-URL: nodejs#9293
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
@bnoordhuis bnoordhuis deleted the fix9288 branch March 2, 2017 12:17
@bnoordhuis
Copy link
Member Author

Landed in 1d631ce...2ebceed, cheers.

@MylesBorins
Copy link
Contributor

@bnoordhuis is this able to be landed in the next release? The next release will be a patch and will not be able to include the revert that is mentioned above

@bnoordhuis
Copy link
Member Author

@MylesBorins Yes, this PR is semver-patch, #11652 the semver-minor.

MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
Don't try to optimize known-unoptimizable functions when --always-opt
is specified on the command line, it makes Crankshaft emit wrong code.

This was fixed upstream when improved WASM support was introduced but
that specific change can't be back-ported because it depends on prior
work that doesn't exist in V8 5.1.  Ergo, I decided to redo the fix
from scratch.

PR-URL: #9293
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
The patch has been modified to maintain ABI compatibility.  The original
change removes the v8::FunctionCallbackInfo<T>::is_construct_call_ field
from deps/v8/include/v8.h.  The field is set directly by JIT-ted code so
the removal of those code paths has been backed out as well.

Original commit message:

    [api] Expose FunctionCallbackInfo::NewTarget

    This is needed by Blink to implement the Custom Elements spec.

    BUG=v8:4261
    LOG=y

    Review-Url: https://codereview.chromium.org/1910253005
    Cr-Commit-Position: refs/heads/master@{#35833}

Fixes: #9288
PR-URL: #9293
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
Original commit message:

    When instantiating a subclassed API function, the instance cache
    is avoided. There is currently no direct API yet to instantiate
    a Template while passing in a new.target. It probably makes sense
    to extend ObjectTemplate::NewInstance to accept a new.target, in
    line with Reflect.construct.

    BUG=v8:3330, v8:5001

    Review-Url: https://codereview.chromium.org/1972613002
    Cr-Commit-Position: refs/heads/master@{#36179}

Fixes: #9288
PR-URL: #9293
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
Remove the new method that was introduced in the back-port of
v8/v8@306c412c ("[api] Expose FunctionCallbackInfo::NewTarget")
so that the meat of the patch can land in a patch release.

This commit can be reverted again in the next minor release.

Fixes: #9288
PR-URL: #9293
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
Add a test that checks that new.target inheritance works when inheriting
from a constructor defined in C++.

PR-URL: #9689
Refs: #9288
Refs: #9293
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@MylesBorins MylesBorins mentioned this pull request Mar 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addons Issues and PRs related to native addons. v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants