js/src/tests/ecma_5/extensions/watch-value-prop-becoming-setter.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 /* A stock watcher function. */
michael@0 7 var watcherCount;
michael@0 8 function watcher(id, old, newval) {
michael@0 9 watcherCount++;
michael@0 10 return newval;
michael@0 11 }
michael@0 12
michael@0 13 /* Create an object with a value property. */
michael@0 14 var o = { w:2, x:3 };
michael@0 15
michael@0 16 /*
michael@0 17 * Place a watchpoint on the value property. The watchpoint structure holds
michael@0 18 * the original JavaScript setter, and a pointer to the shape.
michael@0 19 */
michael@0 20 o.watch('x', watcher);
michael@0 21
michael@0 22 /*
michael@0 23 * Put the object in dictionary mode, so that JSObject::putProperty will
michael@0 24 * mutate its shapes instead of creating new ones.
michael@0 25 */
michael@0 26 delete o.w;
michael@0 27
michael@0 28 /*
michael@0 29 * Replace the value property with a setter.
michael@0 30 */
michael@0 31 var setterCount;
michael@0 32 o.__defineSetter__('x', function() { setterCount++; });
michael@0 33
michael@0 34 /*
michael@0 35 * Trigger the watchpoint. The watchpoint handler should run, and then the
michael@0 36 * setter should run.
michael@0 37 */
michael@0 38 watcherCount = setterCount = 0;
michael@0 39 o.x = 4;
michael@0 40 assertEq(watcherCount, 1);
michael@0 41 assertEq(setterCount, 1);
michael@0 42
michael@0 43 reportCompare(true, true);

mercurial