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
@@ -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
@@ -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]
---*/
This conversation was marked as resolved by rwaldron

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jun 11, 2019

Contributor

Missing features: [FinalizationGroup]


assert.sameValue(
typeof FinalizationGroup, 'function',
'typeof FinalizationGroup is function'
);
@@ -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);
@@ -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
});
@@ -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
});
@@ -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');
@@ -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
});
@@ -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');

@@ -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`'
);
@@ -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);
@@ -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');
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.