Re: [heycam/webidl] Modernize invoking user code (#113)

>                  <li>
>                    Let <var>arg</var><sub>0..<var>n</var>−1</sub> be a list of
>                    ECMAScript values, where <var>arg</var><sub><var>i</var></sub> is the result
>                    of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
>                    <var>idlarg</var><sub><var>i</var></sub> to an ECMAScript value.
>                  </li>
> -                <li>Let <var>script</var> be the <a class="dfnref" href="#dfn-callback-context">callback context</a> associated with <var>V</var>.</li>
> -                <li>Push <var>script</var> on to the <a class="dfnref external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html">stack of incumbent scripts</a>. <a href="#ref-HTML">[HTML]</a></li>
> +                <li>Let <var>execution context</var> be <a class="external" href="https://tc39.github.io/ecma262/#sec-getfunctionrealm">GetFunctionRealm</a>(<var>X</var>)'s <a class="dfnref external" href="https://html.spec.whatwg.org/multipage/webappapis.html#concept-realm-settings-object">settings object</a>'s <a class="external" href="https://html.spec.whatwg.org/multipage/webappapis.html#realm-execution-context">realm execution context</a>.</li>

Wait, no, that doesn't work. Ugh.

Check me on this: no matter what, "dispatch an event" wants to report errors for the HTML script corresponding to the event handler function's, or `handleEvent` getter function's, [[ScriptOrModule]]. That script is where it will get the filename/line number/column number.

In both cases in your examples, this is window A: `new Function` uses the currently active script-or-module to fill the created function's [[ScriptOrModule]]. The currently active script-or-module is your main-document `<script>` tag. This makes sense: the actual line of code declaring those functions is inside that window-A `<script>` tag.

(If you had created examples where the function was declared inside window B or window C, instead of using window B or window C's `Function` constructor to create them while inside window A, then it would be a different story. But it would still make sense: a function declared in window B's `srcdoc`'s `<script>` should get errors reported using that script's filename/line number/column number.)

However, the question is which global it dispatches `"error"` events to.

Two approaches:

- It grabs the global of that script to fire `error` events toward. E.g., we define "the script of a callback value or callback interface value" and the "inner invoke" algorithm says "If this throws an exception, report the exception to the script of _callback_."

  This is window A in both your examples. (But, if we modified them to declare the function in window B or C, it would be window B or C.)

- We set up something to be the entry global before doing the Get(). We dispatch the error event to the entry global at the time of the error. E.g., we modify "report an exception" to take separate script and global parameters. Then in the "inner invoke" algorithm we say "If this throws an exception, report the exception given the script of _callback_ and the entry global at the time of invocation."

  If we do this, we need to figure out what entry global to set up (assume every object has a realm? then we can get B).

The first of these approaches sounds better to me, to be honest.

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/pull/113/files/2687a7f8dee42781c250ffc11c084f1ef84d1bf4#r62943439

Received on Wednesday, 11 May 2016 23:22:03 UTC