Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / NativeErrors / EvalError / proto-from-ctor-realm.js
blob32c2e076624278eabae78caaf6bc9695ff92f0c3
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-nativeerror
6 description: Default [[Prototype]] value derived from realm of the NewTarget.
7 info: |
8   NativeError ( message )
10   1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
11   2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeErrorPrototype%", « [[ErrorData]] »).
12   ...
13   4. Return O.
15   OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
17   ...
18   2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
19   3. Return ObjectCreate(proto, internalSlotsList).
21   GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
23   ...
24   3. Let proto be ? Get(constructor, 'prototype').
25   4. If Type(proto) is not Object, then
26     a. Let realm be ? GetFunctionRealm(constructor).
27     b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
28   5. Return proto.
29 features: [cross-realm, Reflect, Symbol]
30 ---*/
32 var other = $262.createRealm().global;
33 var newTarget = new other.Function();
34 var err;
36 newTarget.prototype = undefined;
37 err = Reflect.construct(EvalError, [], newTarget);
38 assert.sameValue(Object.getPrototypeOf(err), other.EvalError.prototype, 'newTarget.prototype is undefined');
40 newTarget.prototype = null;
41 err = Reflect.construct(EvalError, [], newTarget);
42 assert.sameValue(Object.getPrototypeOf(err), other.EvalError.prototype, 'newTarget.prototype is null');
44 newTarget.prototype = false;
45 err = Reflect.construct(EvalError, [], newTarget);
46 assert.sameValue(Object.getPrototypeOf(err), other.EvalError.prototype, 'newTarget.prototype is a Boolean');
48 newTarget.prototype = 'str';
49 err = Reflect.construct(EvalError, [], newTarget);
50 assert.sameValue(Object.getPrototypeOf(err), other.EvalError.prototype, 'newTarget.prototype is a String');
52 newTarget.prototype = Symbol();
53 err = Reflect.construct(EvalError, [], newTarget);
54 assert.sameValue(Object.getPrototypeOf(err), other.EvalError.prototype, 'newTarget.prototype is a Symbol');
56 newTarget.prototype = 0;
57 err = Reflect.construct(EvalError, [], newTarget);
58 assert.sameValue(Object.getPrototypeOf(err), other.EvalError.prototype, 'newTarget.prototype is a Number');
60 reportCompare(0, 0);