OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 // https://bugs.chromium.org/p/chromium/issues/detail?id=595319 |
| 6 // Ensure exceptions are checked for by Array.prototype.concat from adding |
| 7 // an element, and that elements are added to array subclasses appropriately |
| 8 |
| 9 // If adding a property does throw, the exception is propagated |
| 10 class MyException extends Error { } |
| 11 class NoDefinePropertyArray extends Array { |
| 12 constructor(...args) { |
| 13 super(...args); |
| 14 return new Proxy(this, { |
| 15 defineProperty() { throw new MyException(); } |
| 16 }); |
| 17 } |
| 18 } |
| 19 assertThrows(() => new NoDefinePropertyArray().concat([1]), MyException); |
| 20 |
| 21 // Ensure elements are added to the instance, rather than calling [[Set]]. |
| 22 class ZeroGetterArray extends Array { get 0() {} }; |
| 23 assertArrayEquals([1], new ZeroGetterArray().concat(1)); |
| 24 |
| 25 // Frozen arrays lead to throwing |
| 26 |
| 27 class FrozenArray extends Array { |
| 28 constructor(...args) { super(...args); Object.freeze(this); } |
| 29 } |
| 30 assertThrows(() => new FrozenArray().concat([1]), TypeError); |
| 31 |
| 32 // Non-configurable non-writable zero leads to throwing |
| 33 class ZeroFrozenArray extends Array { |
| 34 constructor(...args) { |
| 35 super(...args); |
| 36 Object.defineProperty(this, 0, {value: 1}); |
| 37 } |
| 38 } |
| 39 assertThrows(() => new ZeroFrozenArray().concat([1]), TypeError); |
OLD | NEW |