Debian Codegraph @

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

raw
1 // |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally
2 // Copyright (C) 2019 Alexey Shvayka. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-intl.segmenter
7 description: Default [[Prototype]] value derived from realm of the NewTarget.
8 info: |
9 Intl.Segmenter ([ locales [ , options ]])
10 1. If NewTarget is undefined, throw a TypeError exception.
11 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
12 ...
13 15. Return segmenter.
14 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
15 ...
16 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
17 3. Return ObjectCreate(proto, internalSlotsList).
18 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, Intl.Segmenter]
26 ---*/
27
28 const other = $262.createRealm().global;
29 const newTarget = new other.Function();
30 let sgm;
31
32 newTarget.prototype = undefined;
33 sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
34 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is undefined');
35
36 newTarget.prototype = null;
37 sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
38 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is null');
39
40 newTarget.prototype = false;
41 sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
42 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Boolean');
43
44 newTarget.prototype = 'str';
45 sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
46 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a String');
47
48 newTarget.prototype = Symbol();
49 sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
50 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Symbol');
51
52 newTarget.prototype = 1;
53 sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
54 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Number');
55
56 reportCompare(0, 0);