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

deps: fix async await desugaring in V8 #12004

Merged
merged 1 commit into from
Mar 27, 2017

Conversation

targos
Copy link
Member

@targos targos commented Mar 23, 2017

This is a backport of https://codereview.chromium.org/2672313003/. The
patch did not land in V8 because it was superseded by another one but it
is much easier to backport to V8 5.5, was reviewed and passed tests.

Original commit message:

[async await] Fix async function desugaring

Previously we rewrote the return statement in an async function from
`return expr;` to `return %ResolvePromise(.promise, expr),
.promise`. This can lead to incorrect behavior in the presence of try-finally.

This patch stores the `expr` of the return statement in a temporary
variable, resolves and returns the promise at the end of the finally
block.

BUG=v8:5896

Fixes: #11960

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows [commit guidelines][]
Affected core subsystem(s)

V8

@targos
Copy link
Member Author

targos commented Mar 23, 2017

@targos
Copy link
Member Author

targos commented Mar 23, 2017

@bnoordhuis
Copy link
Member

@targos It's not just you, #11652 (comment).

@jasnell
Copy link
Member

jasnell commented Mar 23, 2017

@nodejs/build ^^^

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 with a nit and a question.

Scope* catch_scope = NewScope(CATCH_SCOPE);
catch_scope->set_is_hidden();
Variable* catch_variable =
catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, kCreatedInitialized, NORMAL_VARIABLE);
Copy link
Member

Choose a reason for hiding this comment

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

Long line.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

// the FunctionState.
Variable* async_return = function_state_->async_return_variable();
if (async_return == nullptr) {
async_return = scope()->NewTemporary(ast_value_factory()->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.

I realize the original CL does that too but do you happen to know why it uses empty_string() instead of undefined_value() or the_hole_value()?

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 agree, there doesn't seem to be a good reason for that. Do you want me to change it for undefined_value()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I think the logic is that the initial value won't matter because it's overwritten in all code paths? I'd have used the_hole_value() because its presence traps in many cases and it's something you can unambiguously debug-check since it's never produced by JS code.

Copy link
Member

Choose a reason for hiding this comment

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

empty_string isn't the value, it's the name of the variable. we never actually lookup the variable by name, so it doesn't need a name.

This is a backport of https://codereview.chromium.org/2672313003/. The
patch did not land in V8 because it was superseded by another one but it
is much easier to backport to V8 5.5, was reviewed and passed tests.

Original commit message:

    [async await] Fix async function desugaring

    Previously we rewrote the return statement in an async function from
    `return expr;` to `return %ResolvePromise(.promise, expr),
    .promise`. This can lead to incorrect behavior in the presence of try-finally.

    This patch stores the `expr` of the return statement in a temporary
    variable, resolves and returns the promise at the end of the finally
    block.

    BUG=v8:5896

PR-URL: nodejs#12004
Fixes: nodejs#11960
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
@targos targos merged commit d22346d into nodejs:v7.x-staging Mar 27, 2017
@targos targos deleted the v7.x-fix-11960-2 branch March 27, 2017 08:20
@MylesBorins MylesBorins mentioned this pull request Mar 28, 2017
MylesBorins added a commit that referenced this pull request Mar 28, 2017
Notable changes:

* buffer:
  - do not segfault on out-of-range index (Timothy Gu)
    #11927
* crypto:
  - Fix memory leak if certificate is revoked (Tom Atkinson)
    #12089
* deps:
  * upgrade npm to 4.2.0 (Kat Marchán)
    #11389
  * fix async await desugaring in V8 (Michaël Zasso)
    #12004
* readline:
  - add option to stop duplicates in history (Danny Nemer)
    #2982
* src:
  - add native URL class (James M Snell)
    #11801

PR-URL: #12104
MylesBorins added a commit that referenced this pull request Mar 29, 2017
Notable changes:

* buffer:
  - do not segfault on out-of-range index (Timothy Gu)
    #11927
* crypto:
  - Fix memory leak if certificate is revoked (Tom Atkinson)
    #12089
* deps:
  * upgrade npm to 4.2.0 (Kat Marchán)
    #11389
  * fix async await desugaring in V8 (Michaël Zasso)
    #12004
* readline:
  - add option to stop duplicates in history (Danny Nemer)
    #2982
* src:
  - add native URL class (James M Snell)
    #11801

PR-URL: #12104
@italoacasas italoacasas mentioned this pull request Apr 10, 2017
2 tasks
imyller added a commit to imyller/meta-nodejs that referenced this pull request Apr 20, 2017
    Notable changes:

    * buffer:
      - do not segfault on out-of-range index (Timothy Gu)
        nodejs/node#11927
    * crypto:
      - Fix memory leak if certificate is revoked (Tom Atkinson)
        nodejs/node#12089
    * deps:
      * upgrade npm to 4.2.0 (Kat Marchán)
        nodejs/node#11389
      * fix async await desugaring in V8 (Michaël Zasso)
        nodejs/node#12004
    * readline:
      - add option to stop duplicates in history (Danny Nemer)
        nodejs/node#2982
    * src:
      - add native URL class (James M Snell)
        nodejs/node#11801

    PR-URL: nodejs/node#12104

Signed-off-by: Ilkka Myller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants