blob: 7ebf328a8abf5dfb6126d5b79f63e94a750859cd [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
Ben Murdoch61f157c2016-09-16 13:49:30 +01005// Flags: --allow-natives-syntax
Ben Murdochda12d292016-06-02 14:46:10 +01006
7// Overwriting the constructor of an instance updates the protector
8
9let x = [];
10
11assertEquals(Array, x.map(()=>{}).constructor);
12assertEquals(Array, x.filter(()=>{}).constructor);
13assertEquals(Array, x.slice().constructor);
14assertEquals(Array, x.splice().constructor);
15assertEquals(Array, x.concat([1]).constructor);
16assertEquals(1, x.concat([1])[0]);
17
18class MyArray extends Array { }
19
20Object.defineProperty(x, 'constructor', {get() { return MyArray; }});
21assertFalse(%SpeciesProtector());
22
23assertEquals(MyArray, x.map(()=>{}).constructor);
24assertEquals(MyArray, x.filter(()=>{}).constructor);
25assertEquals(MyArray, x.slice().constructor);
26assertEquals(MyArray, x.splice().constructor);
27assertEquals(MyArray, x.concat([1]).constructor);
28assertEquals(1, x.concat([1])[0]);