Fix bound function tests

This commit is contained in:
Alexey Shvayka 2020-04-18 23:40:33 +03:00 committed by Rick Waldron
parent 57fa74b170
commit fe0d4dc781
2 changed files with 87 additions and 29 deletions

View File

@ -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);

View File

@ -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);