From 01e95c664915f9f3ce74d0fbfb37569f370c1a41 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Wed, 9 Oct 2024 20:59:20 -0400 Subject: [PATCH] Normative: Intrepret scripts as async fn bodies --- index.html | 139 +++++++++++++++++++++-------------------------------- 1 file changed, 54 insertions(+), 85 deletions(-) diff --git a/index.html b/index.html index 365e67c4..f273823d 100644 --- a/index.html +++ b/index.html @@ -7071,12 +7071,13 @@

Executing Script

and arguments. -

The rules to execute a function body are as follows. - The algorithm returns an ECMAScript completion record. +

To execute an async function body given session, + bodySource, and arguments. + The algorithm returns success with an ECMAScript Promise instance or error.

If at any point during the algorithm a user prompt appears, - immediately return Completion { [[\Type]]: normal, [[\Value]]: null, - [[\Target]]: empty }, but continue to run the other steps of this algorithm [=in parallel=]. + immediately return success with data null, + but continue to run the other steps of this algorithm [=in parallel=].

  1. Let window be the associated window @@ -7086,47 +7087,55 @@

    Executing Script

  2. Let environment settings be window's [=relevant settings object=]. -

  3. Let global scope be - environment settings realm's - global environment. +
  4. Let realm be environment settings' realm. -

  5. If body is not parsable as a FunctionBody - or if parsing detects an early error, - return - Completion { [[\Type]]: normal, [[\Value]]: null, [[\Target]]: empty }. +

  6. Let parameters be ParseText("", FormalParameters[~Yield, +Await]). -

  7. If body begins with a directive prologue - that contains a use strict directive - then let strict be true, - otherwise let strict be false. +

  8. Assert: parameters is a Parse Node. + +

  9. Let be ParseText(bodySource, AsyncFunctionBody). + +

  10. If body is a List of errors: + +

      + +
    1. Return a new error with error code javascript error and data null. + +

  11. Prepare to run script with environment settings.

  12. Prepare to run a callback with environment settings.

  13. Let function be the result of - calling FunctionCreate, with arguments: + calling OrdinaryFunctionCreate with arguments:

    -
    kind -
    Normal. +
    functionPrototype +
    %AsyncFunction.prototype%. + +
    sourceText +
    bodySource. -
    list -
    An empty List. +
    ParameterList +
    parameters. -
    body -
    The result of parsing body above. +
    Body +
    body. -
    global scope -
    The result of parsing global scope above. +
    thisMode +
    NON-LEXICAL-THIS. -
    strict -
    The result of parsing strict above. +
    env +
    realm.[[\GlobalEnv]]. + +
    privateEnv +
    null.
  14. Let completion be Function.[[\Call]](window, - parameters) with function as the this value. + arguments) with function as the this value.

  15. Clean up after running a callback with environment settings. @@ -7134,7 +7143,9 @@

    Executing Script

  16. Clean up after running script with environment settings. -

  17. Return completion. +

  18. Assert: completion is a normal completion. + +

  19. Return success with data completion.[[\Value]].

The above algorithm is not associated @@ -7180,22 +7191,11 @@

Execute Script

  1. Start the timer with timer and timeout. -

- -
  • Let promise be a new Promise. - -

  • Run the following substeps in parallel: -

      -
    1. Let scriptPromise be the result of promise-calling - execute a function body, with arguments - body and arguments. - -

    2. Upon fulfillment of scriptPromise with value v, - resolve promise with value v. +

    -
  • Upon rejection of scriptPromise with value r, - reject promise with value r. - +

  • Let promise be the result of trying to + execute an async function body, with arguments + session, body and arguments.

  • Wait until promise is resolved, or timer's [=timer/timeout fired flag=] is set, @@ -7275,31 +7275,9 @@

    Execute Async Script

  • Append resolvingFunctions.[[\Resolve]] to arguments. -

  • Let scriptResult be the result of calling - execute a function body, with arguments - body and arguments. - -

  • If scriptResult.[[\Type]] is not normal, then reject - promise with value scriptResult.[[\Value]], and abort these steps. - -

    Prior revisions of this specification did not recognize the - return value of the provided script. In order to preserve legacy behavior, - the return value only influences the command if it is a "thenable" object or - if determining this produces an exception. - -

  • If Type(scriptResult.[[\Value]]) - is not Object, then abort these steps. - -

  • Let then be Get(scriptResult.[[\Value]], "then"). - -

  • If then.[[\Type]] is not normal, then reject - promise with value then.[[\Value]], and abort these steps. - -

  • If IsCallable(then.[[\Type]]) is false, - then abort these steps. - -

  • Let scriptPromise be PromiseResolve(Promise, - scriptResult.[[\Value]]). +

  • Let scriptPromise be the result of trying to + execute an async function body, with arguments + session, body and arguments.

  • Upon fulfillment of scriptPromise with value v, resolve promise with value v. @@ -11633,21 +11611,18 @@

    Index

    The following terms are defined in the ECMAScript Language Specification: [[ECMA-262]]

    @@ -12010,12 +11985,6 @@

    Index

    -
    Promises Guide -

    The following terms are defined in the Promises Guide. [[PROMISES-GUIDE]] -

    -
    XPATH

    The following terms are defined in the Document Object Model XPath standard [[XPATH]]