Re: [heycam/webidl] Add an algorithm to create a platform object. (#635)

domenic commented on this pull request.



> @@ -13327,7 +13363,7 @@ Each {{DOMException}} object has an associated <dfn for="DOMException">name</dfn
 The <dfn constructor for="DOMException"><code>DOMException(|message|, |name|)</code></dfn>
 constructor, when invoked, must run these steps:
 
-1. Let |e| be a new {{DOMException}} object.
+1. Let |e| be a [=new=] {{DOMException}} object in {{NewTarget}}'s Realm, with {{NewTarget}}.

Oh wow, so, this is more complicated than I thought, and you are right that "in the current Realm" is not right. But I think just passing in "NewTarget's realm" might not be right either?

Here is what ES does, unrolled and inlined:

1. Let newTarget be NewTarget, if it is not undefined, or the active function object (i.e. the currently-executing DOMException constructor), if NewTarget is undefined.
1. Let proto be Get(newTarget, "prototype").
1. If Type(proto) is not Object, then:
   1. Let realm be GetFunctionRealm(newTarget).
   1. Set proto to the DOMException interface prototype object in realm.
1. Let object be ObjectCreate(proto, internalSlotsList).
1. ... do stuff to object ...
1. Return object.

In particular accounting for an undefined NewTarget (possible via Reflect.construct) seems like it makes just passing in NewTarget's realm not ideal.

I'm not sure what the ideal setup is, but here are my pointers:

1. We should have "new", with no arguments, do the right thing inside constructors. (When applied to the relevant constructor, as you point out.) By "the right thing" we mean, congruent with the unrolled ES spec I have done above.
1. In other cases, "new" should take a single Realm argument.

Let me know if that's enough to go on. Tricky stuff...

-- 
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/635#discussion_r255146339

Received on Friday, 8 February 2019 16:37:10 UTC