|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/licenses/publicdomain/ |
|
4 */ |
|
5 |
|
6 /* Create an object with a JavaScript setter. */ |
|
7 var firstSetterCount; |
|
8 var o = { w:2, set x(v) { firstSetterCount++; } }; |
|
9 |
|
10 /* |
|
11 * Put the object in dictionary mode, so that JSObject::putProperty will |
|
12 * mutate its shapes instead of creating new ones. |
|
13 */ |
|
14 delete o.w; |
|
15 |
|
16 /* A stock watcher function. */ |
|
17 var watcherCount; |
|
18 function watcher(id, oldval, newval) { watcherCount++; return newval; } |
|
19 |
|
20 /* |
|
21 * Place a watchpoint on the property. The property's shape now has the |
|
22 * watchpoint setter, with the original setter saved in the watchpoint |
|
23 * structure. |
|
24 */ |
|
25 o.watch('x', watcher); |
|
26 |
|
27 /* |
|
28 * Replace the setter with a new setter. The shape should get updated to |
|
29 * refer to the new setter, and then the watchpoint setter should be |
|
30 * re-established. |
|
31 */ |
|
32 var secondSetterCount; |
|
33 Object.defineProperty(o, 'x', { set: function () { secondSetterCount++ } }); |
|
34 |
|
35 /* |
|
36 * Assign to the property. This should trigger the watchpoint and the new setter. |
|
37 */ |
|
38 watcherCount = firstSetterCount = secondSetterCount = 0; |
|
39 o.x = 3; |
|
40 assertEq(watcherCount, 1); |
|
41 assertEq(firstSetterCount, 0); |
|
42 assertEq(secondSetterCount, 1); |
|
43 |
|
44 reportCompare(true, true); |