js/src/tests/ecma_5/extensions/watch-inherited-property.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 a prototype object with a setter property. */
     7 var protoSetterCount;
     8 var proto = ({ set x(v) { protoSetterCount++; } });
    10 /* Put a watchpoint on that setter. */
    11 var protoWatchCount;
    12 proto.watch('x', function() { protoWatchCount++; });
    14 /* Make an object with the above as its prototype. */
    15 function C() { }
    16 C.prototype = proto;
    17 var o = new C();
    19 /*
    20  * Set a watchpoint on the property in the inheriting object. We have
    21  * defined this to mean "duplicate the property, setter and all, in the
    22  * inheriting object." I don't think debugging observation mechanisms
    23  * should mutate the program being run, but that's what we've got.
    24  */
    25 var oWatchCount;
    26 o.watch('x', function() { oWatchCount++; });
    28 /*
    29  * Assign to the property. This should trip the watchpoint on the inheriting object and
    30  * the setter.
    31  */
    32 protoSetterCount = protoWatchCount = oWatchCount = 0;
    33 o.x = 1;
    34 assertEq(protoWatchCount, 0);
    35 assertEq(oWatchCount, 1);
    36 assertEq(protoSetterCount, 1);
    38 reportCompare(true, true);

mercurial