get-fn-realm.js (1732B)
1 // Copyright (C) 2016 the V8 project authors. 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 info: | 8 Array ( ) 9 10 [...] 11 4. Let proto be ? GetPrototypeFromConstructor(newTarget, "%Array.prototype%"). 12 5. Return ! ArrayCreate(0, proto). 13 14 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) 15 16 [...] 17 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). 18 3. Return OrdinaryObjectCreate(proto, internalSlotsList). 19 20 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) 21 22 [...] 23 3. Let proto be ? Get(constructor, "prototype"). 24 4. If Type(proto) is not Object, then 25 a. Let realm be ? GetFunctionRealm(constructor). 26 b. Set proto to realm's intrinsic object named intrinsicDefaultProto. 27 5. Return proto. 28 29 GetFunctionRealm ( obj ) 30 31 [...] 32 2. If obj has a [[Realm]] internal slot, then 33 a. Return obj.[[Realm]]. 34 [...] 35 4. If obj is a Proxy exotic object, then 36 [...] 37 b. Let proxyTarget be obj.[[ProxyTarget]]. 38 c. Return ? GetFunctionRealm(proxyTarget). 39 features: [cross-realm, Reflect, Proxy] 40 ---*/ 41 42 var realm1 = $262.createRealm().global; 43 var realm2 = $262.createRealm().global; 44 var realm3 = $262.createRealm().global; 45 46 var newTarget = new realm1.Function(); 47 newTarget.prototype = false; 48 49 var newTargetProxy = new realm2.Proxy(newTarget, {}); 50 var array = Reflect.construct(realm3.Array, [], newTargetProxy); 51 52 assert(array instanceof realm1.Array); 53 assert.sameValue(Object.getPrototypeOf(array), realm1.Array.prototype); 54 55 reportCompare(0, 0);