Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_5 / extensions / watch-replaced-setter.js
1 /*
2  * Any copyright is dedicated to the Public Domain.
3  * http://creativecommons.org/licenses/publicdomain/
4  */
5
6 /* A stock watcher function. */
7 var watcherCount;
8 function watcher(id, oldval, newval) { watcherCount++; return newval; }
9
10 /* Create an object with a JavaScript setter. */
11 var setterCount;
12 var o = { w:2, set x(v) { setterCount++; } };
13
14 /*
15  * Put the object in dictionary mode, so that JSObject::putProperty will 
16  * mutate its shapes instead of creating new ones.
17  */
18 delete o.w;
19
20 /*
21  * Place a watchpoint on the property. The watchpoint structure holds the
22  * original JavaScript setter, and a pointer to the shape.
23  */
24 o.watch('x', watcher);
25
26 /*
27  * Replace the accessor property with a value property. The shape's setter
28  * should become a non-JS setter, js_watch_set, and the watchpoint
29  * structure's saved setter should be updated (in this case, cleared).
30  */
31 Object.defineProperty(o, 'x', { value:3,
32                                 writable:true,
33                                 enumerable:true,
34                                 configurable:true });
35
36 /*
37  * Assign to the property. This should trigger js_watch_set, which should
38  * call the handler, and then see that there is no JS-level setter to pass
39  * control on to, and return.
40  */
41 watcherCount = setterCount = 0;
42 o.x = 3;
43 assertEq(watcherCount, 1);
44 assertEq(setterCount, 0);
45
46 reportCompare(true, true);