1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/collections/Array-of-length-setter.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,26 @@ 1.4 +// Array.of calls a "length" setter if one is present. 1.5 + 1.6 +var hits = 0; 1.7 +var lastObj = null, lastVal = undefined; 1.8 +function setter(v) { 1.9 + hits++; 1.10 + lastObj = this; 1.11 + lastVal = v; 1.12 +} 1.13 + 1.14 +// when the setter is on the new object 1.15 +function Pack() { 1.16 + Object.defineProperty(this, "length", {set: setter}); 1.17 +} 1.18 +Pack.of = Array.of; 1.19 +var pack = Pack.of("wolves", "cards", "cigarettes", "lies"); 1.20 +assertEq(lastObj, pack); 1.21 +assertEq(lastVal, 4); 1.22 + 1.23 +// when the setter is on the new object's prototype 1.24 +function Bevy() {} 1.25 +Object.defineProperty(Bevy.prototype, "length", {set: setter}); 1.26 +Bevy.of = Array.of; 1.27 +var bevy = Bevy.of("quail"); 1.28 +assertEq(lastObj, bevy); 1.29 +assertEq(lastVal, 1);