1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/extensions/watch-value-prop-becoming-setter.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,43 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/licenses/publicdomain/ 1.7 + */ 1.8 + 1.9 +/* A stock watcher function. */ 1.10 +var watcherCount; 1.11 +function watcher(id, old, newval) { 1.12 + watcherCount++; 1.13 + return newval; 1.14 +} 1.15 + 1.16 +/* Create an object with a value property. */ 1.17 +var o = { w:2, x:3 }; 1.18 + 1.19 +/* 1.20 + * Place a watchpoint on the value property. The watchpoint structure holds 1.21 + * the original JavaScript setter, and a pointer to the shape. 1.22 + */ 1.23 +o.watch('x', watcher); 1.24 + 1.25 +/* 1.26 + * Put the object in dictionary mode, so that JSObject::putProperty will 1.27 + * mutate its shapes instead of creating new ones. 1.28 + */ 1.29 +delete o.w; 1.30 + 1.31 +/* 1.32 + * Replace the value property with a setter. 1.33 + */ 1.34 +var setterCount; 1.35 +o.__defineSetter__('x', function() { setterCount++; }); 1.36 + 1.37 +/* 1.38 + * Trigger the watchpoint. The watchpoint handler should run, and then the 1.39 + * setter should run. 1.40 + */ 1.41 +watcherCount = setterCount = 0; 1.42 +o.x = 4; 1.43 +assertEq(watcherCount, 1); 1.44 +assertEq(setterCount, 1); 1.45 + 1.46 +reportCompare(true, true);