From 2957dbc0b20b580c9c952e5c032bdc2fbf20c31f Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 3 May 2016 15:06:30 -0400 Subject: [PATCH] Modernize invoking user code This updates the four algorithms that invoke user code in the following ways: - Updates them to use HTML's latest framework for managing script settings objects. The previous version referred to concepts, such as the "stack of incumbent scripts", which have not been defined for a long time (i.e. since before whatwg/html#401). Updates in whatwg/html#401 and whatwg/html#1091 have changed the setup here. There is still some ongoing discussion in whatwg/html#473 about whether the current HTML setup is correct for managing _incumbent_ settings objects, but this at least updates the algorithms to correctly manage _entry_ settings objects. The plan implemented here is roughly that discussed in https://github.com/whatwg/html/issues/473#issuecomment-212164549 with details from https://github.com/heycam/webidl/pull/113#issuecomment-218640902 "Step 1". - Gives them explicit s with explicit arguments to be passed. - Updates them to use some slightly-more-modern ES technology such as Call(), Get(), and Set(). - Update their exception handling to use the abrupt completion formalism. --- index.html | 480 ++++++++++++++++++++++++++++++++---------------- index.xml | 531 +++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 694 insertions(+), 317 deletions(-) diff --git a/index.html b/index.html index d1aa02fe..cc7c331c 100644 --- a/index.html +++ b/index.html @@ -19,7 +19,7 @@ -
W3C

Web IDL (Second Edition)

W3C Editor’s Draft 11 May 2016

This Version:
http://heycam.github.io/webidl/
Latest Version:
http://www.w3.org/TR/WebIDL/
Previous Versions:
http://www.w3.org/TR/2012/CR-WebIDL-20120419/
http://www.w3.org/TR/2012/WD-WebIDL-20120207/
http://www.w3.org/TR/2011/WD-WebIDL-20110927/
http://www.w3.org/TR/2011/WD-WebIDL-20110712/
http://www.w3.org/TR/2010/WD-WebIDL-20101021/
http://www.w3.org/TR/2008/WD-WebIDL-20081219/
http://www.w3.org/TR/2008/WD-WebIDL-20080829/
http://www.w3.org/TR/2008/WD-DOM-Bindings-20080410/
http://www.w3.org/TR/2007/WD-DOM-Bindings-20071017/
Participate:
+
@@ -72,7 +72,7 @@

Status of This Document

report can be found in the W3C technical reports index at http://www.w3.org/TR/.

- This document is the 11 May 2016 Editor’s Draft of the + This document is the 19 May 2016 Editor’s Draft of the Web IDL (Second Edition) specification. Please send comments about this document to @@ -176,6 +176,7 @@

