diff --git a/test/built-ins/Function/prototype/bind/get-fn-realm-recursive.js b/test/built-ins/Function/prototype/bind/get-fn-realm-recursive.js index 7e91dbdf49..b6a4feaf3c 100644 --- a/test/built-ins/Function/prototype/bind/get-fn-realm-recursive.js +++ b/test/built-ins/Function/prototype/bind/get-fn-realm-recursive.js @@ -3,23 +3,51 @@ /*--- esid: sec-getfunctionrealm description: > - The realm of a bound function exotic object is the realm of its target - function. GetFunctionRealm is called recursively. + The realm of a bound function exotic object is the realm of its target function. + GetFunctionRealm is called recursively. info: | - 7.3.22 GetFunctionRealm ( obj ) + Object ( [ value ] ) - [...] - 2. If obj has a [[Realm]] internal slot, then - a. Return obj.[[Realm]]. - 3. If obj is a Bound Function exotic object, then - a. Let target be obj.[[BoundTargetFunction]]. - b. Return ? GetFunctionRealm(target). -features: [cross-realm] + 1. If NewTarget is neither undefined nor the active function, then + a. Return ? OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%"). + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return OrdinaryObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + + GetFunctionRealm ( obj ) + + [...] + 2. If obj has a [[Realm]] internal slot, then + a. Return obj.[[Realm]]. + 3. If obj is a bound function exotic object, then + a. Let target be obj.[[BoundTargetFunction]]. + b. Return ? GetFunctionRealm(target). +features: [cross-realm, Reflect] ---*/ -var other = $262.createRealm().global; -var C = new other.Function(); -C.prototype = null; -var B = C.bind().bind(); +var realm1 = $262.createRealm().global; +var realm2 = $262.createRealm().global; +var realm3 = $262.createRealm().global; +var realm4 = $262.createRealm().global; -assert.sameValue(Object.getPrototypeOf(new B()), other.Object.prototype); +var newTarget = new realm1.Function(); +newTarget.prototype = 1; + +var boundNewTarget = realm2.Function.prototype.bind.call(newTarget); +var boundBoundNewTarget = realm3.Function.prototype.bind.call(boundNewTarget); +var object = Reflect.construct(realm4.Object, [], boundBoundNewTarget); + +assert(object instanceof realm1.Object); +assert.sameValue(Object.getPrototypeOf(object), realm1.Object.prototype); diff --git a/test/built-ins/Function/prototype/bind/get-fn-realm.js b/test/built-ins/Function/prototype/bind/get-fn-realm.js index f21b9dd3d0..47c9933597 100644 --- a/test/built-ins/Function/prototype/bind/get-fn-realm.js +++ b/test/built-ins/Function/prototype/bind/get-fn-realm.js @@ -3,23 +3,53 @@ /*--- esid: sec-getfunctionrealm description: > - The realm of a bound function exotic object is the realm of its target - function + The realm of a bound function exotic object is the realm of its target function. info: | - 7.3.22 GetFunctionRealm ( obj ) + Date ( ) + [...] + 3. If NewTarget is undefined, then [...] - 2. If obj has a [[Realm]] internal slot, then - a. Return obj.[[Realm]]. - 3. If obj is a Bound Function exotic object, then - a. Let target be obj.[[BoundTargetFunction]]. - b. Return ? GetFunctionRealm(target). -features: [cross-realm] + 4. Else, + a. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", « [[DateValue]] »). + [...] + c. Return O. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return OrdinaryObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + + GetFunctionRealm ( obj ) + + [...] + 2. If obj has a [[Realm]] internal slot, then + a. Return obj.[[Realm]]. + 3. If obj is a bound function exotic object, then + a. Let target be obj.[[BoundTargetFunction]]. + b. Return ? GetFunctionRealm(target). +features: [cross-realm, Reflect] ---*/ -var other = $262.createRealm().global; -var C = new other.Function(); -C.prototype = null; -var B = C.bind(); +var realm1 = $262.createRealm().global; +var realm2 = $262.createRealm().global; +var realm3 = $262.createRealm().global; -assert.sameValue(Object.getPrototypeOf(new B()), other.Object.prototype); +var newTarget = new realm1.Function(); +newTarget.prototype = "str"; + +var boundNewTarget = realm2.Function.prototype.bind.call(newTarget); +var date = Reflect.construct(realm3.Date, [], boundNewTarget); + +assert(date instanceof realm1.Date); +assert.sameValue(Object.getPrototypeOf(date), realm1.Date.prototype);