js/src/tests/ecma_5/extensions/watch-value-prop-becoming-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 /* A stock watcher function. */
     7 var watcherCount;
     8 function watcher(id, old, newval) {
     9     watcherCount++;
    10     return newval; 
    11 }
    13 /* Create an object with a value property. */
    14 var o = { w:2, x:3 };
    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);
    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;
    28 /*
    29  * Replace the value property with a setter.
    30  */
    31 var setterCount;
    32 o.__defineSetter__('x', function() { setterCount++; });
    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);
    43 reportCompare(true, true);

mercurial