get-fn-realm-recursive.js (1904B)
1 // Copyright (C) 2019 Aleksey Shvayka. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-getfunctionrealm 5 description: > 6 The realm of a Proxy exotic object is the realm of its target function. 7 GetFunctionRealm is called recursively. 8 info: | 9 Boolean ( value ) 10 11 [...] 12 3. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Boolean.prototype%", « [[BooleanData]] »). 13 [...] 14 5. Return O. 15 16 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) 17 18 [...] 19 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). 20 3. Return OrdinaryObjectCreate(proto, internalSlotsList). 21 22 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) 23 24 [...] 25 3. Let proto be ? Get(constructor, "prototype"). 26 4. If Type(proto) is not Object, then 27 a. Let realm be ? GetFunctionRealm(constructor). 28 b. Set proto to realm's intrinsic object named intrinsicDefaultProto. 29 5. Return proto. 30 31 GetFunctionRealm ( obj ) 32 33 [...] 34 2. If obj has a [[Realm]] internal slot, then 35 a. Return obj.[[Realm]]. 36 [...] 37 4. If obj is a Proxy exotic object, then 38 [...] 39 b. Let proxyTarget be obj.[[ProxyTarget]]. 40 c. Return ? GetFunctionRealm(proxyTarget). 41 features: [cross-realm, Reflect, Proxy] 42 ---*/ 43 44 var realm1 = $262.createRealm().global; 45 var realm2 = $262.createRealm().global; 46 var realm3 = $262.createRealm().global; 47 var realm4 = $262.createRealm().global; 48 49 var newTarget = new realm1.Function(); 50 newTarget.prototype = null; 51 52 var newTargetProxy = new realm2.Proxy(newTarget, {}); 53 var newTargetProxyProxy = new realm3.Proxy(newTargetProxy, {}); 54 var boolean = Reflect.construct(realm4.Boolean, [], newTargetProxyProxy); 55 56 assert(boolean instanceof realm1.Boolean); 57 assert.sameValue(Object.getPrototypeOf(boolean), realm1.Boolean.prototype); 58 59 reportCompare(0, 0);