Re: [heycam/webidl] Environment stuff for exception throwing is nonsense (#292)

That's not really viable, in my opinion, because for a number of these exceptions there is no "this" to speak of.

As a simple example, the SecurityErrors thrown by cross-origin windows really shouldn't use the "relevant realm" of the cross-origin target, because then you wouldn't even be able to examine the exceptions, right?

Same thing for Web IDL algorithms of various sorts.  For example, https://heycam.github.io/webidl/#dfn-create-operation-function step 2.1.2.4.  What is "the relevant realm of this" in that case?

The example code you mention is ... unclear to me.  Is it actually calling the computeSquareRoot function (the JS function) and having it throw?  Or is it performing its underlying steps without calling through JS?  It matters in terms of the current global, obviously.

I should also note that IDL does say:

> Any requirements in this document to throw an instance of an ECMAScript built-in Error must use the built-in from the current global environment.

which means it's actually trying to specify different behavior for Error and TypeError, for reasons that are entirely unclear to me....

Anyway, in practical terms, I think that implementations don't necessarily represent exceptions as objects internally, and their internal representations may not admit attaching a global to them (not least for efficiency reasons).  As a result in practice exceptions are given a global in the binding layer.  I did just check, as a simple example, what WebKit, Blink, and Gecko do for querySelector.  WebKit has `ec = SYNTAX_ERR;` where `ec` is an `ExceptionCode&`.  Blink has `exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is not a valid selector.");` and Gecko has `aRv.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR, NS_LITERAL_CSTRING("'") + NS_ConvertUTF16toUTF8(aSelectorString) + NS_LITERAL_CSTRING("' is not a valid selector")` none of which attach a global at the exception throw point.

-- 
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/issues/292#issuecomment-277383956

Received on Friday, 3 February 2017 22:49:36 UTC