blob: 46ca27444f4f8902a9d53864c794c9cc987057c5 [file] [log] [blame]
Ben Murdochda12d292016-06-02 14:46:10 +01001// 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
10class MyException extends Error { }
11class NoDefinePropertyArray extends Array {
12 constructor(...args) {
13 super(...args);
14 return new Proxy(this, {
15 defineProperty() { throw new MyException(); }
16 });
17 }
18}
19assertThrows(() => new NoDefinePropertyArray().concat([1]), MyException);
20
21// Ensure elements are added to the instance, rather than calling [[Set]].
22class ZeroGetterArray extends Array { get 0() {} };
23assertArrayEquals([1], new ZeroGetterArray().concat(1));
24
25// Frozen arrays lead to throwing
26
27class FrozenArray extends Array {
28 constructor(...args) { super(...args); Object.freeze(this); }
29}
30assertThrows(() => new FrozenArray().concat([1]), TypeError);
31
32// Non-configurable non-writable zero leads to throwing
33class ZeroFrozenArray extends Array {
34 constructor(...args) {
35 super(...args);
36 Object.defineProperty(this, 0, {value: 1});
37 }
38}
39assertThrows(() => new ZeroFrozenArray().concat([1]), TypeError);