Skip to content

Commit d6505e9

Browse files
committed
More tests
1 parent 9b2be0c commit d6505e9

29 files changed

+729
-17
lines changed

test/built-ins/FinalizationGroup/constructor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ description: >
1010

1111
assert.sameValue(
1212
typeof FinalizationGroup, 'function',
13-
'typeof FinalizationGroup is "function"'
13+
'typeof FinalizationGroup is function'
1414
);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2019 Leo Balter. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-finalization-group-target
6+
description: Instances of FinalizationGroup are extensible
7+
info: |
8+
FinalizationGroup ( cleanupCallback )
9+
10+
...
11+
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
12+
...
13+
9. Return finalizationGroup.
14+
15+
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
16+
17+
...
18+
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
19+
3. Return ObjectCreate(proto, internalSlotsList).
20+
21+
ObjectCreate ( proto [ , internalSlotsList ] )
22+
23+
4. Set obj.[[Prototype]] to proto.
24+
5. Set obj.[[Extensible]] to true.
25+
6. Return obj.
26+
features: [FinalizationGroup, Reflect]
27+
---*/
28+
29+
var fg = new FinalizationGroup(function() {});
30+
assert.sameValue(Object.isExtensible(fg), true);

test/built-ins/FinalizationGroup/length.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ includes: [propertyHelper.js]
2424
features: [FinalizationGroup]
2525
---*/
2626

