diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/xpconnect/tests/mochitest/test_private_field_dom.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/xpconnect/tests/mochitest/test_private_field_dom.html | 221 |
1 files changed, 221 insertions, 0 deletions
diff --git a/js/xpconnect/tests/mochitest/test_private_field_dom.html b/js/xpconnect/tests/mochitest/test_private_field_dom.html new file mode 100644 index 0000000000..4a50c7ca95 --- /dev/null +++ b/js/xpconnect/tests/mochitest/test_private_field_dom.html @@ -0,0 +1,221 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=???? +--> + +<head> + <meta charset="utf-8"> + <title>Test for Bug ????</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> + <iframe id="ifr"></iframe> +</head> + +<body> + <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1094930">Mozilla Bug 1094930</a> + <p id="display"></p> + <div id="test_contents"> + <!-- Extracted from nsHTMLTagList.h --> + <applet></applet> + <area></area> + <audio></audio> + <base> + </base> + <bgsound></bgsound> + <blockquote></blockquote> + + <body></body> + <br></br> + <button></button> + <canvas></canvas> + <caption></caption> + <col> + </col> + <colgroup></colgroup> + <data></data> + <datalist></datalist> + <del></del> + <details></details> + <dialog></dialog> + <dir></dir> + <div></div> + <dl></dl> + <embed></embed> + <fieldset></fieldset> + <font></font> + <form></form> + <frame></frame> + <frameset></frameset> + <h1></h1> + <h2></h2> + <h3></h3> + <h4></h4> + <h5></h5> + <h6></h6> + + <head></head> + <hr> + </hr> + <html> + + </html> + <iframe></iframe> + <img></img> + <input></input> + <ins></ins> + <keygen></keygen> + <label></label> + <legend></legend> + <li></li> + <link> + </link> + <listing></listing> + <map></map> + <marquee></marquee> + <menu></menu> + <menuitem> + </menuitem> + <meta> + </meta> + <meter></meter> + <multicol></multicol> + <object></object> + <ol></ol> + <optgroup></optgroup> + <option></option> + <output></output> + <p></p> + <param> + </param> + <picture></picture> + <pre></pre> + <progress></progress> + <q></q> + <script></script> + <select></select> + <slot></slot> + <source> + </source> + <span></span> + <style></style> + <summary></summary> + <table></table> + <tbody></tbody> + <td></td> + <textarea></textarea> + <tfoot></tfoot> + <th></th> + <thead></thead> + <template></template> + <time></time> + <title></title> + <tr></tr> + <track> + </track> + <ul></ul> + <video></video> + <xmp></xmp> + </div> + <script type="application/javascript"> + SimpleTest.waitForExplicitFinish(); + info("running") + + + // Because private fields may not be enabled, we construct A via the below eval of an IFFE, + // and return early if it syntax errors. + var A = undefined; + try { + A = eval(`(function(){ + class Base { + constructor(o) { + return o; + } + } + + class A extends Base { + #x = 1; + static g(o) { + return o.#x; + } + static s(o, v) { + o.#x = v; + } + } + + return A; + })();`); + } catch (e) { + is(e instanceof SyntaxError, true, "Threw Syntax Error, Private Fields Not Enabled"); + is(/private fields are not currently supported/.test(e.message), true, "correct message"); + } + + if (A instanceof Function) { + function assertThrewInstance(f, error) { + var threw = true; + try { + f(); + threw = false; + } catch (e) { + // info("Caught " + e.name); + is(e instanceof error, true, "Correct Error thrown"); + } + is(threw, true, "Error was thrown"); + } + + function testNode(node) { + info("Testing node " + node.nodeName); + + assertThrewInstance(() => A.g(node), TypeError); + assertThrewInstance(() => A.s(node, 'node'), TypeError); + // info("Stamping Node"); + new A(node); + // info("Asserting read"); + is(A.g(node), 1, "correct value read"); + // info("Setting"); + A.s(node, 'node'); + // info("Verifing setter set the value"); + is(A.g(node), 'node', "updated value read"); + // info("Verifying we cannot double-init"); + assertThrewInstance(() => new A(node), TypeError); + } + + function testNodeRecursive(node) { + testNode(node); + for (c of node.children) { + testNodeRecursive(c) + } + } + + const test_contents = document.getElementById('test_contents'); + testNodeRecursive(test_contents); + + info("Checking Window"); + // Window itself isn't allowed to host private fields, because it's + // a cross-origin object + assertThrewInstance(() => A.g(window), TypeError) + + info("Checking Window Prototype Chain") + // However, it's prototype chain can. + w = Object.getPrototypeOf(window); + while (w) { + testNode(w); + w = Object.getPrototypeOf(w); + } + + info("Test Document") + testNode(document); + + + info("Test CSSRuleList") + testNode(document.styleSheets[0].cssRules) + + info("Test DOMTokenList") + const div = document.createElement('div'); + testNode(div.classList); + } + SimpleTest.finish(); + </script> +</body> + +</html>
\ No newline at end of file |