Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic tests for WeakRef and FinalizationGroup #2192

Merged
merged 11 commits into from
Jun 21, 2019
5 changes: 5 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ export-star-as-namespace-from-module
# https://github.com/tc39/proposal-import-meta
import.meta

# WeakRef
# https://github.com/tc39/proposal-weakref
WeakRef
FinalizationGroup

## Standard language features
#
# Language features that have been included in a published version of the
Expand Down
15 changes: 15 additions & 0 deletions test/built-ins/FinalizationGroup/constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-finalization-group-constructor
description: >
The FinalizationGroup constructor is the %FinalizationGroup% intrinsic object and the initial
value of the FinalizationGroup property of the global object.
features: [FinalizationGroup]
---*/
rwaldron marked this conversation as resolved.
Show resolved Hide resolved

assert.sameValue(
typeof FinalizationGroup, 'function',
'typeof FinalizationGroup is function'
);
30 changes: 30 additions & 0 deletions test/built-ins/FinalizationGroup/instance-extensible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-finalization-group-target
description: Instances of FinalizationGroup are extensible
info: |
FinalizationGroup ( cleanupCallback )

...
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
...
9. Return finalizationGroup.

OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

...
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
3. Return ObjectCreate(proto, internalSlotsList).

ObjectCreate ( proto [ , internalSlotsList ] )

4. Set obj.[[Prototype]] to proto.
5. Set obj.[[Extensible]] to true.
6. Return obj.
features: [FinalizationGroup]
---*/

var fg = new FinalizationGroup(function() {});
assert.sameValue(Object.isExtensible(fg), true);
32 changes: 32 additions & 0 deletions test/built-ins/FinalizationGroup/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-finalization-group-target
description: FinalizationGroup.length property descriptor
info: |
FinalizationGroup ( cleanupCallback )

17 ECMAScript Standard Built-in Objects

Every built-in function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which
are shown using the form «...name») are not included in the default
argument count.

Unless otherwise specified, the length property of a built-in
function object has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [FinalizationGroup]
---*/

verifyProperty(FinalizationGroup, 'length', {
value: 1,
writable: false,
enumerable: false,
configurable: true
});
31 changes: 31 additions & 0 deletions test/built-ins/FinalizationGroup/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-finalization-group-target
description: FinalizationGroup.name property descriptor
info: |
FinalizationGroup ( value )

17 ECMAScript Standard Built-in Objects

Every built-in function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String. Unless otherwise specified, this value is the name that
is given to the function in this specification. For functions that
are specified as properties of objects, the name value is the
property name string used to access the function. [...]

Unless otherwise specified, the name property of a built-in function
object, if it exists, has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [FinalizationGroup]
---*/

verifyProperty(FinalizationGroup, 'name', {
value: 'FinalizationGroup',
writable: false,
enumerable: false,
configurable: true
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-finalization-group-target
description: >
[[Prototype]] defaults to %FinalizationGroupPrototype% if NewTarget.prototype is not an object.
info: |
FinalizationGroup ( cleanupCallback )

...
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
...
9. Return finalizationGroup.

OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

...
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
3. Return ObjectCreate(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.
features: [FinalizationGroup, Reflect.construct, Symbol]
---*/

var fg;
function newTarget() {}
function fn() {}

newTarget.prototype = undefined;
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is undefined');

newTarget.prototype = null;
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is null');

newTarget.prototype = true;
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a Boolean');

newTarget.prototype = '';
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a String');

newTarget.prototype = Symbol();
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a Symbol');

newTarget.prototype = 1;
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a Number');
22 changes: 22 additions & 0 deletions test/built-ins/FinalizationGroup/prop-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-finalization-group-constructor
description: >
Property descriptor of FinalizationGroup
info: |
17 ECMAScript Standard Built-in Objects:

Every other data property described in clauses 18 through 26 and in Annex B.2
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
includes: [propertyHelper.js]
features: [FinalizationGroup]
---*/

verifyProperty(this, 'FinalizationGroup', {
enumerable: false,
writable: true,
configurable: true
});
59 changes: 59 additions & 0 deletions test/built-ins/FinalizationGroup/proto-from-ctor-realm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-finalization-group-target
description: Default [[Prototype]] value derived from realm of the newTarget
info: |
FinalizationGroup ( cleanupCallback )

...
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
...
9. Return finalizationGroup.

OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

...
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
3. Return ObjectCreate(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.
features: [FinalizationGroup, cross-realm, Reflect]
---*/

var other = $262.createRealm().global;
var newTarget = new other.Function();
function fn() {}
var fg;

newTarget.prototype = undefined;
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is undefined');

newTarget.prototype = null;
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is null');

newTarget.prototype = true;
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a Boolean');

newTarget.prototype = '';
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a String');

newTarget.prototype = Symbol();
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a Symbol');

newTarget.prototype = 1;
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a Number');

18 changes: 18 additions & 0 deletions test/built-ins/FinalizationGroup/proto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-properties-of-the-finalization-group-constructor
description: >
The prototype of FinalizationGroup is Object.prototype
info: |
The value of the [[Prototype]] internal slot of the FinalizationGroup object is the
intrinsic object %FunctionPrototype%.
features: [FinalizationGroup]
---*/

assert.sameValue(
Object.getPrototypeOf(FinalizationGroup),
Function.prototype,
'Object.getPrototypeOf(FinalizationGroup) returns the value of `Function.prototype`'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-finalization-group-target
description: >
Return abrupt from getting the NewTarget prototype
info: |
FinalizationGroup ( cleanupCallback )

...
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
...
9. Return finalizationGroup.

OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

...
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
3. Return ObjectCreate(proto, internalSlotsList).

GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )

3. Let proto be ? Get(constructor, 'prototype').
features: [FinalizationGroup, Reflect.construct]
---*/

var calls = 0;
var newTarget = function() {}.bind(null);
Object.defineProperty(newTarget, 'prototype', {
get: function() {
calls += 1;
throw new Test262Error();
}
});

assert.throws(Test262Error, function() {
Reflect.construct(FinalizationGroup, [function() {}], newTarget);
});

assert.sameValue(calls, 1);
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-finalization-group-target
description: >
The [[Prototype]] internal slot is computed from NewTarget.
info: |
FinalizationGroup ( cleanupCallback )

...
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
...
9. Return finalizationGroup.

OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

...
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
3. Return ObjectCreate(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.
features: [FinalizationGroup, Reflect.construct]
---*/

var fg;

fg = Reflect.construct(FinalizationGroup, [function() {}], Object);
assert.sameValue(Object.getPrototypeOf(fg), Object.prototype, 'NewTarget is built-in Object constructor');

var newTarget = function() {}.bind(null);
Object.defineProperty(newTarget, 'prototype', {
get: function() {
return Array.prototype;
}
});
fg = Reflect.construct(FinalizationGroup, [function() {}], newTarget);
assert.sameValue(Object.getPrototypeOf(fg), Array.prototype, 'NewTarget is BoundFunction with accessor');
Loading