Improve GetFunctionRealm coverage (#2155)

* Fix Function.prototype.bind test

* Simplify Proxy test

* Info tweaks

* Add Function.prototype.bind recursive test

* Add Proxy recursive test
This commit is contained in:
Aleksey Shvayka 2019-05-23 01:11:49 +03:00 committed by Leo Balter
parent 1951d335d6
commit 6f4c0d96f7
4 changed files with 67 additions and 14 deletions

View File

@ -0,0 +1,25 @@
// Copyright (C) 2019 Aleksey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-getfunctionrealm
description: >
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 )
[...]
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]
---*/
var other = $262.createRealm().global;
var C = new other.Function();
C.prototype = null;
var B = C.bind().bind();
assert.sameValue(Object.getPrototypeOf(new B()), other.Object.prototype);

View File

@ -7,17 +7,20 @@ description: >
The realm of a bound function exotic object is the realm of its target
function
info: |
7.3.22 GetFunctionRealm ( obj )
[...]
2. If obj has a [[Realm]] internal slot, then
a, Return obj's [[Realm]] internal slot.
a. Return obj.[[Realm]].
3. If obj is a Bound Function exotic object, then
a. Let target be obj's [[BoundTargetFunction]] internal slot.
a. Let target be obj.[[BoundTargetFunction]].
b. Return ? GetFunctionRealm(target).
features: [cross-realm]
---*/
var other = $262.createRealm().global;
var C = new other.Function();
var B = Function.prototype.bind.call(C);
C.prototype = null;
var B = C.bind();
assert.sameValue(Object.getPrototypeOf(new B()), C.prototype);
assert.sameValue(Object.getPrototypeOf(new B()), other.Object.prototype);

View File

@ -0,0 +1,27 @@
// Copyright (C) 2019 Aleksey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-getfunctionrealm
description: >
The realm of a proxy exotic object is the realm of its target function.
GetFunctionRealm is called recursively.
info: |
7.3.22 GetFunctionRealm ( obj )
[...]
2. If obj has a [[Realm]] internal slot, then
a. Return obj.[[Realm]].
[...]
4. If obj is a Proxy exotic object, then
a. If obj.[[ProxyHandler]] is null, throw a TypeError exception.
b. Let proxyTarget be obj.[[ProxyTarget]].
c. Return ? GetFunctionRealm(proxyTarget).
features: [cross-realm, Proxy]
---*/
var other = $262.createRealm().global;
var C = new other.Function();
C.prototype = null;
var P = new Proxy(new Proxy(C, {}), {});
assert.sameValue(Object.getPrototypeOf(new P()), other.Object.prototype);

View File

@ -6,24 +6,22 @@ es6id: 7.3.22
description: >
The realm of a proxy exotic object is the realm of its target function
info: |
7.3.22 GetFunctionRealm ( obj )
[...]
2. If obj has a [[Realm]] internal slot, then
a, Return obj's [[Realm]] internal slot.
3. If obj is a Bound Function exotic object, then
[...]
a. Return obj.[[Realm]].
[...]
4. If obj is a Proxy exotic object, then
a. If the value of the [[ProxyHandler]] internal slot of obj is null,
throw a TypeError exception.
b. Let proxyTarget be the value of obj's [[ProxyTarget]] internal slot.
a. If obj.[[ProxyHandler]] is null, throw a TypeError exception.
b. Let proxyTarget be obj.[[ProxyTarget]].
c. Return ? GetFunctionRealm(proxyTarget).
features: [cross-realm, Proxy]
---*/
var other = $262.createRealm().global;
var C = new other.Function();
// Ensure that the proxy does not report a `prototype` property
var P = new Proxy(C, {
get: function() {}
});
C.prototype = null;
var P = new Proxy(C, {});
assert.sameValue(Object.getPrototypeOf(new P()), other.Object.prototype);