@@ -87643,25 +87643,45 @@ interface <dfn>NavigatorOnLine</dfn> {
8764387643 <code>Navigator</code> object on which it is invoked. This has the following impact: <ref
8764487644 spec=BATTERY>
8764587645
87646- <pre><!DOCTYPE html>
87646+ <pre><!-- outer.html -->
87647+ <!DOCTYPE html>
8764787648<html lang="en">
87648- <title>Relevant Realm demo</title>
87649+ <title>Relevant Realm demo: outer page</title>
87650+ <script>
87651+ function doTest() {
87652+ const promise = navigator.getBattery().call(frames[0].navigator);
87653+
87654+ console.log(promise instanceof Promise); // logs false
87655+ console.log(promise instanceof frames[0].Promise); // logs true
87656+
87657+ frames[0].hello();
87658+ }
87659+ </script>
87660+ <iframe src="inner.html" onload="doTest()"></iframe>
8764987661
87650- <iframe src="about:blank"></iframe>
87662+ <!-- inner.html -->
87663+ <!DOCTYPE html>
87664+ <html lang="en">
87665+ <title>Relevant Realm demo: inner page</title>
8765187666<script>
87652- const promise = navigator.getBattery().call(frames[0].navigator);
87667+ function hello() {
87668+ const promise = navigator.getBattery();
8765387669
87654- console.log(promise instanceof Promise); // logs false
87655- console.log(promise instanceof frames[0].Promise); // logs true
87670+ console.log(promise instanceof Promise); // logs true
87671+ console.log(promise instanceof parent.Promise); // logs false
87672+ }
8765687673</script></pre>
8765787674
8765887675 <p>If the algorithm for the <code data-x="dom-navigator-getBattery">getBattery()</code> method
87659- had instead used the <span data-x="current Realm Record">current Realm</span>, the results would
87660- be reversed. The downside of such an approach would be that all future calls to that frame's
87661- <code data-x="dom-navigator-getBattery">getBattery()</code>, even ones from within the
87662- <code>iframe</code> and without cross-frame shenanigans, would forever return <code
87663- data-x="">Promise</code> objects from the outer realm. Since this is undesirable, the algorithm
87664- instead uses the <span data-x="concept-relevant-realm">relevant Realm</span>.</p>
87676+ had instead used the <span data-x="current Realm Record">current Realm</span>, all the results
87677+ would be reversed. That is, after the first call to <code
87678+ data-x="dom-navigator-getBattery">getBattery()</code> in <code data-x="">outer.html</code>, the
87679+ <code>Navigator</code> object in <code data-x="">inner.html</code> would be permanently storing
87680+ a <code data-x="">Promise</code> object created in <code data-x="">outer.html</code>'s
87681+ <span>JavaScript realm</span>, and calls like that inside the <code data-x="">hello()</code>
87682+ function would thus return a promise from the "wrong" realm. Since this is undesirable, the
87683+ algorithm instead uses the <span data-x="concept-relevant-realm">relevant Realm</span>, giving
87684+ the sensible results indicated in the comments above.</p>
8766587685 </div>
8766687686
8766787687 <hr>
0 commit comments