Debian Codegraph @

js/src/tests/test262/intl402/Locale/proto-from-ctor-realm.js

raw
1 // Copyright (C) 2019 Alexey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-Intl.Locale
6 description: Default [[Prototype]] value derived from realm of the NewTarget.
7 info: |
8 Intl.Locale ( tag [ , options] )
9
10 ...
11 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, %LocalePrototype%, internalSlotsList).
12 ...
13 38. Return locale.
14
15 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
16
17 ...
18 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
19 3. Return ObjectCreate(proto, internalSlotsList).
20
21 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
22
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: [Intl.Locale, cross-realm, Reflect, Symbol]
30 ---*/
31
32 var other = $262.createRealm().global;
33 var newTarget = new other.Function();
34 var locale;
35
36 newTarget.prototype = undefined;
37 locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
38 assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is undefined');
39
40 newTarget.prototype = null;
41 locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
42 assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is null');
43
44 newTarget.prototype = true;
45 locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
46 assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is a Boolean');
47
48 newTarget.prototype = 'str';
49 locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
50 assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is a String');
51
52 newTarget.prototype = Symbol();
53 locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
54 assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is a Symbol');
55
56 newTarget.prototype = 0;
57 locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
58 assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is a Number');
59
60 reportCompare(0, 0);