Bug 1942639 - Propagate --filter argument from desktop_unittest.py to runreftest...
[gecko.git] / dom / bindings / test / test_proxy_expandos.html
blobbfe6ab598ced40900d72200573f2c1386f293d6b
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=965992
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 965992</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=965992">Mozilla Bug 965992</a>
14 <p id="display"></p>
15 <form id="theform"></form>
16 <pre id="test">
17 <script type="application/javascript">
19 // Ensure we are in JIT code and attach IC stubs.
20 const iterations = 50;
22 function testFoo(obj, kind, expected) {
23 for (var i = 0; i < iterations; i++) {
24 obj.foo = i;
25 is(obj.foo, (expected === undefined) ? i : expected,
26 "Looking up an expando should work - " + kind);
30 function getPropTests(obj) {
31 // Start with a plain data property.
32 obj.foo = "bar";
33 testFoo(obj, "plain");
35 // Now change it to a scripted getter/setter.
36 var count = 0;
37 var getterSetterVal = 0;
38 Object.defineProperty(obj, "foo", {configurable: true, get() {
39 is(this, obj, "Getter should have the proxy as |this|");
40 is(arguments.length, 0, "Shouldn't pass arguments to getters");
41 count++;
42 return getterSetterVal;
43 }, set(v) {
44 is(this, obj, "Setter should have the proxy as |this|");
45 is(arguments.length, 1, "Should pass 1 argument to setters");
46 getterSetterVal = v;
47 count++;
48 }});
49 testFoo(obj, "scripted getter/setter");
50 is(count, iterations * 2, "Should have called the getter/setter enough times");
52 // Now try a native getter/setter.
53 Object.defineProperty(obj, "foo", {get: Math.abs, set: Math.abs, configurable: true});
54 testFoo(obj, "native getter/setter", NaN);
57 function getElemTests(obj) {
58 // Define two expando properties, then test inline caches for obj[prop]
59 // correctly guard on prop being the same.
60 var count = 0, getterSetterVal = 0;
61 obj.elem1 = 1;
62 Object.defineProperty(obj, "elem2", {
63 get() { count++; return getterSetterVal; },
64 set(v) { getterSetterVal = v; count++; },
65 });
66 for (var i = 0; i < iterations; i++) {
67 var prop = ((i & 1) == 0) ? "elem1" : "elem2";
68 obj[prop] = i;
69 is(obj[prop], i, "Should return correct property value");
71 is(count, iterations, "Should have called the getter/setter enough times");
74 var directExpando = document.getElementsByTagName("*");
75 var indirectExpando = document.getElementById("theform");
77 getPropTests(directExpando);
78 getPropTests(indirectExpando);
80 getElemTests(indirectExpando);
81 getElemTests(directExpando);
83 </script>
84 </pre>
85 </body>
86 </html>