OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Based on: https://hg.mozilla.org/mozilla-central/file/d0c3168c3c47/js/src/jit
-test/tests/collections/Array-of-length-setter.js |
| 6 |
| 7 // Flags: --harmony-arrays |
| 8 |
| 9 |
| 10 // Array.of calls a "length" setter if one is present. |
| 11 |
| 12 var hits = 0; |
| 13 var lastObj = null, lastVal = undefined; |
| 14 function setter(v) { |
| 15 hits++; |
| 16 lastObj = this; |
| 17 lastVal = v; |
| 18 } |
| 19 |
| 20 // when the setter is on the new object |
| 21 function Pack() { |
| 22 Object.defineProperty(this, "length", {set: setter}); |
| 23 } |
| 24 Pack.of = Array.of; |
| 25 var pack = Pack.of("wolves", "cards", "cigarettes", "lies"); |
| 26 assertEquals(lastObj, pack); |
| 27 assertEquals(lastVal, 4); |
| 28 |
| 29 // when the setter is on the new object's prototype |
| 30 function Bevy() {} |
| 31 Object.defineProperty(Bevy.prototype, "length", {set: setter}); |
| 32 Bevy.of = Array.of; |
| 33 var bevy = Bevy.of("quail"); |
| 34 assertEquals(lastObj, bevy); |
| 35 assertEquals(lastVal, 1); |
OLD | NEW |