proto-from-ctor-realm.js (2413B)
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.segmenter 6 description: Default [[Prototype]] value derived from realm of the NewTarget. 7 info: | 8 Intl.Segmenter ([ locales [ , options ]]) 9 1. If NewTarget is undefined, throw a TypeError exception. 10 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList). 11 ... 12 15. Return segmenter. 13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) 14 ... 15 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). 16 3. Return ObjectCreate(proto, internalSlotsList). 17 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) 18 ... 19 3. Let proto be ? Get(constructor, 'prototype'). 20 4. If Type(proto) is not Object, then 21 a. Let realm be ? GetFunctionRealm(constructor). 22 b. Set proto to realm's intrinsic object named intrinsicDefaultProto. 23 5. Return proto. 24 features: [cross-realm, Reflect, Symbol, Intl.Segmenter] 25 ---*/ 26 27 const other = $262.createRealm().global; 28 const newTarget = new other.Function(); 29 let sgm; 30 31 newTarget.prototype = undefined; 32 sgm = Reflect.construct(Intl.Segmenter, [], newTarget); 33 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is undefined'); 34 35 newTarget.prototype = null; 36 sgm = Reflect.construct(Intl.Segmenter, [], newTarget); 37 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is null'); 38 39 newTarget.prototype = false; 40 sgm = Reflect.construct(Intl.Segmenter, [], newTarget); 41 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Boolean'); 42 43 newTarget.prototype = 'str'; 44 sgm = Reflect.construct(Intl.Segmenter, [], newTarget); 45 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a String'); 46 47 newTarget.prototype = Symbol(); 48 sgm = Reflect.construct(Intl.Segmenter, [], newTarget); 49 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Symbol'); 50 51 newTarget.prototype = 1; 52 sgm = Reflect.construct(Intl.Segmenter, [], newTarget); 53 assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Number'); 54 55 reportCompare(0, 0);