js/src/tests/ecma_5/extensions/watch-setter-become-setter.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/licenses/publicdomain/
     4  */
     6 /* Create an object with a JavaScript setter. */
     7 var firstSetterCount;
     8 var o = { w:2, set x(v) { firstSetterCount++; } };
    10 /*
    11  * Put the object in dictionary mode, so that JSObject::putProperty will 
    12  * mutate its shapes instead of creating new ones.
    13  */
    14 delete o.w;
    16 /* A stock watcher function. */
    17 var watcherCount;
    18 function watcher(id, oldval, newval) { watcherCount++; return newval; }
    20 /*
    21  * Place a watchpoint on the property. The property's shape now has the
    22  * watchpoint setter, with the original setter saved in the watchpoint
    23  * structure.
    24  */
    25 o.watch('x', watcher);
    27 /*
    28  * Replace the setter with a new setter. The shape should get updated to
    29  * refer to the new setter, and then the watchpoint setter should be
    30  * re-established.
    31  */
    32 var secondSetterCount;
    33 Object.defineProperty(o, 'x', { set: function () { secondSetterCount++ } });
    35 /*
    36  * Assign to the property. This should trigger the watchpoint and the new setter.
    37  */
    38 watcherCount = firstSetterCount = secondSetterCount = 0;
    39 o.x = 3;
    40 assertEq(watcherCount, 1);
    41 assertEq(firstSetterCount, 0);
    42 assertEq(secondSetterCount, 1);
    44 reportCompare(true, true);

mercurial