Re: [heycam/webidl] Define "implements" checks using internal slots (#595)

bzbarsky commented on this pull request.



>  Every [=platform object=] is associated with a global environment, just
 as the [=initial objects=] are.
 It is the responsibility of specifications using Web IDL to state
 which global environment (or, by proxy, which global object) each platform
 object is associated with.
 
+<div algorithm>
+    To <dfn>create an object implementing the interface</dfn> |interface|, with optional
+    intenal slots |slots| and |new.target| value |newTarget|, for an interface which is not
+    declared with the [{{Global}}] [=extended attribute=], perform the following steps:
+
+    1. If |slots| is provided, append \[[PrimaryInterface]] to |slots|.
+    1. Otherwise, let |slots| be &laquo; \[[PrimaryInterface]] &raquo;.
+    1. If |NewTarget| is provided, let |instance| be ? [$OrdinaryCreateFromConstructor$](|newTarget|, "%ObjectPrototype%")
+    1. Otherwise,
+        1. Let |realm| be the [=relevant Realm=] of the |this| value that led to the execution of this algorithm.

This may not exist either.  Simple example: the HTML parser.  It's creating objects without any |this| value involved, or any script anywhere in sight.

>  Every [=platform object=] is associated with a global environment, just
 as the [=initial objects=] are.
 It is the responsibility of specifications using Web IDL to state
 which global environment (or, by proxy, which global object) each platform
 object is associated with.
 
+<div algorithm>
+    To <dfn>create an object implementing the interface</dfn> |interface|, with optional
+    intenal slots |slots| and |new.target| value |newTarget|, for an interface which is not
+    declared with the [{{Global}}] [=extended attribute=], perform the following steps:
+
+    1. If |slots| is provided, append \[[PrimaryInterface]] to |slots|.
+    1. Otherwise, let |slots| be &laquo; \[[PrimaryInterface]] &raquo;.
+    1. If |NewTarget| is provided, let |instance| be ? [$OrdinaryCreateFromConstructor$](|newTarget|, "%ObjectPrototype%")

I don't think this does the right thing, because not all web platform objects are ordinary objects (due to things like legacygetters and whatnot), but OrdinaryCreateFromConstructor explicitly creates an ordinary object.  Not sure how best to deal with that.

Also, this does not match existing browser behavior, which I think is the right behavior, for the cases when a prototype cannot be derived from `newTarget`.  This would create the object with proto set to `%ObjectPrototype%`, but we want to create it with proto set to the default prototype for the given interface in the correct Realm (the current Realm, which I believe would in fact always exist when `newTarget` exists.

As a minor nit, is it `newTarget` or `NewTarget`?  Should be consistent.

>  Every [=platform object=] is associated with a global environment, just
 as the [=initial objects=] are.
 It is the responsibility of specifications using Web IDL to state
 which global environment (or, by proxy, which global object) each platform
 object is associated with.
 
+<div algorithm>
+    To <dfn>create an object implementing the interface</dfn> |interface|, with optional
+    intenal slots |slots| and |new.target| value |newTarget|, for an interface which is not
+    declared with the [{{Global}}] [=extended attribute=], perform the following steps:
+
+    1. If |slots| is provided, append \[[PrimaryInterface]] to |slots|.
+    1. Otherwise, let |slots| be &laquo; \[[PrimaryInterface]] &raquo;.
+    1. If |NewTarget| is provided, let |instance| be ? [$OrdinaryCreateFromConstructor$](|newTarget|, "%ObjectPrototype%")
+    1. Otherwise,
+        1. Let |realm| be the [=relevant Realm=] of the |this| value that led to the execution of this algorithm.
+        1. Let |proto| be the [=interface prototype object=] of |interface| in |realm|.
+        1. Let |instance| be [$ObjectCreate$](|proto|, |slots|).

Again, this always creates ordinary objects...

The ES spec really doesn't have great hooks for creating exotic objects, does it?  :(

-- 
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/595#pullrequestreview-184321335

Received on Wednesday, 12 December 2018 18:20:01 UTC