mirror of https://github.com/tc39/test262.git
Fix bound function tests
This commit is contained in:
parent
57fa74b170
commit
fe0d4dc781
|
@ -3,23 +3,51 @@
|
||||||
/*---
|
/*---
|
||||||
esid: sec-getfunctionrealm
|
esid: sec-getfunctionrealm
|
||||||
description: >
|
description: >
|
||||||
The realm of a bound function exotic object is the realm of its target
|
The realm of a bound function exotic object is the realm of its target function.
|
||||||
function. GetFunctionRealm is called recursively.
|
GetFunctionRealm is called recursively.
|
||||||
info: |
|
info: |
|
||||||
7.3.22 GetFunctionRealm ( obj )
|
Object ( [ value ] )
|
||||||
|
|
||||||
[...]
|
1. If NewTarget is neither undefined nor the active function, then
|
||||||
2. If obj has a [[Realm]] internal slot, then
|
a. Return ? OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%").
|
||||||
a. Return obj.[[Realm]].
|
|
||||||
3. If obj is a Bound Function exotic object, then
|
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||||
a. Let target be obj.[[BoundTargetFunction]].
|
|
||||||
b. Return ? GetFunctionRealm(target).
|
[...]
|
||||||
features: [cross-realm]
|
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 realm1 = $262.createRealm().global;
|
||||||
var C = new other.Function();
|
var realm2 = $262.createRealm().global;
|
||||||
C.prototype = null;
|
var realm3 = $262.createRealm().global;
|
||||||
var B = C.bind().bind();
|
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);
|
||||||
|
|
|
@ -3,23 +3,53 @@
|
||||||
/*---
|
/*---
|
||||||
esid: sec-getfunctionrealm
|
esid: sec-getfunctionrealm
|
||||||
description: >
|
description: >
|
||||||
The realm of a bound function exotic object is the realm of its target
|
The realm of a bound function exotic object is the realm of its target function.
|
||||||
function
|
|
||||||
info: |
|
info: |
|
||||||
7.3.22 GetFunctionRealm ( obj )
|
Date ( )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
3. If NewTarget is undefined, then
|
||||||
[...]
|
[...]
|
||||||
2. If obj has a [[Realm]] internal slot, then
|
4. Else,
|
||||||
a. Return obj.[[Realm]].
|
a. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", « [[DateValue]] »).
|
||||||
3. If obj is a Bound Function exotic object, then
|
[...]
|
||||||
a. Let target be obj.[[BoundTargetFunction]].
|
c. Return O.
|
||||||
b. Return ? GetFunctionRealm(target).
|
|
||||||
features: [cross-realm]
|
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 realm1 = $262.createRealm().global;
|
||||||
var C = new other.Function();
|
var realm2 = $262.createRealm().global;
|
||||||
C.prototype = null;
|
var realm3 = $262.createRealm().global;
|
||||||
var B = C.bind();
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue