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

Function branding boilerplate tests from PR #3866 #4230

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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-asyncdisposablestack
description: >
[[Prototype]] defaults to %AsyncDisposableStack.prototype% if NewTarget.prototype is not an object.
info: |
AsyncDisposableStack( target )

...
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, Reflect.construct, Symbol]
---*/

var stack;
function newTarget() {}

newTarget.prototype = undefined;
stack = Reflect.construct(AsyncDisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), AsyncDisposableStack.prototype, 'newTarget.prototype is undefined');

newTarget.prototype = null;
stack = Reflect.construct(AsyncDisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), AsyncDisposableStack.prototype, 'newTarget.prototype is null');

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

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

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

newTarget.prototype = 1;
stack = Reflect.construct(AsyncDisposableStack, [], newTarget);
assert.sameValue(Object.getPrototypeOf(stack), AsyncDisposableStack.prototype, 'newTarget.prototype is a Number');
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.adopt
description: Throws a TypeError if this does not have a [[AsyncDisposableState]] internal slot
info: |
AsyncDisposableStack.prototype.adopt ( value, onDisposeAsync )

1. Let asyncDisposableStack be the this value.
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]).
3. ...

RequireInternalSlot ( O, internalSlot )

1. If O is not an Object, throw a TypeError exception.
2. If O does not have an internalSlot internal slot, throw a TypeError exception.
...

features: [explicit-resource-management]
---*/

assert.sameValue(typeof AsyncDisposableStack.prototype.adopt, 'function');

var adopt = AsyncDisposableStack.prototype.adopt;

assert.throws(TypeError, function() {
adopt.call({ ['[[AsyncDisposableState]]']: {} });
}, 'Ordinary object without [[AsyncDisposableState]]');

assert.throws(TypeError, function() {
adopt.call(AsyncDisposableStack.prototype);
}, 'AsyncDisposableStack.prototype does not have a [[AsyncDisposableState]] internal slot');

assert.throws(TypeError, function() {
adopt.call(AsyncDisposableStack);
}, 'AsyncDisposableStack does not have a [[AsyncDisposableState]] internal slot');

var stack = new DisposableStack();
assert.throws(TypeError, function() {
adopt.call(stack);
}, 'DisposableStack instance');
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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.adopt
description: Throws a TypeError if this is not an Object
info: |
AsyncDisposableStack.prototype.adopt ( value, onDisposeAsync )

1. Let asyncDisposableStack be the this value.
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]).
...

RequireInternalSlot ( O, internalSlot )

1. If O is not an Object, throw a TypeError exception.
...

features: [explicit-resource-management]
---*/

assert.sameValue(typeof AsyncDisposableStack.prototype.adopt, 'function');

var adopt = AsyncDisposableStack.prototype.adopt;

assert.throws(TypeError, function() {
adopt.call(undefined);
}, 'undefined');

assert.throws(TypeError, function() {
adopt.call(null);
}, 'null');

assert.throws(TypeError, function() {
adopt.call(true);
}, 'true');

assert.throws(TypeError, function() {
adopt.call(false);
}, 'false');

assert.throws(TypeError, function() {
adopt.call(1);
}, 'number');

assert.throws(TypeError, function() {
adopt.call('object');
}, 'string');

var s = Symbol();
assert.throws(TypeError, function() {
adopt.call(s);
}, 'symbol');
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.defer
description: Throws a TypeError if this does not have a [[AsyncDisposableState]] internal slot
info: |
AsyncDisposableStack.prototype.defer ( )

1. Let asyncDisposableStack be the this value.
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]).
3. ...

RequireInternalSlot ( O, internalSlot )

1. If O is not an Object, throw a TypeError exception.
2. If O does not have an internalSlot internal slot, throw a TypeError exception.
...

features: [explicit-resource-management]
---*/

assert.sameValue(typeof AsyncDisposableStack.prototype.defer, 'function');

var defer = AsyncDisposableStack.prototype.defer;

assert.throws(TypeError, function() {
defer.call({ ['[[AsyncDisposableState]]']: {} });
}, 'Ordinary object without [[AsyncDisposableState]]');

assert.throws(TypeError, function() {
defer.call(AsyncDisposableStack.prototype);
}, 'AsyncDisposableStack.prototype does not have a [[AsyncDisposableState]] internal slot');

assert.throws(TypeError, function() {
defer.call(AsyncDisposableStack);
}, 'AsyncDisposableStack does not have a [[AsyncDisposableState]] internal slot');

var stack = new DisposableStack();
assert.throws(TypeError, function() {
defer.call(stack);
}, 'DisposableStack instance');
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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.defer
description: Throws a TypeError if this is not an Object
info: |
AsyncDisposableStack.prototype.defer ( )

