js/src/jit-test/tests/collections/Array-of-length-setter.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // Array.of calls a "length" setter if one is present.
     3 var hits = 0;
     4 var lastObj = null, lastVal = undefined;
     5 function setter(v) {
     6     hits++;
     7     lastObj = this;
     8     lastVal = v;
     9 }
    11 // when the setter is on the new object
    12 function Pack() {
    13     Object.defineProperty(this, "length", {set: setter});
    14 }
    15 Pack.of = Array.of;
    16 var pack = Pack.of("wolves", "cards", "cigarettes", "lies");
    17 assertEq(lastObj, pack);
    18 assertEq(lastVal, 4);
    20 // when the setter is on the new object's prototype
    21 function Bevy() {}
    22 Object.defineProperty(Bevy.prototype, "length", {set: setter});
    23 Bevy.of = Array.of;
    24 var bevy = Bevy.of("quail");
    25 assertEq(lastObj, bevy);
    26 assertEq(lastVal, 1);

mercurial