Thu, 22 Jan 2015 13:21:57 +0100
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);