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

bzbarsky commented on this pull request.



> @@ -10699,14 +10714,18 @@ the <code>typeof</code> operator will return "function" when applied to an inter
         1.  Let &lt;|constructor|, |values|&gt; be the result
             of passing |S| and |args|.
             to the [=overload resolution algorithm=].
-        1.  Let |R| be the result of performing
-            the actions listed in the description of |constructor|
-            with |values| as the argument values.
+        1.  Let |targetRealm| be [$GetFunctionRealm$]({{NewTarget}}).
+        1.  Let |object| be the result of [=internally create a new object implementing the

ES builtins get the default prototype to use if NewTarget's `.prototype` is not an object in the realm of NewTarget, which is what I thought https://github.com/heycam/webidl/pull/635#discussion_r254879231 was talking about.  But they create the object in the current Realm.  Which is not observable in ES so far (without weakrefs), because you can't observe a Realm for non-Function objects.  But if you look at the unrolled steps from ES, the ObjectCreate is happening at a point when the current Realm is the Realm of the constructor.

Note that ES is actually kinda internally inconsistent here.  In particular, if you look at https://tc39.github.io/ecma262/#sec-ecmascript-function-objects-construct-argumentslist-newtarget (the [[Construct]] for normal scripted functions), it does the ObjectCreate before entering the Realm of the function itself.  So this creation happens in whatever Realm you're in when you call the constructor, which can be neither the Realm of the constructor nor the Realm of the NewTarget.  This came up recently in https://phabricator.services.mozilla.com/D19760#519322 and is likely a spec issue if object realms become observable.

On the other hand, for a built-in function (like Map, say, or any of the Web IDL constructors) the [[Construct]] is defined as https://tc39.github.io/ecma262/#sec-built-in-function-objects-construct-argumentslist-newtarget which just defers to https://tc39.github.io/ecma262/#sec-built-in-function-objects-call-thisargument-argumentslist with step 10 changed.  Importantly, there is no object-creation here outside of step 10 doing whatever it does, and we enter the Realm of the constructor in step 9.  So let's look at the Map constructor, to consider something specific.  It's defined at https://tc39.github.io/ecma262/#sec-map-iterable and calls https://tc39.github.io/ecma262/#sec-ordinarycreatefromconstructor which calls `ObjectCreate` while in the Realm of the Map constructor itself.  Again, the proto comes from whatever NewTarget is, but the actual object comes from the current Realm.

-- 
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_r256939632

Received on Thursday, 14 February 2019 17:44:59 UTC