Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_5 / extensions / watch-value-prop-becoming-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, old, newval) {
9     watcherCount++;
10     return newval; 
11 }
12
13 /* Create an object with a value property. */
14 var o = { w:2, x:3 };
15
16 /*
17  * Place a watchpoint on the value property. The watchpoint structure holds
18  * the original JavaScript setter, and a pointer to the shape.
19  */
20 o.watch('x', watcher);
21
22 /*
23  * Put the object in dictionary mode, so that JSObject::putProperty will 
24  * mutate its shapes instead of creating new ones.
25  */
26 delete o.w;
27
28 /*
29  * Replace the value property with a setter.
30  */
31 var setterCount;
32 o.__defineSetter__('x', function() { setterCount++; });
33
34 /*
35  * Trigger the watchpoint. The watchpoint handler should run, and then the
36  * setter should run.
37  */
38 watcherCount = setterCount = 0;
39 o.x = 4;
40 assertEq(watcherCount, 1);
41 assertEq(setterCount, 1);
42
43 reportCompare(true, true);