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

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     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