4 https://bugzilla.mozilla.org/show_bug.cgi?id=965992
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"/>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=965992">Mozilla Bug
965992</a>
15 <form id=
"theform"></form>
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++) {
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.
33 testFoo(obj,
"plain");
35 // Now change it to a scripted getter/setter.
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");
42 return getterSetterVal;
44 is(this, obj,
"Setter should have the proxy as |this|");
45 is(arguments.length,
1,
"Should pass 1 argument to setters");
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;
62 Object.defineProperty(obj,
"elem2", {
63 get() { count++; return getterSetterVal; },
64 set(v) { getterSetterVal = v; count++; },
66 for (var i =
0; i < iterations; i++) {
67 var prop = ((i &
1) ==
0) ?
"elem1" :
"elem2";
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);