michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: /* A stock watcher function. */ michael@0: var watcherCount; michael@0: function watcher(id, old, newval) { michael@0: watcherCount++; michael@0: return newval; michael@0: } michael@0: michael@0: /* Create an object with a value property. */ michael@0: var o = { w:2, x:3 }; michael@0: michael@0: /* michael@0: * Place a watchpoint on the value property. The watchpoint structure holds michael@0: * the original JavaScript setter, and a pointer to the shape. michael@0: */ michael@0: o.watch('x', watcher); michael@0: michael@0: /* michael@0: * Put the object in dictionary mode, so that JSObject::putProperty will michael@0: * mutate its shapes instead of creating new ones. michael@0: */ michael@0: delete o.w; michael@0: michael@0: /* michael@0: * Replace the value property with a setter. michael@0: */ michael@0: var setterCount; michael@0: o.__defineSetter__('x', function() { setterCount++; }); michael@0: michael@0: /* michael@0: * Trigger the watchpoint. The watchpoint handler should run, and then the michael@0: * setter should run. michael@0: */ michael@0: watcherCount = setterCount = 0; michael@0: o.x = 4; michael@0: assertEq(watcherCount, 1); michael@0: assertEq(setterCount, 1); michael@0: michael@0: reportCompare(true, true);