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

Ms2ger 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

Okay, thanks for clarifying. I wrote some tests, and it turns out no two browsers agree. I updated the PR to match my understanding of what ES does, based on your comment. Note that this doesn't match Gecko if NewTarget has a prototype property that isn't an object.

<table>
<thead>
<tr><th>Test <th>Gecko <th>WebKit <th>Chrome
<tbody>
<tr><th colspan=4>new DOMParser()
<tr><th>Prototype <td colspan=3>DOMParser.&shy;prototype
<tr><th>Object realm <td colspan=3>parent window
<tr><th colspan=4>new i.&shy;contentWindow.&shy;DOMParser()
<tr><th>Prototype <td colspan=3>i.&shy;contentWindow.&shy;DOMParser.&shy;prototype
<tr><th>Object realm <td colspan=3>child window
<tr><th colspan=4>Reflect.&shy;construct(i.&shy;contentWindow.&shy;DOMParser, [], DOMParser)
<tr><th>Prototype <td>DOMParser.&shy;prototype <td>i.&shy;contentWindow.&shy;DOMParser.&shy;prototype <td>DOMParser.&shy;prototype
<tr><th>Object realm <td>child window <td>child window <td>parent window
<tr><th colspan=4>Reflect.&shy;construct(DOMParser, [], i.&shy;contentWindow.&shy;DOMParser)
<tr><th>Prototype <td>i.&shy;contentWindow.&shy;DOMParser.&shy;prototype <td>DOMParser.&shy;prototype <td>i.&shy;contentWindow.&shy;DOMParser.&shy;prototype
<tr><th>Object realm <td>parent window <td>parent window <td>child window
<tr><th colspan=4>Reflect.&shy;construct(i.&shy;contentWindow.&shy;DOMParser, [], cons)
<tr><th>Prototype <td>i.&shy;contentWindow.&shy;DOMParser.&shy;prototype <td>i.&shy;contentWindow.&shy;DOMParser.&shy;prototype <td>Object.&shy;prototype
<tr><th>Object realm <td>child window <td>child window <td>parent window
<tr><th colspan=4>Reflect.&shy;construct(DOMParser, [], i.&shy;contentWindow.&shy;cons)
<tr><th>Prototype <td>DOMParser.&shy;prototype <td>DOMParser.&shy;prototype <td>i.&shy;contentWindow.&shy;Object.&shy;prototype
<tr><th>Object realm <td>parent window <td>parent window <td>child window
<tr><th colspan=4>Conclusion
<tr><th>Prototype <td>From NewTarget; fallback to interface object from constructor's realm <td>Interface object from constructor's realm <td>From NewTarget; fallback to Object.prototype from NewTarget's realm
<tr><th>Object realm <td>From constructor <td>From constructor <td>From NewTarget
</table>

<details>
<summary>Test</summary>

```html
<!DOCTYPE html>
<script>
function identify(proto, i) {
  if (proto === Object.prototype)
    return "Object.prototype";

  if (proto === i.contentWindow.Object.prototype)
    return "i.contentWindow.Object.prototype";

  if (proto === DOMParser.prototype)
    return "DOMParser.prototype";

  if (proto === i.contentWindow.DOMParser.prototype)
    return "i.contentWindow.DOMParser.prototype";

  return "???"
}

function object_realm(dp) {
  var url = DOMParser.prototype.parseFromString.call(dp, "x", "text/html").documentURI;
  if (url === "http://software.hixie.ch/utilities/js/live-dom-viewer/")
    return "parent window";

  if (url === "http://software.hixie.ch/utilities/js/live-dom-viewer/document")
    return "child window";

  return "???";
}

function f(i) {
var dp = new DOMParser();
w("new DOMParser()");
w(identify(dp.__proto__, i));
w(object_realm(dp));
w("");

dp = new i.contentWindow.DOMParser();
w("new i.contentWindow.DOMParser()");
w(identify(dp.__proto__, i));
w(object_realm(dp));
w("");

dp = Reflect.construct(i.contentWindow.DOMParser, [], DOMParser);
w("Reflect.construct(i.contentWindow.DOMParser, [], DOMParser)");
w(identify(dp.__proto__, i));
w(object_realm(dp));
w("");

dp = Reflect.construct(DOMParser, [], i.contentWindow.DOMParser);
w("Reflect.construct(DOMParser, [], i.contentWindow.DOMParser)");
w(identify(dp.__proto__, i));
w(object_realm(dp));
w("");

var cons = function() {};
cons.prototype = 7;

dp = Reflect.construct(i.contentWindow.DOMParser, [], cons);
w("Reflect.construct(i.contentWindow.DOMParser, [], cons)");
w(identify(dp.__proto__, i));
w(object_realm(dp));
w("");

var script = i.contentWindow.document.createElement("script");
script.textContent = "window.cons = function() {}; cons.prototype = 8;";
i.contentWindow.document.documentElement.appendChild(script);

dp = Reflect.construct(DOMParser, [], i.contentWindow.cons);
w("Reflect.construct(DOMParser, [], i.contentWindow.cons)");
w(identify(dp.__proto__, i));
w(object_realm(dp));
w("");

}
</script>
<iframe src=document onload=f(this)></iframe>
```
</summary>

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

Received on Tuesday, 19 February 2019 11:48:15 UTC