1.1. Typographic conventions

  • Unicode characters: U+0030 DIGIT ZERO ("0")
  • Extended attributes: [ExampleExtendedAttribute]
  • Variable names in prose and algorithms: exampleVariableName.
  • +
  • Algorithms use the conventions of the ECMAScript specification, including the ! and ? notation for unwrapping completion records.
  • IDL informal syntax examples:
    interface identifier {
       interface-members…
    @@ -6513,6 +6514,17 @@ 

    4.1. ECMAScript environment

    for Web pages.

  • + +

    + Although at the time of this writing the ECMAScript specification does not reflect this, + every ECMAScript object must have an associated Realm. The mechanisms + for associating objects with Realms are, for now, underspecified. However, we note that + in the case of platform objects, the + associated Realm is equal to the object's relevant Realm, and + for non-exotic function objects (i.e. not callable proxies, and not bound functions) + the associated Realm is equal to the value of the function object's [[Realm]] internal + slot. +

    @@ -7889,12 +7901,12 @@

    4.2.26. Promise types — Promise<T>

    to an IDL Promise<T> value as follows:

      -
    1. Let resolve be the original value of %Promise%.resolve. +
    2. Let resolve be the original value of %Promise%.resolve.
      Editorial note

      ECMAScript should grow a %Promise_resolve% well-known intrinsic object that can be referenced here.

    3. -
    4. Let promise be the result of calling resolve with %Promise% +
    5. Let promise be the result of calling resolve with %Promise% as the this value and V as the single argument value.
    6. Return the IDL promise type value that is a reference to the same object as promise.
    7. @@ -11860,8 +11872,8 @@

      4.6.7. Operations

    8. If the operation has a return type that is a promise type, then:
        -
      1. Let reject be the initial value of %Promise%.reject.
      2. -
      3. Return the result of calling reject with %Promise% as the +
      4. Let reject be the initial value of %Promise%.reject.
      5. +
      6. Return the result of calling reject with %Promise% as the this object and the exception as the single argument value.
      @@ -14007,6 +14019,15 @@

      4.9. User objects implementing callback interfaces

      property name that is that identifier.
    9. + +

      + Note that ECMAScript objects need not have + properties corresponding to constants + on them to be considered as user objects + implementing interfaces that happen + to have constants declared on them. +

      +

      A single operation callback interface is a callback interface that: @@ -14017,138 +14038,225 @@

      4.9. User objects implementing callback interfaces

    10. has one or more regular operations that all have the same identifier, and no others.
    11. +

      - A user object’s - operation is called - with a list of IDL argument values idlarg0..n−1 by - following the algorithm below. The callback this value - is the value to use as the this value - when a callable - object was supplied as the implementation of a - single operation callback interface. - By default, undefined is used as the callback this value, - however this MAY be overridden by other - specifications. + To call a user object's operation, given a callback interface type value value, + sometimes-optional operation name opName, list of argument values + arg0..n−1 each of which is either an IDL value or the + special value “missing” (representing a missing optional argument), and optional callback this value + thisArg, perform the following steps. These steps will either return an IDL + value or throw an exception.

      +
        -
      1. Try running the following steps: +
      2. Let completion be an uninitialized variable.
      3. + +
      4. If thisArg was not given, let thisArg be undefined.
      5. + +
      6. Let O be the ECMAScript object corresponding to value.
      7. + +
      8. Let realm be O's associated Realm.
      9. + +
      10. Let settings be realm's settings + object.
      11. + +
      12. Prepare to run script with settings.
      13. + +
      14. + Determine the implementation of the operation, X: +
          -
        1. Let V be the IDL callback interface type value - that represents the user object implementing the interface.
        2. -
        3. Let O be the ECMAScript object corresponding to V.
        4. -
        5. Let X be the implementation of the operation. If the interface is a single operation callback interface and IsCallable(O) is true, then X is O. - Otherwise, X is the result of calling - the internal [[Get]] method of O with the identifier of the operation as the property name.
        6. -
        7. If Type(X) is not Object, throw a TypeError exception.
        8. -
        9. If IsCallable(X) is false, then throw a TypeError exception.
        10. -
        11. Let this be O if the interface is not a single operation callback interface - or if IsCallable(O) is false, - and the callback this value otherwise.
        12. +
        13. If value's interface is a single operation callback + interface and ! IsCallable(O) is true, then set + X to O.
        14. +
        15. - Let arg0..n−1 be a list of - ECMAScript values, where argi is the result - of converting - idlargi to an ECMAScript value. -
        16. -
        17. Let script be the callback context associated with V.
        18. -
        19. Push script on to the stack of incumbent scripts. [HTML]
        20. -
        21. Let R be an uninitialized variable.
        22. -
        23. Try running the following step: -
            -
          1. Set R to the result of invoking the [[Call]] method of X, providing this as the this value and arg0..n−1 as the argument values.
          2. -
          - And then, whether or not an exception was thrown: + Otherwise, opName must be supplied:
            -
          1. Pop script off the stack of incumbent scripts.
          2. -
          3. If an exception was thrown, end these steps, and allow it to propagate.
          4. +
          5. Let getResult be Get(O, + opName).
          6. + +
          7. If getResult is an abrupt completion, set completion + to getResult and jump to the step labeled return.
          8. + +
          9. Set X to getResult.[[Value]].
        24. -
        25. If the operation’s return type is void, return.
        26. -
        27. - Return the result of converting - R to an IDL value of the same type as the operation’s return type. -
        - And then, if an exception was thrown: +
      15. + + +
      16. If ! IsCallable(X) is false, + then set completion to a new Completion{[[Type]]: throw, [[Value]]: a + newly created TypeError object, [[Target]]: empty}, and jump + to the step labeled return.
      17. + +
      18. If value's interface is not a single operation callback interface, + or if ! IsCallable(O) is false, + set thisArg to O (overriding the provided value).
      19. + +
      20. Let esArgs be an empty List of ECMAScript values.
      21. + +
      22. Let i be 0.
      23. + +
      24. Let count be 0.
      25. + +
      26. + While i < n: +
          -
        1. If the operation has a return type that is a promise type, then: +
        2. If argi is the special value “missing”, then + append undefined to esArgs.
        3. + +
        4. + Otherwise, argi is an IDL value: +
            -
          1. Let reject be the initial value of %Promise%.reject.
          2. -
          3. Return the result of calling reject with %Promise% as the this object and the exception as the single argument value.
          4. +
          5. Let convertResult be the result of converting + argi to an ECMAScript value.
          6. + +
          7. If convertResult is an abrupt completion, set completion + to convertResult and jump to the step labeled return.
          8. + +
          9. Append convertResult.[[Value]] to esArgs.
          10. + +
          11. Set count to i + 1.
        5. -
        6. Otherwise, end these steps and allow the exception to propagate.
        7. + +
        8. Set i to i + 1.
        9. +
        +
      27. + +
      28. Truncate esArgs to have length count.
      29. + +
      30. Let callResult be Call(X, thisArg, + esArgs).
      31. + +
      32. If callResult is an abrupt completion, set completion to + callResult and jump to the step labeled return.
      33. + +
      34. Set completion to the result of converting + callResult.[[Value]] to an IDL value of the same type as the operation’s + return type.
      35. + +
      36. + Return: at this + point completion will be set to an ECMAScript completion value. + +
          +
        1. Clean up after running script with settings.
        2. + +
        3. If completion is a normal completion, return + completion.
        4. + +
        5. If completion is an abrupt completion and the operation has a return type that is not a promise type, return completion.
        6. + +
        7. Let reject be the initial value of %Promise%.reject.
        8. + +
        9. Let rejectedPromise be the result of calling reject with + %Promise% as the this value and + completion.[[Value]] as the single argument value.
        10. + +
        11. Return the result of converting + rejectedPromise to the operation's return type.
      +

      - Note that ECMAScript objects need not have - properties corresponding to constants - on them to be considered as user objects - implementing interfaces that happen - to have constants declared on them. -

      -

      - The value of a user object’s - attribute is retrieved using the - following algorithm: + To get a user object's attribute value, given a callback interface type value object + and attribute name attributeName, perform the following steps. These steps + will either return an IDL value or throw an exception.

      +
        -
      1. Try running the following steps: -
          -
        1. Let V be the IDL callback interface type value - that represents the user object implementing the interface.
        2. -
        3. Let O be the ECMAScript object corresponding to V.
        4. -
        5. Let P be the identifier of the attribute.
        6. -
        7. Let script be the callback context associated with V.
        8. -
        9. Push script on to the stack of incumbent scripts. [HTML]
        10. -
        11. Let R be an uninitialized variable.
        12. -
        13. Try running the following step: -
            -
          1. Set R to the result of invoking the [[Get]] method of O with property name P.
          2. -
          - And then, whether or not an exception was thrown: -
            -
          1. Pop script off the stack of incumbent scripts.
          2. -
          3. If an exception was thrown, end these steps, and allow it to propagate.
          4. -
          -
        14. -
        15. Return the result of converting R to an IDL value of the same type as the attribute’s type.
        16. -
        - And then, if an exception was thrown: +
      2. Let completion be an uninitialized variable.
      3. + +
      4. Let O be the ECMAScript object corresponding to object.
      5. + +
      6. Let realm be O's associated Realm.
      7. + +
      8. Let settings be realm's settings + object.
      9. + +
      10. Prepare to run script with settings.
      11. + +
      12. Let getResult be Get(O, attributeName).
      13. + +
      14. If getResult is an abrupt completion, set completion to + getResult and jump to the step labeled return.
      15. + +
      16. Set completion to the result of converting + getResult.[[Value]] to an IDL value of the same type as the attribute's + type.
      17. + +
      18. + Return: at this + point completion will be set to an ECMAScript completion value. +
          -
        1. If the attribute has a return type that is a promise type, then: -
            -
          1. Let reject be the initial value of %Promise%.reject.
          2. -
          3. Return the result of calling reject with %Promise% as the this object and the exception as the single argument value.
          4. -
          -
        2. -
        3. Otherwise, end these steps and allow the exception to propagate.
        4. +
        5. Clean up after running script with settings.
        6. + +
        7. If completion is a normal completion, return + completion.
        8. + +
        9. If completion is an abrupt completion and the attribute's type is + not a promise type, return + completion.
        10. + +
        11. Let reject be the initial value of %Promise%.reject.
        12. + +
        13. Let rejectedPromise be the result of calling reject with + %Promise% as the this value and + completion.[[Value]] as the single argument value.
        14. + +
        15. Return the result of converting + rejectedPromise to the attribute's type.
      +

      - The value of a user object’s - attribute is set using the - following algorithm: + To set a user object's attribute value, given a callback interface type value + object, attribute name attributeName, and IDL value + value, perform the following steps. These steps will not return anything, but + could throw an exception.

      +
        -
      1. Let V be the IDL callback interface type value - that represents the user object implementing the interface.
      2. -
      3. Let O be the ECMAScript object corresponding to V.
      4. -
      5. Let P be the identifier of the attribute.
      6. -
      7. Let V be the IDL value to be assigned to the attribute.
      8. -
      9. Let W be the result of converting V to an ECMAScript value.
      10. -
      11. Let script be the callback context associated with V.
      12. -
      13. Push script on to the stack of incumbent scripts. [HTML]
      14. -
      15. Try running the following step: -
          -
        1. Invoke the [[Put]] method of O with property name P and value W.
        2. -
        - And then, whether or not an exception was thrown: +
      16. Let completion be an uninitialized variable.
      17. + +
      18. Let O be the ECMAScript object corresponding to object.
      19. + +
      20. Let realm be O's associated Realm.
      21. + +
      22. Let settings be realm's settings + object.
      23. + +
      24. Prepare to run script with settings.
      25. + +
      26. Let convertResult be the result of converting value to an + ECMAScript value.
      27. + +
      28. If convertResult is an abrupt completion, set completion to + convertResult and jump to the step labeled return.
      29. + +
      30. Set completion to Set(O, attributeName, + convertResult.[[Value]], true).
      31. + +
      32. + Return: at this + point completion will be set to an ECMAScript completion value, which is + either an abrupt completion or a normal completion for the value true (as returned by Set). +
          -
        1. Pop script off the stack of incumbent scripts.
        2. -
        3. If an exception was thrown, end these steps, and allow it to propagate.
        4. +
        5. Clean up after running script with settings.
        6. + +
        7. If completion is an abrupt completion, return + completion.
        8. + +
        9. Return NormalCompletion(void).
      @@ -14162,66 +14270,116 @@

      4.10. Invoking callback functions

      used as a callback function value is called in a manner similar to how operations on user objects are called (as - described in the previous section). The callable object - is called with a list of values - arg0..n−1, - each of which is either an IDL value of the special value “missing” (representing - a missing optional argument), by - following the algorithm below. By default, the callback this value - when invoking a callback function - is undefined, unless overridden by other specifications. + described in the previous section).

      + +

      + To invoke a callback function type value callable with + a list of arguments arg0..n−1, each of which is either + an IDL value or the special value “missing” (representing a missing optional argument), + and with optional callback this + value thisArg, perform the following steps. These steps will either + return an IDL value or throw an exception. +

      +
        -
      1. Try running the following steps: +
      2. Let completion be an uninitialized variable.
      3. + +
      4. If thisArg was not given, let thisArg be undefined.
      5. + +
      6. Let F be the ECMAScript object corresponding to value.
      7. + +
      8. + If ! IsCallable(F) is false: +
          -
        1. Let V be the IDL callback function type value.
        2. -
        3. Let F be the ECMAScript object corresponding to V.
        4. -
        5. Let R be an uninitialized variable.
        6. -
        7. If IsCallable(F) is false, then set R to the value undefined.
        8. -
        9. Otherwise, -
            -
          1. Initialize values to be an empty list of ECMAScript values.
          2. -
          3. Initialize count to 0.
          4. -
          5. Initialize i to 0.
          6. -
          7. While i < n: -
              -
            1. If argi is the special value “missing”, then append to values the ECMAScript undefined value.
            2. -
            3. Otherwise, argi is an IDL value. Append to values the result of - converting argi to an ECMAScript value, - and set count to i + 1.
            4. -
            5. Set i to i + 1.
            6. -
            -
          8. -
          9. Truncate values to have length count.
          10. -
          11. Let script be the callback context associated with V.
          12. -
          13. Push script on to the stack of incumbent scripts. [HTML]
          14. -
          15. Try running the following step: -
              -
            1. Set R to the result of invoking the [[Call]] method of F, providing the callback this value as the this value and values as the argument values.
            2. -
            - And then, whether or not an exception was thrown: -
              -
            1. Pop script off the stack of incumbent scripts.
            2. -
            3. If an exception was thrown, end these steps, and allow it to propagate.
            4. -
            -
          16. -
          -
        10. -
        11. If the callback function’s return type is void, return.
        12. - Return the result of converting - R to an IDL value of the same type as the callback function’s return type. +

          If the callback function's return type is void, + return.

          + +
          Note
          +

          This is only possible when the callback function came from an attribute + marked with [TreatNonObjectAsNull].

          +
        13. + +
        14. Return the result of converting undefined to the callback function's return type.
        - And then, if an exception was thrown: +
      9. + +
      10. Let realm be F's associated Realm.
      11. + +
      12. Let settings be realm's settings + object.
      13. + +
      14. Prepare to run script with settings.
      15. + +
      16. Let esArgs be an empty List of ECMAScript values.
      17. + +
      18. Let i be 0.
      19. + +
      20. Let count be 0.
      21. + +
      22. + While i < n: +
          -
        1. If the callback function has a return type that is a promise type, then: +
        2. If argi is the special value “missing”, then + append undefined to esArgs.
        3. + +
        4. + Otherwise, argi is an IDL value: +
            -
          1. Let reject be the initial value of %Promise%.reject.
          2. -
          3. Return the result of calling reject with %Promise% as the this object and the exception as the single argument value.
          4. +
          5. Let convertResult be the result of converting + argi to an ECMAScript value.
          6. + +
          7. If convertResult is an abrupt completion, set completion + to convertResult and jump to the step labeled return.
          8. + +
          9. Append convertResult.[[Value]] to esArgs.
          10. + +
          11. Set count to i + 1.
        5. -
        6. Otherwise, end these steps and allow the exception to propagate.
        7. + +
        8. Set i to i + 1.
        9. +
        +
      23. + +
      24. Truncate esArgs to have length count.
      25. + +
      26. Let callResult be Call(X, thisArg, + esArgs).
      27. + +
      28. If callResult is an abrupt completion, set completion to + callResult and jump to the step labeled return.
      29. + +
      30. Set completion to the result of converting + callResult.[[Value]] to an IDL value of the same type as the operation’s + return type.
      31. + +
      32. + Return: at this + point completion will be set to an ECMAScript completion value. + +
          +
        1. Clean up after running script with settings.
        2. + +
        3. If completion is a normal completion, return + completion.
        4. + +
        5. If completion is an abrupt completion and the callback function has a + return type that is not a promise type, return completion.
        6. + +
        7. Let reject be the initial value of %Promise%.reject.
        8. + +
        9. Let rejectedPromise be the result of calling reject with + %Promise% as the this value and + completion.[[Value]] as the single argument value.
        10. + +
        11. Return the result of converting + rejectedPromise to the callback function's return type.
      diff --git a/index.xml b/index.xml index 619e24f0..0af34650 100644 --- a/index.xml +++ b/index.xml @@ -82,7 +82,7 @@ - + @@ -91,6 +91,8 @@ + + + + + + + + + + + @@ -272,6 +292,7 @@
    12. Unicode characters: U+0030 DIGIT ZERO ("0")
    13. Extended attributes: [ExampleExtendedAttribute]
    14. Variable names in prose and algorithms: exampleVariableName.
    15. +
    16. Algorithms use the conventions of the ECMAScript specification, including the ! and ? notation for unwrapping completion records.
    17. IDL informal syntax examples:
      interface identifier {
         interface-members…
      @@ -6368,6 +6389,18 @@ iframe.appendChild instanceof w.Function;  // Evaluates to
                     for Web pages.
                   

    + +

    + Although at the time of this writing the ECMAScript specification does not reflect this, + every ECMAScript object must have an associated Realm. The mechanisms + for associating objects with Realms are, for now, underspecified. However, we note that + in the case of platform objects, the + associated Realm is equal to the object's relevant Realm, and + for non-exotic function objects (i.e. not callable proxies, and not bound functions) + the associated Realm is equal to the value of the function object's [[Realm]] internal + slot. +

    @@ -13889,6 +13922,15 @@ C implements A; property name that is that identifier. + +

    + Note that ECMAScript objects need not have + properties corresponding to constants + on them to be considered as user objects + implementing interfaces that happen + to have constants declared on them. +

    +

    A single operation callback interface is a callback interface that: @@ -13899,138 +13941,252 @@ C implements A;

  • has one or more regular operations that all have the same identifier, and no others.
  • +

    - A user object’s - operation is called - with a list of IDL argument values idlarg0..n−1 by - following the algorithm below. The callback this value - is the value to use as the this value - when a callable - object was supplied as the implementation of a - single operation callback interface. - By default, undefined is used as the callback this value, - however this MAY be overridden by other - specifications. + To call a user object's operation, given a callback interface type value value, + sometimes-optional operation name opName, list of argument values + arg0..n−1 each of which is either an IDL value or the + special value “missing” (representing a missing optional argument), and optional callback this value + thisArg, perform the following steps. These steps will either return an IDL + value or throw an exception.

    +
      -
    1. Try running the following steps: +
    2. Let completion be an uninitialized variable.
    3. + +
    4. If thisArg was not given, let thisArg be undefined.
    5. + +
    6. Let O be the ECMAScript object corresponding to value.
    7. + +
    8. Let realm be O's associated Realm.
    9. + +
    10. Let settings be realm's settings + object.
    11. + +
    12. Prepare to run script with settings.
    13. + +
    14. + Determine the implementation of the operation, X: +
        -
      1. Let V be the IDL callback interface type value - that represents the user object implementing the interface.
      2. -
      3. Let O be the ECMAScript object corresponding to V.
      4. -
      5. Let X be the implementation of the operation. If the interface is a single operation callback interface and IsCallable(O) is true, then X is O. - Otherwise, X is the result of calling - the internal [[Get]] method of O with the identifier of the operation as the property name.
      6. -
      7. If Type(X) is not Object, throw a TypeError exception.
      8. -
      9. If IsCallable(X) is false, then throw a TypeError exception.
      10. -
      11. Let this be O if the interface is not a single operation callback interface - or if IsCallable(O) is false, - and the callback this value otherwise.
      12. +
      13. If value's interface is a single operation callback + interface and ! IsCallable(O) is true, then set + X to O.
      14. +
      15. - Let arg0..n−1 be a list of - ECMAScript values, where argi is the result - of converting - idlargi to an ECMAScript value. -
      16. -
      17. Let script be the callback context associated with V.
      18. -
      19. Push script on to the stack of incumbent scripts. [HTML]
      20. -
      21. Let R be an uninitialized variable.
      22. -
      23. Try running the following step: -
          -
        1. Set R to the result of invoking the [[Call]] method of X, providing this as the this value and arg0..n−1 as the argument values.
        2. -
        - And then, whether or not an exception was thrown: + Otherwise, opName must be supplied:
          -
        1. Pop script off the stack of incumbent scripts.
        2. -
        3. If an exception was thrown, end these steps, and allow it to propagate.
        4. +
        5. Let getResult be Get(O, + opName).
        6. + +
        7. If getResult is an abrupt completion, set completion + to getResult and jump to the step labeled return.
        8. + +
        9. Set X to getResult.[[Value]].
      24. -
      25. If the operation’s return type is void, return.
      26. -
      27. - Return the result of converting - R to an IDL value of the same type as the operation’s return type. -
      - And then, if an exception was thrown: +
    15. + + +
    16. If ! IsCallable(X) is false, + then set completion to a new Completion{[[Type]]: throw, [[Value]]: a + newly created TypeError object, [[Target]]: empty}, and jump + to the step labeled return.
    17. + +
    18. If value's interface is not a single operation callback interface, + or if ! IsCallable(O) is false, + set thisArg to O (overriding the provided value).
    19. + +
    20. Let esArgs be an empty List of ECMAScript values.
    21. + +
    22. Let i be 0.
    23. + +
    24. Let count be 0.
    25. + +
    26. + While i < n: +
        -
      1. If the operation has a return type that is a promise type, then: +
      2. If argi is the special value “missing”, then + append undefined to esArgs.
      3. + +
      4. + Otherwise, argi is an IDL value: +
          -
        1. Let reject be the initial value of %Promise%.reject.
        2. -
        3. Return the result of calling reject with %Promise% as the this object and the exception as the single argument value.
        4. +
        5. Let convertResult be the result of converting + argi to an ECMAScript value.
        6. + +
        7. If convertResult is an abrupt completion, set completion + to convertResult and jump to the step labeled return.
        8. + +
        9. Append convertResult.[[Value]] to esArgs.
        10. + +
        11. Set count to i + 1.
      5. -
      6. Otherwise, end these steps and allow the exception to propagate.
      7. + +
      8. Set i to i + 1.
      9. +
      +
    27. + +
    28. Truncate esArgs to have length count.
    29. + +
    30. Let callResult be Call(X, thisArg, + esArgs).
    31. + +
    32. If callResult is an abrupt completion, set completion to + callResult and jump to the step labeled return.
    33. + +
    34. Set completion to the result of converting + callResult.[[Value]] to an IDL value of the same type as the operation’s + return type.
    35. + +
    36. + Return: at this + point completion will be set to an ECMAScript completion value. + +
        +
      1. Clean up after running script with settings.
      2. + +
      3. If completion is a normal completion, return + completion.
      4. + +
      5. If completion is an abrupt completion and the operation has a return type that is not a promise type, return completion.
      6. + +
      7. Let reject be the initial value of %Promise%.reject.
      8. + +
      9. Let rejectedPromise be the result of calling reject with + %Promise% as the this value and + completion.[[Value]] as the single argument value.
      10. + +
      11. Return the result of converting + rejectedPromise to the operation's return type.
    +

    - Note that ECMAScript objects need not have - properties corresponding to constants - on them to be considered as user objects - implementing interfaces that happen - to have constants declared on them. -

    -

    - The value of a user object’s - attribute is retrieved using the - following algorithm: + To get a user object's attribute value, given a callback interface type value object + and attribute name attributeName, perform the following steps. These steps + will either return an IDL value or throw an exception.

    +
      -
    1. Try running the following steps: -
        -
      1. Let V be the IDL callback interface type value - that represents the user object implementing the interface.
      2. -
      3. Let O be the ECMAScript object corresponding to V.
      4. -
      5. Let P be the identifier of the attribute.
      6. -
      7. Let script be the callback context associated with V.
      8. -
      9. Push script on to the stack of incumbent scripts. [HTML]
      10. -
      11. Let R be an uninitialized variable.
      12. -
      13. Try running the following step: -
          -
        1. Set R to the result of invoking the [[Get]] method of O with property name P.
        2. -
        - And then, whether or not an exception was thrown: -
          -
        1. Pop script off the stack of incumbent scripts.
        2. -
        3. If an exception was thrown, end these steps, and allow it to propagate.
        4. -
        -
      14. -
      15. Return the result of converting R to an IDL value of the same type as the attribute’s type.
      16. -
      - And then, if an exception was thrown: +
    2. Let completion be an uninitialized variable.
    3. + +
    4. Let O be the ECMAScript object corresponding to object.
    5. + +
    6. Let realm be O's associated Realm.
    7. + +
    8. Let settings be realm's settings + object.
    9. + +
    10. Prepare to run script with settings.
    11. + +
    12. Let getResult be Get(O, attributeName).
    13. + +
    14. If getResult is an abrupt completion, set completion to + getResult and jump to the step labeled return.
    15. + +
    16. Set completion to the result of converting + getResult.[[Value]] to an IDL value of the same type as the attribute's + type.
    17. + +
    18. + Return: at this + point completion will be set to an ECMAScript completion value. +
        -
      1. If the attribute has a return type that is a promise type, then: -
          -
        1. Let reject be the initial value of %Promise%.reject.
        2. -
        3. Return the result of calling reject with %Promise% as the this object and the exception as the single argument value.
        4. -
        -
      2. -
      3. Otherwise, end these steps and allow the exception to propagate.
      4. +
      5. Clean up after running script with settings.
      6. + +
      7. If completion is a normal completion, return + completion.
      8. + +
      9. If completion is an abrupt completion and the attribute's type is + not a promise type, return + completion.
      10. + +
      11. Let reject be the initial value of %Promise%.reject.
      12. + +
      13. Let rejectedPromise be the result of calling reject with + %Promise% as the this value and + completion.[[Value]] as the single argument value.
      14. + +
      15. Return the result of converting + rejectedPromise to the attribute's type.
    +

    - The value of a user object’s - attribute is set using the - following algorithm: + To set a user object's attribute value, given a callback interface type value + object, attribute name attributeName, and IDL value + value, perform the following steps. These steps will not return anything, but + could throw an exception.

    +
      -
    1. Let V be the IDL callback interface type value - that represents the user object implementing the interface.
    2. -
    3. Let O be the ECMAScript object corresponding to V.
    4. -
    5. Let P be the identifier of the attribute.
    6. -
    7. Let V be the IDL value to be assigned to the attribute.
    8. -
    9. Let W be the result of converting V to an ECMAScript value.
    10. -
    11. Let script be the callback context associated with V.
    12. -
    13. Push script on to the stack of incumbent scripts. [HTML]
    14. -
    15. Try running the following step: -
        -
      1. Invoke the [[Put]] method of O with property name P and value W.
      2. -
      - And then, whether or not an exception was thrown: +
    16. Let completion be an uninitialized variable.
    17. + +
    18. Let O be the ECMAScript object corresponding to object.
    19. + +
    20. Let realm be O's associated Realm.
    21. + +
    22. Let settings be realm's settings + object.
    23. + +
    24. Prepare to run script with settings.
    25. + +
    26. Let convertResult be the result of converting value to an + ECMAScript value.
    27. + +
    28. If convertResult is an abrupt completion, set completion to + convertResult and jump to the step labeled return.
    29. + +
    30. Set completion to Set(O, attributeName, + convertResult.[[Value]], true).
    31. + +
    32. + Return: at this + point completion will be set to an ECMAScript completion value, which is + either an abrupt completion or a normal completion for the value true (as returned by Set). +
        -
      1. Pop script off the stack of incumbent scripts.
      2. -
      3. If an exception was thrown, end these steps, and allow it to propagate.
      4. +
      5. Clean up after running script with settings.
      6. + +
      7. If completion is an abrupt completion, return + completion.
      8. + +
      9. Return NormalCompletion(void).
    @@ -14044,66 +14200,129 @@ C implements A; used as a callback function value is called in a manner similar to how operations on user objects are called (as - described in the previous section). The callable object - is called with a list of values - arg0..n−1, - each of which is either an IDL value of the special value “missing” (representing - a missing optional argument), by - following the algorithm below. By default, the callback this value - when invoking a callback function - is undefined, unless overridden by other specifications. + described in the previous section).

    + +

    + To invoke a callback function type value callable with + a list of arguments arg0..n−1, each of which is either + an IDL value or the special value “missing” (representing a missing optional argument), + and with optional callback this + value thisArg, perform the following steps. These steps will either + return an IDL value or throw an exception. +

    +
      -
    1. Try running the following steps: +
    2. Let completion be an uninitialized variable.
    3. + +
    4. If thisArg was not given, let thisArg be undefined.
    5. + +
    6. Let F be the ECMAScript object corresponding to value.
    7. + +
    8. + If ! IsCallable(F) is false: +
        -
      1. Let V be the IDL callback function type value.
      2. -
      3. Let F be the ECMAScript object corresponding to V.
      4. -
      5. Let R be an uninitialized variable.
      6. -
      7. If IsCallable(F) is false, then set R to the value undefined.
      8. -
      9. Otherwise, -
          -
        1. Initialize values to be an empty list of ECMAScript values.
        2. -
        3. Initialize count to 0.
        4. -
        5. Initialize i to 0.
        6. -
        7. While i < n: -
            -
          1. If argi is the special value “missing”, then append to values the ECMAScript undefined value.
          2. -
          3. Otherwise, argi is an IDL value. Append to values the result of - converting argi to an ECMAScript value, - and set count to i + 1.
          4. -
          5. Set i to i + 1.
          6. -
          -
        8. -
        9. Truncate values to have length count.
        10. -
        11. Let script be the callback context associated with V.
        12. -
        13. Push script on to the stack of incumbent scripts. [HTML]
        14. -
        15. Try running the following step: -
            -
          1. Set R to the result of invoking the [[Call]] method of F, providing the callback this value as the this value and values as the argument values.
          2. -
          - And then, whether or not an exception was thrown: -
            -
          1. Pop script off the stack of incumbent scripts.
          2. -
          3. If an exception was thrown, end these steps, and allow it to propagate.
          4. -
          -
        16. -
        -
      10. -
      11. If the callback function’s return type is void, return.
      12. - Return the result of converting - R to an IDL value of the same type as the callback function’s return type. +

        If the callback function's return type is void, + return.

        + +
        +

        This is only possible when the callback function came from an attribute + marked with [TreatNonObjectAsNull].

        +
      13. + +
      14. Return the result of converting undefined to the callback function's return type.
      - And then, if an exception was thrown: +
    9. + +
    10. Let realm be F's associated Realm.
    11. + +
    12. Let settings be realm's settings + object.
    13. + +
    14. Prepare to run script with settings.
    15. + +
    16. Let esArgs be an empty List of ECMAScript values.
    17. + +
    18. Let i be 0.
    19. + +
    20. Let count be 0.
    21. + +
    22. + While i < n: +
        -
      1. If the callback function has a return type that is a promise type, then: +
      2. If argi is the special value “missing”, then + append undefined to esArgs.
      3. + +
      4. + Otherwise, argi is an IDL value: +
          -
        1. Let reject be the initial value of %Promise%.reject.
        2. -
        3. Return the result of calling reject with %Promise% as the this object and the exception as the single argument value.
        4. +
        5. Let convertResult be the result of converting + argi to an ECMAScript value.
        6. + +
        7. If convertResult is an abrupt completion, set completion + to convertResult and jump to the step labeled return.
        8. + +
        9. Append convertResult.[[Value]] to esArgs.
        10. + +
        11. Set count to i + 1.
      5. -
      6. Otherwise, end these steps and allow the exception to propagate.
      7. + +
      8. Set i to i + 1.
      9. +
      +
    23. + +
    24. Truncate esArgs to have length count.
    25. + +
    26. Let callResult be Call(X, thisArg, + esArgs).
    27. + +
    28. If callResult is an abrupt completion, set completion to + callResult and jump to the step labeled return.
    29. + +
    30. Set completion to the result of converting + callResult.[[Value]] to an IDL value of the same type as the operation’s + return type.
    31. + +
    32. + Return: at this + point completion will be set to an ECMAScript completion value. + +
        +
      1. Clean up after running script with settings.
      2. + +
      3. If completion is a normal completion, return + completion.
      4. + +
      5. If completion is an abrupt completion and the callback function has a + return type that is not a promise type, return completion.
      6. + +
      7. Let reject be the initial value of %Promise%.reject.
      8. + +
      9. Let rejectedPromise be the result of calling reject with + %Promise% as the this value and + completion.[[Value]] as the single argument value.
      10. + +
      11. Return the result of converting + rejectedPromise to the callback function's return type.