Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Array / proto-from-ctor-realm-one.js
blob4ebc31467ca0f5f5ed64e9602200a0d663c16032
1 // Copyright (C) 2019 Alexey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-array-len
6 description: Default [[Prototype]] value derived from realm of the NewTarget.
7 info: |
8   Array ( len )
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. Let array be ! ArrayCreate(0, proto).
14   ...
15   9. Return array.
17   GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
19   ...
20   3. Let proto be ? Get(constructor, "prototype").
21   4. If Type(proto) is not Object, then
22     a. Let realm be ? GetFunctionRealm(constructor).
23     b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
24   5. Return proto.
25 features: [cross-realm, Reflect, Symbol]
26 ---*/
28 var other = $262.createRealm().global;
29 var newTarget = new other.Function();
30 var arr;
32 newTarget.prototype = undefined;
33 arr = Reflect.construct(Array, [1], newTarget);
34 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
36 newTarget.prototype = null;
37 arr = Reflect.construct(Array, [1], newTarget);
38 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
40 newTarget.prototype = true;
41 arr = Reflect.construct(Array, [1], newTarget);
42 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
44 newTarget.prototype = '';
45 arr = Reflect.construct(Array, [1], newTarget);
46 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
48 newTarget.prototype = Symbol();
49 arr = Reflect.construct(Array, [1], newTarget);
50 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
52 newTarget.prototype = 0;
53 arr = Reflect.construct(Array, [1], newTarget);
54 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
56 reportCompare(0, 0);