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, oldval, newval) { watcherCount++; return newval; } michael@0: michael@0: /* Create an object with a JavaScript setter. */ michael@0: var setterCount; michael@0: var o = { w:2, set x(v) { setterCount++; } }; 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: * Place a watchpoint on the property. The watchpoint structure holds the michael@0: * original JavaScript setter, and a pointer to the shape. michael@0: */ michael@0: o.watch('x', watcher); michael@0: michael@0: /* michael@0: * Replace the accessor property with a value property. The shape's setter michael@0: * should become a non-JS setter, js_watch_set, and the watchpoint michael@0: * structure's saved setter should be updated (in this case, cleared). michael@0: */ michael@0: Object.defineProperty(o, 'x', { value:3, michael@0: writable:true, michael@0: enumerable:true, michael@0: configurable:true }); michael@0: michael@0: /* michael@0: * Assign to the property. This should trigger js_watch_set, which should michael@0: * call the handler, and then see that there is no JS-level setter to pass michael@0: * control on to, and return. michael@0: */ michael@0: watcherCount = setterCount = 0; michael@0: o.x = 3; michael@0: assertEq(watcherCount, 1); michael@0: assertEq(setterCount, 0); michael@0: michael@0: reportCompare(true, true);