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