27-
verifyProperty(FinalizationGroup, "length", {
27+
verifyProperty(FinalizationGroup, 'length', {
2828
value: 1,
2929
writable: false,
3030
enumerable: false,

test/built-ins/FinalizationGroup/name.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ includes: [propertyHelper.js]
2323
features: [FinalizationGroup]
2424
---*/
2525

26-
verifyProperty(FinalizationGroup, "name", {
27-
value: "FinalizationGroup",
26+
verifyProperty(FinalizationGroup, 'name', {
27+
value: 'FinalizationGroup',
2828
writable: false,
2929
enumerable: false,
3030
configurable: true
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (C) 2019 Leo Balter. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-finalization-group-target
6+
description: >
7+
[[Prototype]] defaults to %FinalizationGroupPrototype% if NewTarget.prototype is not an object.
8+
info: |
9+
FinalizationGroup ( cleanupCallback )
10+
11+
...
12+
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
13+
...
14+
9. Return finalizationGroup.
15+
16+
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
17+
18+
...
19+
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
20+
3. Return ObjectCreate(proto, internalSlotsList).
21+
22+
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
23+
24+
3. Let proto be ? Get(constructor, 'prototype').
25+
4. If Type(proto) is not Object, then
26+
a. Let realm be ? GetFunctionRealm(constructor).
27+
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
28+
5. Return proto.
29+
features: [FinalizationGroup, Reflect.construct, Symbol]
30+
---*/
31+
32+
var fg;
33+
function newTarget() {}
34+
function fn() {}
35+
36+
newTarget.prototype = undefined;
37+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
38+
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is undefined');
39+
40+
newTarget.prototype = null;
41+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
42+
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is null');
43+
44+
newTarget.prototype = true;
45+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
46+
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a Boolean');
47+
48+
newTarget.prototype = '';
49+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
50+
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a String');
51+
52+
newTarget.prototype = Symbol();
53+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
54+
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a Symbol');
55+
56+
newTarget.prototype = 1;
57+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
58+
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a Number');

test/built-ins/FinalizationGroup/prop-desc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ includes: [propertyHelper.js]
1515
features: [FinalizationGroup]
1616
---*/
1717

18-
verifyProperty(this, "FinalizationGroup", {
18+
verifyProperty(this, 'FinalizationGroup', {
1919
enumerable: false,
2020
writable: true,
2121
configurable: true
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (C) 2019 Leo Balter. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-finalization-group-target
6+
description: Default [[Prototype]] value derived from realm of the newTarget
7+
info: |
8+
FinalizationGroup ( cleanupCallback )
9+
10+
...
11+
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
12+
...
13+
9. Return finalizationGroup.
14+
15+
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
16+
17+
...
18+
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
19+
3. Return ObjectCreate(proto, internalSlotsList).
20+
21+
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
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+
features: [FinalizationGroup, cross-realm, Reflect]
29+
---*/
30+
31+
var other = $262.createRealm().global;
32+
var newTarget = new other.Function();
33+
function fn() {}
34+
var fg;
35+
36+
newTarget.prototype = undefined;
37+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
38+
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is undefined');
39+
40+
newTarget.prototype = null;
41+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
42+
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is null');
43+
44+
newTarget.prototype = true;
45+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
46+
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a Boolean');
47+
48+
newTarget.prototype = '';
49+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
50+
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a String');
51+
52+
newTarget.prototype = Symbol();
53+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
54+
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a Symbol');
55+
56+
newTarget.prototype = 1;
57+
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
58+
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a Number');
59+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (C) 2019 Leo Balter. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-finalization-group-target
6+
description: >
7+
Return abrupt from getting the NewTarget prototype
8+
info: |
9+
FinalizationGroup ( cleanupCallback )
10+
11+
...
12+
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
13+
...
14+
9. Return finalizationGroup.
15+
16+
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
17+
18+
...
19+
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
20+
3. Return ObjectCreate(proto, internalSlotsList).
21+
22+
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
23+
24+
3. Let proto be ? Get(constructor, 'prototype').
25+
features: [FinalizationGroup, Reflect.construct]
26+
---*/
27+
28+
var calls = 0;
29+
var newTarget = function() {}.bind(null);
30+
Object.defineProperty(newTarget, 'prototype', {
31+
get: function() {
32+
calls += 1;
33+
throw new Test262Error();
34+
}
35+
});
36+
37+
assert.throws(Test262Error, function() {
38+
Reflect.construct(FinalizationGroup, [{}], newTarget);
39+
});
40+
41+
assert.sameValue(calls, 1);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (C) 2019 Leo Balter. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-finalization-group-target
6+
description: >
7+
The [[Prototype]] internal slot is computed from NewTarget.
8+
info: |
9+
FinalizationGroup ( cleanupCallback )
10+
11+
...
12+
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
13+
...
14+
9. Return finalizationGroup.
15+
16+
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
17+
18+
...
19+
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
20+
3. Return ObjectCreate(proto, internalSlotsList).
21+
22+
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
23+
24+
3. Let proto be ? Get(constructor, 'prototype').
25+
4. If Type(proto) is not Object, then
26+
a. Let realm be ? GetFunctionRealm(constructor).
27+
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
28+
5. Return proto.
29+
features: [FinalizationGroup, Reflect.construct]
30+
---*/
31+
32+
var fg;
33+
34+
fg = Reflect.construct(FinalizationGroup, [function() {}], Object);
35+
assert.sameValue(Object.getPrototypeOf(fg), Object.prototype, 'NewTarget is built-in Object constructor');
36+
37+
var newTarget = function() {}.bind(null);
38+
Object.defineProperty(newTarget, 'prototype', {
39+
get: function() {
40+
return Array.prototype;
41+
}
42+
});
43+
fg = Reflect.construct(FinalizationGroup, [function() {}], newTarget);
44+
assert.sameValue(Object.getPrototypeOf(fg), Array.prototype, 'NewTarget is BoundFunction with accessor');
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (C) 2019 Leo Balter. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-finalization-group-target
6+
description: >
7+
The [[Prototype]] internal slot is computed from NewTarget.
8+
info: |
9+
FinalizationGroup ( cleanupCallback )
10+
11+
...
12+
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
13+
...
14+
9. Return finalizationGroup.
15+
16+
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
17+
18+
...
19+
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
20+
3. Return ObjectCreate(proto, internalSlotsList).
21+
22+
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
23+
24+
3. Let proto be ? Get(constructor, 'prototype').
25+
4. If Type(proto) is not Object, then
26+
a. Let realm be ? GetFunctionRealm(constructor).
27+
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
28+
5. Return proto.
29+
features: [FinalizationGroup]
30+
---*/
31+
32+
var fg = new FinalizationGroup(function() {});
33+
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype);

0 commit comments

Comments
 (0)