1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/extensions/watch-replaced-setter.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 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, oldval, newval) { watcherCount++; return newval; } 1.12 + 1.13 +/* Create an object with a JavaScript setter. */ 1.14 +var setterCount; 1.15 +var o = { w:2, set x(v) { setterCount++; } }; 1.16 + 1.17 +/* 1.18 + * Put the object in dictionary mode, so that JSObject::putProperty will 1.19 + * mutate its shapes instead of creating new ones. 1.20 + */ 1.21 +delete o.w; 1.22 + 1.23 +/* 1.24 + * Place a watchpoint on the property. The watchpoint structure holds the 1.25 + * original JavaScript setter, and a pointer to the shape. 1.26 + */ 1.27 +o.watch('x', watcher); 1.28 + 1.29 +/* 1.30 + * Replace the accessor property with a value property. The shape's setter 1.31 + * should become a non-JS setter, js_watch_set, and the watchpoint 1.32 + * structure's saved setter should be updated (in this case, cleared). 1.33 + */ 1.34 +Object.defineProperty(o, 'x', { value:3, 1.35 + writable:true, 1.36 + enumerable:true, 1.37 + configurable:true }); 1.38 + 1.39 +/* 1.40 + * Assign to the property. This should trigger js_watch_set, which should 1.41 + * call the handler, and then see that there is no JS-level setter to pass 1.42 + * control on to, and return. 1.43 + */ 1.44 +watcherCount = setterCount = 0; 1.45 +o.x = 3; 1.46 +assertEq(watcherCount, 1); 1.47 +assertEq(setterCount, 0); 1.48 + 1.49 +reportCompare(true, true);