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: /* Create an object with a JavaScript setter. */ michael@0: var firstSetterCount; michael@0: var o = { w:2, set x(v) { firstSetterCount++; } }; 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: /* A stock watcher function. */ michael@0: var watcherCount; michael@0: function watcher(id, oldval, newval) { watcherCount++; return newval; } michael@0: michael@0: /* michael@0: * Place a watchpoint on the property. The property's shape now has the michael@0: * watchpoint setter, with the original setter saved in the watchpoint michael@0: * structure. michael@0: */ michael@0: o.watch('x', watcher); michael@0: michael@0: /* michael@0: * Replace the setter with a new setter. The shape should get updated to michael@0: * refer to the new setter, and then the watchpoint setter should be michael@0: * re-established. michael@0: */ michael@0: var secondSetterCount; michael@0: Object.defineProperty(o, 'x', { set: function () { secondSetterCount++ } }); michael@0: michael@0: /* michael@0: * Assign to the property. This should trigger the watchpoint and the new setter. michael@0: */ michael@0: watcherCount = firstSetterCount = secondSetterCount = 0; michael@0: o.x = 3; michael@0: assertEq(watcherCount, 1); michael@0: assertEq(firstSetterCount, 0); michael@0: assertEq(secondSetterCount, 1); michael@0: michael@0: reportCompare(true, true);