summaryrefslogtreecommitdiffstats
path: root/dom/bindings/test/test_proxy_accessors.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/bindings/test/test_proxy_accessors.html
parentInitial commit. (diff)
downloadfirefox-upstream/124.0.1.tar.xz
firefox-upstream/124.0.1.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/bindings/test/test_proxy_accessors.html')
-rw-r--r--dom/bindings/test/test_proxy_accessors.html78
1 files changed, 78 insertions, 0 deletions
diff --git a/dom/bindings/test/test_proxy_accessors.html b/dom/bindings/test/test_proxy_accessors.html
new file mode 100644
index 0000000000..9474369688
--- /dev/null
+++ b/dom/bindings/test/test_proxy_accessors.html
@@ -0,0 +1,78 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1700052
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1700052</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1700052">Mozilla Bug 1700052</a>
+<p id="display"></p>
+<form id="theform"></form>
+<pre id="test">
+<script>
+function expandoTests() {
+ // Get a DOM proxy with an expando object. Define/redefine a "foo" getter/setter
+ // and ensure the right function is called.
+
+ var obj = document.getElementById("theform");
+ var count1 = 0, count2 = 0, count3 = 0;
+ var fun1 = function() { count1++; };
+ var fun2 = function() { count2++; };
+ var fun3 = function() { count3++; };
+
+ Object.defineProperty(obj, "foo", {configurable: true, get: fun1, set: fun1});
+
+ for (var i = 0; i < 100; i++) {
+ obj.foo;
+ obj.foo = i;
+ if (i === 50) {
+ Object.defineProperty(obj, "foo", {configurable: true, get: fun2, set: fun2});
+ } else if (i === 80) {
+ Object.defineProperty(obj, "foo", {configurable: true, get: fun3, set: fun3});
+ }
+ }
+
+ is(count1, 102, "call count for fun1 must match");
+ is(count2, 60, "call count for fun2 must match");
+ is(count3, 38, "call count for fun3 must match");
+}
+expandoTests();
+
+function unshadowedTests() {
+ // Same as above, but for non-shadowing properties on the prototype.
+
+ var obj = document.getElementById("theform");
+ var proto = Object.getPrototypeOf(obj);
+
+ var count1 = 0, count2 = 0;
+ var fun1 = function() { count1++; };
+ var fun2 = function() { count2++; };
+
+ for (var i = 0; i < 100; i++) {
+ obj.name;
+ obj.name = "test";
+ if (i === 50) {
+ let desc = Object.getOwnPropertyDescriptor(proto, "name");
+ desc.get = desc.set = fun1;
+ Object.defineProperty(proto, "name", desc);
+ }
+ if (i === 90) {
+ let desc = Object.getOwnPropertyDescriptor(proto, "name");
+ desc.get = desc.set = fun2;
+ Object.defineProperty(proto, "name", desc);
+ }
+ }
+
+ is(count1, 80, "call count for fun1 must match");
+ is(count2, 18, "call count for fun2 must match");
+}
+unshadowedTests();
+</script>
+</pre>
+</body>
+</html>