tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

invalid-this-value-cross-realm.html (2633B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Cross-realm getter / setter / operation doesn't use lexical global object to throw an error for incompatible |this| value</title>
      4 <link rel="help" href="https://webidl.spec.whatwg.org/#dfn-attribute-getter">
      5 <link rel="help" href="https://webidl.spec.whatwg.org/#dfn-attribute-setter">
      6 <link rel="help" href="https://webidl.spec.whatwg.org/#dfn-create-operation-function">
      7 
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 <script src="support/create-realm.js"></script>
     11 
     12 <body>
     13 <script>
     14 promise_test(async t => {
     15    const other = await createRealm(t);
     16    const notElement = Object.create(other.HTMLElement.prototype);
     17 
     18    assert_throws_js(other.TypeError, () => { Object.create(other.document).head; });
     19    assert_throws_js(other.TypeError, () => { Object.getOwnPropertyDescriptor(other.HTMLElement.prototype, "title").get.call(notElement); });
     20    assert_throws_js(other.TypeError, () => { Reflect.get(other.document.createElement("div"), "hidden", notElement); });
     21    assert_throws_js(other.TypeError, () => { new Proxy(other.text, {}).nodeType; });
     22 }, "Cross-realm getter throws when called on incompatible object");
     23 
     24 promise_test(async t => {
     25    const other = await createRealm(t);
     26    const notElement = Object.create(other.HTMLElement.prototype);
     27    const notText = Object.create(other.Text.prototype);
     28 
     29    assert_throws_js(other.TypeError, () => { Object.create(other.element).innerHTML = ""; });
     30    assert_throws_js(other.TypeError, () => { Object.getOwnPropertyDescriptor(other.HTMLElement.prototype, "onclick").set.call(notElement, null); });
     31    assert_throws_js(other.TypeError, () => { Reflect.set(new other.Text("foo"), "data", "foo", notText); });
     32    assert_throws_js(other.TypeError, () => { new Proxy(other.document, {}).title = ""; });
     33 }, "Cross-realm setter throws when called on incompatible object");
     34 
     35 promise_test(async t => {
     36    const other = await createRealm(t);
     37    const notDocument = Object.create(other.HTMLDocument.prototype);
     38    const notText = Object.create(other.Text.prototype);
     39 
     40    assert_throws_js(other.TypeError, () => { Object.create(other.element).click(); });
     41    assert_throws_js(other.TypeError, () => { other.document.querySelector.call(notDocument, "*"); });
     42    assert_throws_js(other.TypeError, () => { Reflect.apply(other.text.remove, notText, []); });
     43    assert_throws_js(other.TypeError, () => { new Proxy(other.document.createElement("a"), {}).addEventListener("foo", () => {}); });
     44 }, "Cross-realm operation throws when called on incompatible object");
     45 </script>