Builtin boilerplate tests from PR #3866 (#4236)

Includes some proto-from-ctor-realm.js tests that look like standard tests for prototypes.

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
This commit is contained in:
Ioanna M Dimitriou H 2024-09-24 14:04:28 +02:00 committed by GitHub
parent 0c7af4685f
commit c63d53ad9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 516 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncdisposablestack
description: Instances of AsyncDisposableStack are extensible
info: |
AsyncDisposableStack( )
...
2. Let asyncDisposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncDisposableStack.prototype%", « [[AsyncDisposableState]], [[DisposeCapability]] »).
3. Set asyncDisposableStack.[[AsyncDisposableState]] to pending.
4. Set asyncDisposableStack.[[DisposeCapability]] to NewDisposeCapability().
5. Return asyncDisposableStack.
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: [explicit-resource-management, Reflect]
---*/
var stack = new AsyncDisposableStack();
assert.sameValue(Object.isExtensible(stack), true);

View File

@ -0,0 +1,59 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncdisposablestack
description: Default [[Prototype]] value derived from realm of the newTarget
info: |
AsyncDisposableStack( )
...
2. Let asyncDisposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncDisposableStack.prototype%", « [[AsyncDisposableState]], [[DisposeCapability]] »).
3. Set asyncDisposableStack.[[AsyncDisposableState]] to pending.
4. Set asyncDisposableStack.[[DisposeCapability]] to NewDisposeCapability().
5. Return asyncDisposableStack.
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: [explicit-resource-management, cross-realm, Reflect, Symbol]
---*/
var other = $262.createRealm().global;
var newTarget = new other.Function();
var stack;
newTarget.prototype = undefined;
stack = Reflect.construct(AsyncDisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.AsyncDisposableStack.prototype, 'newTarget.prototype is undefined');
newTarget.prototype = null;
stack = Reflect.construct(AsyncDisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.AsyncDisposableStack.prototype, 'newTarget.prototype is null');
newTarget.prototype = true;
stack = Reflect.construct(AsyncDisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.AsyncDisposableStack.prototype, 'newTarget.prototype is a Boolean');
newTarget.prototype = '';
stack = Reflect.construct(AsyncDisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.AsyncDisposableStack.prototype, 'newTarget.prototype is a String');
newTarget.prototype = Symbol();
stack = Reflect.construct(AsyncDisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.AsyncDisposableStack.prototype, 'newTarget.prototype is a Symbol');
newTarget.prototype = 1;
stack = Reflect.construct(AsyncDisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.AsyncDisposableStack.prototype, 'newTarget.prototype is a Number');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-asyncdisposablestack-constructor
description: >
The prototype of AsyncDisposableStack is Function.prototype
info: |
The value of the [[Prototype]] internal slot of the AsyncDisposableStack object is the
intrinsic object %FunctionPrototype%.
features: [explicit-resource-management]
---*/
assert.sameValue(
Object.getPrototypeOf(AsyncDisposableStack),
Function.prototype,
'Object.getPrototypeOf(AsyncDisposableStack) returns the value of `Function.prototype`'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncdisposablestack.prototype-@@asyncDispose
description: Initial state of the Symbol.asyncDispose property
info: |
The initial value of the @@asyncDispose property is the same function object as
the initial value of the disposeAsync property.
Per ES6 section 17, the method should exist on the Array prototype, and it
should be writable and configurable, but not enumerable.
includes: [propertyHelper.js]
features: [explicit-resource-management]
---*/
verifyProperty(AsyncDisposableStack.prototype, Symbol.asyncDispose, {
value: AsyncDisposableStack.prototype.disposeAsync,
enumerable: false,
writable: true,
configurable: true,
});

View File

@ -0,0 +1,32 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-asyncdisposablestack.prototype.disposed
description: >
Property type and descriptor.
info: |
get AsyncDisposableStack.prototype.disposed
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
features: [explicit-resource-management]
---*/
var descriptor = Object.getOwnPropertyDescriptor(AsyncDisposableStack.prototype, 'disposed');
assert.sameValue(
typeof descriptor.get,
'function',
'typeof descriptor.get is function'
);
assert.sameValue(
typeof descriptor.set,
'undefined',
'typeof descriptor.set is undefined'
);
verifyProperty(AsyncDisposableStack.prototype, 'disposed', {
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,14 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The prototype of AsyncDisposableStack.prototype is Object.prototype
esid: sec-properties-of-the-asyncdisposablestack-prototype-object
info: |
The value of the [[Prototype]] internal slot of the AsyncDisposableStack prototype object
is the intrinsic object %Object.prototype%.
features: [explicit-resource-management]
---*/
var proto = Object.getPrototypeOf(AsyncDisposableStack.prototype);
assert.sameValue(proto, Object.prototype);

View File

@ -0,0 +1,13 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%asynciteratorprototype%-@@asyncDispose
description: >
AsyncIterator.prototype[@@asyncDispose] is a built-in function
features: [explicit-resource-management]
---*/
async function* generator() {}
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(generator.prototype))
assert.sameValue(typeof AsyncIteratorPrototype[Symbol.asyncDispose], 'function');

View File

@ -0,0 +1,31 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-disposablestack
description: Instances of DisposableStack are extensible
info: |
DisposableStack( )
...
2. Let disposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%DisposableStack.prototype%", « [[DisposableState]], [[DisposeCapability]] »).
3. Set disposableStack.[[DisposableState]] to pending.
4. Set disposableStack.[[DisposeCapability]] to NewDisposeCapability().
5. Return disposableStack.
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: [explicit-resource-management, Reflect]
---*/
var stack = new DisposableStack();
assert.sameValue(Object.isExtensible(stack), true);

View File

@ -0,0 +1,59 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-disposablestack
description: Default [[Prototype]] value derived from realm of the newTarget
info: |
DisposableStack( )
...
2. Let disposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%DisposableStack.prototype%", « [[DisposableState]], [[DisposeCapability]] »).
3. Set disposableStack.[[DisposableState]] to pending.
4. Set disposableStack.[[DisposeCapability]] to NewDisposeCapability().
5. Return disposableStack.
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: [explicit-resource-management, cross-realm, Reflect, Symbol]
---*/
var other = $262.createRealm().global;
var newTarget = new other.Function();
var stack;
newTarget.prototype = undefined;
stack = Reflect.construct(DisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.DisposableStack.prototype, 'newTarget.prototype is undefined');
newTarget.prototype = null;
stack = Reflect.construct(DisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.DisposableStack.prototype, 'newTarget.prototype is null');
newTarget.prototype = true;
stack = Reflect.construct(DisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.DisposableStack.prototype, 'newTarget.prototype is a Boolean');
newTarget.prototype = '';
stack = Reflect.construct(DisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.DisposableStack.prototype, 'newTarget.prototype is a String');
newTarget.prototype = Symbol();
stack = Reflect.construct(DisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.DisposableStack.prototype, 'newTarget.prototype is a Symbol');
newTarget.prototype = 1;
stack = Reflect.construct(DisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), other.DisposableStack.prototype, 'newTarget.prototype is a Number');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-disposablestack-constructor
description: >
The prototype of DisposableStack is Function.prototype
info: |
The value of the [[Prototype]] internal slot of the DisposableStack object is the
intrinsic object %FunctionPrototype%.
features: [explicit-resource-management]
---*/
assert.sameValue(
Object.getPrototypeOf(DisposableStack),
Function.prototype,
'Object.getPrototypeOf(DisposableStack) returns the value of `Function.prototype`'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-disposablestack.prototype-@@dispose
description: Initial state of the Symbol.dispose property
info: |
The initial value of the @@dispose property is the same function object as
the initial value of the dispose property.
Per ES6 section 17, the method should exist on the Array prototype, and it
should be writable and configurable, but not enumerable.
includes: [propertyHelper.js]
features: [explicit-resource-management]
---*/
assert.sameValue(DisposableStack.prototype[Symbol.dispose], DisposableStack.prototype.dispose);
verifyProperty(DisposableStack.prototype, Symbol.dispose, {
enumerable: false;
writable: true;
configurable: true;
});

View File

@ -0,0 +1,32 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-disposablestack.prototype.disposed
description: >
Property type and descriptor.
info: |
get DisposableStack.prototype.disposed
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
features: [explicit-resource-management]
---*/
var descriptor = Object.getOwnPropertyDescriptor(DisposableStack.prototype, 'disposed');
assert.sameValue(
typeof descriptor.get,
'function',
'typeof descriptor.get is function'
);
assert.sameValue(
typeof descriptor.set,
'undefined',
'typeof descriptor.set is undefined'
);
verifyProperty(DisposableStack.prototype, 'disposed', {
enumerable: false;
configurable: true;
});

View File

@ -0,0 +1,14 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The prototype of DisposableStack.prototype is Object.prototype
esid: sec-properties-of-the-disposablestack-prototype-object
info: |
The value of the [[Prototype]] internal slot of the DisposableStack prototype object
is the intrinsic object %Object.prototype%.
features: [explicit-resource-management]
---*/
var proto = Object.getPrototypeOf(DisposableStack.prototype);
assert.sameValue(proto, Object.prototype);

View File

@ -0,0 +1,13 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%iteratorprototype%-@@dispose
description: >
Iterator.prototype[@@dispose] is a built-in function
features: [explicit-resource-management]
---*/
const IteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf([][Symbol.iterator]())
);
assert.sameValue(typeof IteratorPrototype[Symbol.dispose], 'function');

View File

@ -0,0 +1,58 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-suppressederror-constructor
description: Default [[Prototype]] value derived from realm of the NewTarget.
info: |
SuppressedError ( error, suppressed, message )
1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%SuppressedError.prototype%", « [[ErrorData]] »).
...
6. Return O.
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: [explicit-resource-management, cross-realm, Reflect, Symbol]
---*/
var other = $262.createRealm().global;
var newTarget = new other.Function();
var err;
newTarget.prototype = undefined;
err = Reflect.construct(SuppressedError, [[]], newTarget);
assert.sameValue(Object.getPrototypeOf(err), other.SuppressedError.prototype, 'newTarget.prototype is undefined');
newTarget.prototype = null;
err = Reflect.construct(SuppressedError, [[]], newTarget);
assert.sameValue(Object.getPrototypeOf(err), other.SuppressedError.prototype, 'newTarget.prototype is null');
newTarget.prototype = true;
err = Reflect.construct(SuppressedError, [[]], newTarget);
assert.sameValue(Object.getPrototypeOf(err), other.SuppressedError.prototype, 'newTarget.prototype is a Boolean');
newTarget.prototype = '';
err = Reflect.construct(SuppressedError, [[]], newTarget);
assert.sameValue(Object.getPrototypeOf(err), other.SuppressedError.prototype, 'newTarget.prototype is a String');
newTarget.prototype = Symbol();
err = Reflect.construct(SuppressedError, [[]], newTarget);
assert.sameValue(Object.getPrototypeOf(err), other.SuppressedError.prototype, 'newTarget.prototype is a Symbol');
newTarget.prototype = -1;
err = Reflect.construct(SuppressedError, [[]], newTarget);
assert.sameValue(Object.getPrototypeOf(err), other.SuppressedError.prototype, 'newTarget.prototype is a Number');

View File

@ -0,0 +1,16 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The prototype of SuppressedError constructor is Error
esid: sec-properties-of-the-suppressederror-constructors
info: |
Properties of the SuppressedError Constructor
- has a [[Prototype]] internal slot whose value is the intrinsic object %Error%.
features: [explicit-resource-management]
---*/
var proto = Object.getPrototypeOf(SuppressedError);
assert.sameValue(proto, Error);

View File

@ -0,0 +1,25 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-suppressederror.prototype.constructor
description: >
The `SuppressedError.prototype.constructor` property descriptor.
info: |
The initial value of SuppressedError.prototype.constructor is the intrinsic
object %SuppressedError%.
17 ECMAScript Standard Built-in Objects:
Every other data property described (...) has the attributes { [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified.
includes: [propertyHelper.js]
features: [explicit-resource-management]
---*/
verifyProperty(SuppressedError.prototype, 'constructor', {
value: SuppressedError,
enumerable: false,
writable: true,
configurable: true
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-aggregate-error.prototype.message
description: >
The `SuppressedError.prototype.message` property descriptor.
info: |
The initial value of the message property of the prototype for a given SuppressedError
constructor is the empty String.
17 ECMAScript Standard Built-in Objects:
Every other data property described (...) has the attributes { [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified.
includes: [propertyHelper.js]
features: [explicit-resource-management]
---*/
verifyProperty(SuppressedError.prototype, 'message', {
value: '',
enumerable: false,
writable: true,
configurable: true
});

View File

@ -0,0 +1,16 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-the-suppressederror-prototype-objects
description: The prototype of SuppressedError.prototype constructor is Error.prototype
info: |
Properties of the SuppressedError Prototype Object
- has a [[Prototype]] internal slot whose value is the intrinsic object %Error.prototype%.
features: [explicit-resource-management]
---*/
var proto = Object.getPrototypeOf(SuppressedError.prototype);
assert.sameValue(proto, Error.prototype);