Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Array / proto-from-ctor-realm-zero.js
blob09c458336c47e8faaab5efb666e8fc4455d292dd
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-array-constructor-array
6 description: Default [[Prototype]] value derived from realm of the NewTarget.
7 info: |
8   Array ( )
10   ...
11   3. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
12   4. Let proto be ? GetPrototypeFromConstructor(newTarget, "%Array.prototype%").
13   5. Return ! ArrayCreate(0, proto).
15   GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
17   ...
18   3. Let proto be ? Get(constructor, "prototype").
19   4. If Type(proto) is not Object, then
20     a. Let realm be ? GetFunctionRealm(constructor).
21     b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
22   5. Return proto.
23 features: [cross-realm, Reflect, Symbol]
24 ---*/
26 var other = $262.createRealm().global;
27 var newTarget = new other.Function();
28 var arr;
30 newTarget.prototype = undefined;
31 arr = Reflect.construct(Array, [], newTarget);
32 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
34 newTarget.prototype = null;
35 arr = Reflect.construct(Array, [], newTarget);
36 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
38 newTarget.prototype = true;
39 arr = Reflect.construct(Array, [], newTarget);
40 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
42 newTarget.prototype = 'str';
43 arr = Reflect.construct(Array, [], newTarget);
44 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
46 newTarget.prototype = Symbol();
47 arr = Reflect.construct(Array, [], newTarget);
48 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
50 newTarget.prototype = 1;
51 arr = Reflect.construct(Array, [], newTarget);
52 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
54 reportCompare(0, 0);