1. Let asyncDisposableStack be the this value.
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]).
...

RequireInternalSlot ( O, internalSlot )

1. If O is not an Object, throw a TypeError exception.
...

features: [explicit-resource-management]
---*/

assert.sameValue(typeof AsyncDisposableStack.prototype.defer, 'function');

var defer = AsyncDisposableStack.prototype.defer;

assert.throws(TypeError, function() {
defer.call(undefined);
}, 'undefined');

assert.throws(TypeError, function() {
defer.call(null);
}, 'null');

assert.throws(TypeError, function() {
defer.call(true);
}, 'true');

assert.throws(TypeError, function() {
defer.call(false);
}, 'false');

assert.throws(TypeError, function() {
defer.call(1);
}, 'number');

assert.throws(TypeError, function() {
defer.call('object');
}, 'string');

var s = Symbol();
assert.throws(TypeError, function() {
defer.call(s);
}, 'symbol');
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.disposeAsync
description: Throws a TypeError if this does not have a [[AsyncDisposableState]] internal slot
info: |
AsyncDisposableStack.prototype.disposeAsync ( )

1. Let asyncDisposableStack be the this value.
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]).
3. ...

RequireInternalSlot ( O, internalSlot )

1. If O is not an Object, throw a TypeError exception.
2. If O does not have an internalSlot internal slot, throw a TypeError exception.
...

flags: [async]
includes: [asyncHelpers.js]
features: [explicit-resource-management]
---*/

asyncTest(async function() {
assert.sameValue(typeof AsyncDisposableStack.prototype.disposeAsync, 'function');

var disposeAsync = AsyncDisposableStack.prototype.disposeAsync;

await assert.throwsAsync(TypeError, function() {
return disposeAsync.call({ ['[[AsyncDisposableState]]']: {} });
}, 'Ordinary object without [[AsyncDisposableState]]');

await assert.throwsAsync(TypeError, function() {
return disposeAsync.call(AsyncDisposableStack.prototype);
}, 'AsyncDisposableStack.prototype does not have a [[AsyncDisposableState]] internal slot');

await assert.throwsAsync(TypeError, function() {
return disposeAsync.call(AsyncDisposableStack);
}, 'AsyncDisposableStack does not have a [[AsyncDisposableState]] internal slot');

var stack = new DisposableStack();
await assert.throwsAsync(TypeError, function () {
return disposeAsync.call(stack);
}, 'DisposableStack instance');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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.disposeAsync
description: Throws a TypeError if this is not an Object
info: |
AsyncDisposableStack.prototype.disposeAsync ( )

1. Let asyncDisposableStack be the this value.
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]).
...

RequireInternalSlot ( O, internalSlot )

1. If O is not an Object, throw a TypeError exception.
...

flags: [async]
includes: [asyncHelpers.js]
features: [explicit-resource-management]
---*/

assert.sameValue(typeof AsyncDisposableStack.prototype.disposeAsync, 'function');

var disposeAsync = AsyncDisposableStack.prototype.disposeAsync;

asyncTest(async function () {
await assert.throwsAsync(TypeError, function() {
return disposeAsync.call(undefined);
}, 'undefined');

await assert.throwsAsync(TypeError, function() {
return disposeAsync.call(null);
}, 'null');

await assert.throwsAsync(TypeError, function() {
return disposeAsync.call(true);
}, 'true');

await assert.throwsAsync(TypeError, function() {
return disposeAsync.call(false);
}, 'false');

await assert.throwsAsync(TypeError, function() {
return disposeAsync.call(1);
}, 'number');

await assert.throwsAsync(TypeError, function() {
return disposeAsync.call('object');
}, 'string');

var s = Symbol();
await assert.throwsAsync(TypeError, function() {
return disposeAsync.call(s);
}, 'symbol');
});
Original file line number Diff line number Diff line change
@@ -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: >
Throws a TypeError if `this` object does not have a [[AsyncDisposableState]] internal slot.
info: |
get AsyncDisposableStack.prototype.disposed

1. Let asyncDisposableStack be the this value.
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]).
...

RequireInternalSlot ( O, internalSlot )

1. If O is not an Object, throw a TypeError exception.
2. If O does not have an internalSlot internal slot, throw a TypeError exception.
...

features: [explicit-resource-management]
---*/

var descriptor = Object.getOwnPropertyDescriptor(AsyncDisposableStack.prototype, 'disposed');

var stack = new AsyncDisposableStack();

// Does not throw
descriptor.get.call(stack);

assert.throws(TypeError, function() {
descriptor.get.call([]);
});
Loading
Loading