From dc7a22dd286da9f6ef5589de77550e9fe9e85cb2 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 2 Sep 2024 22:11:10 +0200 Subject: [PATCH] Function branding boilerplate tests from PR #3866 --- .../newtarget-prototype-is-not-object.js | 58 ++++++++++++++ ...ve-internal-asyncdisposablestate-throws.js | 42 +++++++++++ .../prototype/adopt/this-not-object-throws.js | 53 +++++++++++++ ...ve-internal-asyncdisposablestate-throws.js | 42 +++++++++++ .../prototype/defer/this-not-object-throws.js | 53 +++++++++++++ ...e-internal-asyncdisposablestate-rejects.js | 46 ++++++++++++ .../disposeAsync/this-not-object-rejects.js | 57 ++++++++++++++ ...have-asyncdisposablestate-internal-slot.js | 32 ++++++++ .../disposed/this-not-object-throw.js | 50 +++++++++++++ ...ve-internal-asyncdisposablestate-throws.js | 42 +++++++++++ .../prototype/move/this-not-object-throws.js | 53 +++++++++++++ ...ve-internal-asyncdisposablestate-throws.js | 44 +++++++++++ .../prototype/use/this-not-object-throws.js | 53 +++++++++++++ .../use/throws-if-value-not-object.js | 48 ++++++++++++ .../newtarget-prototype-is-not-object.js | 58 ++++++++++++++ ...ot-have-internal-disposablestate-throws.js | 42 +++++++++++ .../prototype/adopt/this-not-object-throws.js | 53 +++++++++++++ ...ot-have-internal-disposablestate-throws.js | 42 +++++++++++ .../prototype/defer/this-not-object-throws.js | 53 +++++++++++++ ...ot-have-internal-disposablestate-throws.js | 42 +++++++++++ .../dispose/this-not-object-throws.js | 53 +++++++++++++ ...-not-have-disposablestate-internal-slot.js | 32 ++++++++ .../disposed/this-not-object-throw.js | 50 +++++++++++++ ...ot-have-internal-disposablestate-throws.js | 42 +++++++++++ .../prototype/move/this-not-object-throws.js | 53 +++++++++++++ ...ot-have-internal-disposablestate-throws.js | 44 +++++++++++ .../prototype/use/this-not-object-throws.js | 53 +++++++++++++ .../use/throws-if-value-not-object.js | 48 ++++++++++++ .../message-undefined-no-prop.js | 33 ++++++++ .../throws-if-initializer-not-object.js | 75 +++++++++++++++++++ .../using/throws-if-initializer-not-object.js | 71 ++++++++++++++++++ 31 files changed, 1517 insertions(+) create mode 100644 test/built-ins/AsyncDisposableStack/newtarget-prototype-is-not-object.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/adopt/this-does-not-have-internal-asyncdisposablestate-throws.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/adopt/this-not-object-throws.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/defer/this-does-not-have-internal-asyncdisposablestate-throws.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/defer/this-not-object-throws.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/disposeAsync/this-does-not-have-internal-asyncdisposablestate-rejects.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/disposeAsync/this-not-object-rejects.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/disposed/does-not-have-asyncdisposablestate-internal-slot.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/disposed/this-not-object-throw.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/move/this-does-not-have-internal-asyncdisposablestate-throws.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/move/this-not-object-throws.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/use/this-does-not-have-internal-asyncdisposablestate-throws.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/use/this-not-object-throws.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/use/throws-if-value-not-object.js create mode 100644 test/built-ins/DisposableStack/newtarget-prototype-is-not-object.js create mode 100644 test/built-ins/DisposableStack/prototype/adopt/this-does-not-have-internal-disposablestate-throws.js create mode 100644 test/built-ins/DisposableStack/prototype/adopt/this-not-object-throws.js create mode 100644 test/built-ins/DisposableStack/prototype/defer/this-does-not-have-internal-disposablestate-throws.js create mode 100644 test/built-ins/DisposableStack/prototype/defer/this-not-object-throws.js create mode 100644 test/built-ins/DisposableStack/prototype/dispose/this-does-not-have-internal-disposablestate-throws.js create mode 100644 test/built-ins/DisposableStack/prototype/dispose/this-not-object-throws.js create mode 100644 test/built-ins/DisposableStack/prototype/disposed/does-not-have-disposablestate-internal-slot.js create mode 100644 test/built-ins/DisposableStack/prototype/disposed/this-not-object-throw.js create mode 100644 test/built-ins/DisposableStack/prototype/move/this-does-not-have-internal-disposablestate-throws.js create mode 100644 test/built-ins/DisposableStack/prototype/move/this-not-object-throws.js create mode 100644 test/built-ins/DisposableStack/prototype/use/this-does-not-have-internal-disposablestate-throws.js create mode 100644 test/built-ins/DisposableStack/prototype/use/this-not-object-throws.js create mode 100644 test/built-ins/DisposableStack/prototype/use/throws-if-value-not-object.js create mode 100644 test/built-ins/NativeErrors/SuppressedError/message-undefined-no-prop.js create mode 100644 test/language/statements/await-using/throws-if-initializer-not-object.js create mode 100644 test/language/statements/using/throws-if-initializer-not-object.js diff --git a/test/built-ins/AsyncDisposableStack/newtarget-prototype-is-not-object.js b/test/built-ins/AsyncDisposableStack/newtarget-prototype-is-not-object.js new file mode 100644 index 0000000000..f644a89e17 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/newtarget-prototype-is-not-object.js @@ -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'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/adopt/this-does-not-have-internal-asyncdisposablestate-throws.js b/test/built-ins/AsyncDisposableStack/prototype/adopt/this-does-not-have-internal-asyncdisposablestate-throws.js new file mode 100644 index 0000000000..91c89e8d32 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/adopt/this-does-not-have-internal-asyncdisposablestate-throws.js @@ -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'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/adopt/this-not-object-throws.js b/test/built-ins/AsyncDisposableStack/prototype/adopt/this-not-object-throws.js new file mode 100644 index 0000000000..43d78dcfde --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/adopt/this-not-object-throws.js @@ -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'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/defer/this-does-not-have-internal-asyncdisposablestate-throws.js b/test/built-ins/AsyncDisposableStack/prototype/defer/this-does-not-have-internal-asyncdisposablestate-throws.js new file mode 100644 index 0000000000..80b0674bcd --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/defer/this-does-not-have-internal-asyncdisposablestate-throws.js @@ -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'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/defer/this-not-object-throws.js b/test/built-ins/AsyncDisposableStack/prototype/defer/this-not-object-throws.js new file mode 100644 index 0000000000..cadb54018b --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/defer/this-not-object-throws.js @@ -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'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/disposeAsync/this-does-not-have-internal-asyncdisposablestate-rejects.js b/test/built-ins/AsyncDisposableStack/prototype/disposeAsync/this-does-not-have-internal-asyncdisposablestate-rejects.js new file mode 100644 index 0000000000..9a35ddbd31 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/disposeAsync/this-does-not-have-internal-asyncdisposablestate-rejects.js @@ -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'); +}); diff --git a/test/built-ins/AsyncDisposableStack/prototype/disposeAsync/this-not-object-rejects.js b/test/built-ins/AsyncDisposableStack/prototype/disposeAsync/this-not-object-rejects.js new file mode 100644 index 0000000000..af511ce59f --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/disposeAsync/this-not-object-rejects.js @@ -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'); +}); diff --git a/test/built-ins/AsyncDisposableStack/prototype/disposed/does-not-have-asyncdisposablestate-internal-slot.js b/test/built-ins/AsyncDisposableStack/prototype/disposed/does-not-have-asyncdisposablestate-internal-slot.js new file mode 100644 index 0000000000..8a8530904a --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/disposed/does-not-have-asyncdisposablestate-internal-slot.js @@ -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([]); +}); diff --git a/test/built-ins/AsyncDisposableStack/prototype/disposed/this-not-object-throw.js b/test/built-ins/AsyncDisposableStack/prototype/disposed/this-not-object-throw.js new file mode 100644 index 0000000000..1f0e058bd5 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/disposed/this-not-object-throw.js @@ -0,0 +1,50 @@ +// 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` is not an Object. +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. + ... + +features: [explicit-resource-management,Symbol] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(AsyncDisposableStack.prototype, 'disposed'); + +assert.throws(TypeError, function() { + descriptor.get.call(1); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(false); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(1); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(''); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(undefined); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(null); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(Symbol()); +}); diff --git a/test/built-ins/AsyncDisposableStack/prototype/move/this-does-not-have-internal-asyncdisposablestate-throws.js b/test/built-ins/AsyncDisposableStack/prototype/move/this-does-not-have-internal-asyncdisposablestate-throws.js new file mode 100644 index 0000000000..4d086ab547 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/move/this-does-not-have-internal-asyncdisposablestate-throws.js @@ -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.move +description: Throws a TypeError if this does not have a [[AsyncDisposableState]] internal slot +info: | + AsyncDisposableStack.prototype.move ( ) + + 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.move, 'function'); + +var move = AsyncDisposableStack.prototype.move; + +assert.throws(TypeError, function() { + move.call({ ['[[AsyncDisposableState]]']: {} }); +}, 'Ordinary object without [[AsyncDisposableState]]'); + +assert.throws(TypeError, function() { + move.call(AsyncDisposableStack.prototype); +}, 'AsyncDisposableStack.prototype does not have a [[AsyncDisposableState]] internal slot'); + +assert.throws(TypeError, function() { + move.call(AsyncDisposableStack); +}, 'AsyncDisposableStack does not have a [[AsyncDisposableState]] internal slot'); + +var stack = new DisposableStack(); +assert.throws(TypeError, function() { + move.call(stack); +}, 'DisposableStack instance'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/move/this-not-object-throws.js b/test/built-ins/AsyncDisposableStack/prototype/move/this-not-object-throws.js new file mode 100644 index 0000000000..0cdff69280 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/move/this-not-object-throws.js @@ -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.move +description: Throws a TypeError if this is not an Object +info: | + AsyncDisposableStack.prototype.move ( ) + + 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.move, 'function'); + +var move = AsyncDisposableStack.prototype.move; + +assert.throws(TypeError, function() { + move.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + move.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + move.call(true); +}, 'true'); + +assert.throws(TypeError, function() { + move.call(false); +}, 'false'); + +assert.throws(TypeError, function() { + move.call(1); +}, 'number'); + +assert.throws(TypeError, function() { + move.call('object'); +}, 'string'); + +var s = Symbol(); +assert.throws(TypeError, function() { + move.call(s); +}, 'symbol'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/use/this-does-not-have-internal-asyncdisposablestate-throws.js b/test/built-ins/AsyncDisposableStack/prototype/use/this-does-not-have-internal-asyncdisposablestate-throws.js new file mode 100644 index 0000000000..4ccb3262f6 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/use/this-does-not-have-internal-asyncdisposablestate-throws.js @@ -0,0 +1,44 @@ +// 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.use +description: Throws a TypeError if this does not have a [[AsyncDisposableState]] internal slot +info: | + AsyncDisposableStack.prototype.use ( value ) + + 1. Let asyncDisposableStack be the this value. + 2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]). + 3. If asyncDisposableStack.[[AsyncDisposableState]] is disposed, throw a ReferenceError exception. + 4. Perform ? AddDisposableResource(asyncDisposableStack.[[DisposeCapability]], value, sync-dispose). + 5. Return value. + + 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.use, 'function'); + +var use = AsyncDisposableStack.prototype.use; + +assert.throws(TypeError, function() { + use.call({ ['[[AsyncDisposableState]]']: {} }); +}, 'Ordinary object without [[AsyncDisposableState]]'); + +assert.throws(TypeError, function() { + use.call(AsyncDisposableStack.prototype); +}, 'AsyncDisposableStack.prototype does not have a [[AsyncDisposableState]] internal slot'); + +assert.throws(TypeError, function() { + use.call(AsyncDisposableStack); +}, 'AsyncDisposableStack does not have a [[AsyncDisposableState]] internal slot'); + +var stack = new DisposableStack(); +assert.throws(TypeError, function() { + use.call(stack); +}, 'DisposableStack instance'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/use/this-not-object-throws.js b/test/built-ins/AsyncDisposableStack/prototype/use/this-not-object-throws.js new file mode 100644 index 0000000000..fa541fd9ec --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/use/this-not-object-throws.js @@ -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.use +description: Throws a TypeError if this is not an Object +info: | + AsyncDisposableStack.prototype.use () + + 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.use, 'function'); + +var use = AsyncDisposableStack.prototype.use; + +assert.throws(TypeError, function() { + use.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + use.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + use.call(true); +}, 'true'); + +assert.throws(TypeError, function() { + use.call(false); +}, 'false'); + +assert.throws(TypeError, function() { + use.call(1); +}, 'number'); + +assert.throws(TypeError, function() { + use.call('object'); +}, 'string'); + +var s = Symbol(); +assert.throws(TypeError, function() { + use.call(s); +}, 'symbol'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/use/throws-if-value-not-object.js b/test/built-ins/AsyncDisposableStack/prototype/use/throws-if-value-not-object.js new file mode 100644 index 0000000000..e9232bd165 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/use/throws-if-value-not-object.js @@ -0,0 +1,48 @@ +// 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.use +description: Throws if the argument is not an object and is neither null nor undefined. +info: | + AsyncDisposableStack.prototype.use ( value ) + + 1. Let asyncDisposableStack be the this value. + 2. Perform ? RequireInternalSlot(asyncDisposableStack, [[DisposableState]]). + 3. If asyncDisposableStack.[[DisposableState]] is disposed, throw a ReferenceError exception. + 4. Perform ? AddDisposableResource(asyncDisposableStack.[[DisposeCapability]], value, async-dispose). + ... + + AddDisposableResource ( disposeCapability, V, hint [, method ] ) + + 1. If method is not present then, + a. If V is either null or undefined and hint is sync-dispose, then + i. Return unused + b. Let resource be ? CreateDisposableResource(V, hint). + ... + ... + +features: [explicit-resource-management] +---*/ + +var stack = new AsyncDisposableStack(); +assert.throws(TypeError, function() { + stack.use(true); +}, 'true'); + +assert.throws(TypeError, function() { + stack.use(false); +}, 'false'); + +assert.throws(TypeError, function() { + stack.use(1); +}, 'number'); + +assert.throws(TypeError, function() { + stack.use('object'); +}, 'string'); + +var s = Symbol(); +assert.throws(TypeError, function() { + stack.use(s); +}, 'symbol'); diff --git a/test/built-ins/DisposableStack/newtarget-prototype-is-not-object.js b/test/built-ins/DisposableStack/newtarget-prototype-is-not-object.js new file mode 100644 index 0000000000..658389b63d --- /dev/null +++ b/test/built-ins/DisposableStack/newtarget-prototype-is-not-object.js @@ -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-disposablestack +description: > + [[Prototype]] defaults to %DisposableStack.prototype% if NewTarget.prototype is not an object. +info: | + DisposableStack( target ) + + ... + 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, Reflect.construct, Symbol] +---*/ + +var stack; +function newTarget() {} + +newTarget.prototype = undefined; +stack = Reflect.construct(DisposableStack, [], newTarget); +assert.sameValue(Object.getPrototypeOf(stack), DisposableStack.prototype, 'newTarget.prototype is undefined'); + +newTarget.prototype = null; +stack = Reflect.construct(DisposableStack, [], newTarget); +assert.sameValue(Object.getPrototypeOf(stack), DisposableStack.prototype, 'newTarget.prototype is null'); + +newTarget.prototype = true; +stack = Reflect.construct(DisposableStack, [], newTarget); +assert.sameValue(Object.getPrototypeOf(stack), DisposableStack.prototype, 'newTarget.prototype is a Boolean'); + +newTarget.prototype = ''; +stack = Reflect.construct(DisposableStack, [], newTarget); +assert.sameValue(Object.getPrototypeOf(stack), DisposableStack.prototype, 'newTarget.prototype is a String'); + +newTarget.prototype = Symbol(); +stack = Reflect.construct(DisposableStack, [], newTarget); +assert.sameValue(Object.getPrototypeOf(stack), DisposableStack.prototype, 'newTarget.prototype is a Symbol'); + +newTarget.prototype = 1; +stack = Reflect.construct(DisposableStack, [], newTarget); +assert.sameValue(Object.getPrototypeOf(stack), DisposableStack.prototype, 'newTarget.prototype is a Number'); diff --git a/test/built-ins/DisposableStack/prototype/adopt/this-does-not-have-internal-disposablestate-throws.js b/test/built-ins/DisposableStack/prototype/adopt/this-does-not-have-internal-disposablestate-throws.js new file mode 100644 index 0000000000..9211fd67d5 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/adopt/this-does-not-have-internal-disposablestate-throws.js @@ -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-disposablestack.prototype.adopt +description: Throws a TypeError if this does not have a [[DisposableState]] internal slot +info: | + DisposableStack.prototype.adopt ( ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + 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 DisposableStack.prototype.adopt, 'function'); + +var adopt = DisposableStack.prototype.adopt; + +assert.throws(TypeError, function() { + adopt.call({ ['[[DisposableState]]']: {} }); +}, 'Ordinary object without [[DisposableState]]'); + +assert.throws(TypeError, function() { + adopt.call(DisposableStack.prototype); +}, 'DisposableStack.prototype does not have a [[DisposableState]] internal slot'); + +assert.throws(TypeError, function() { + adopt.call(DisposableStack); +}, 'DisposableStack does not have a [[DisposableState]] internal slot'); + +var asyncStack = new AsyncDisposableStack(function() {}); +assert.throws(TypeError, function() { + adopt.call(asyncStack); +}, 'AsyncDisposableStack instance'); diff --git a/test/built-ins/DisposableStack/prototype/adopt/this-not-object-throws.js b/test/built-ins/DisposableStack/prototype/adopt/this-not-object-throws.js new file mode 100644 index 0000000000..d375b61af9 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/adopt/this-not-object-throws.js @@ -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-disposablestack.prototype.adopt +description: Throws a TypeError if this is not an Object +info: | + DisposableStack.prototype.adopt ( ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + ... + + RequireInternalSlot ( O, internalSlot ) + + 1. If O is not an Object, throw a TypeError exception. + ... + +features: [explicit-resource-management] +---*/ + +assert.sameValue(typeof DisposableStack.prototype.adopt, 'function'); + +var adopt = DisposableStack.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'); diff --git a/test/built-ins/DisposableStack/prototype/defer/this-does-not-have-internal-disposablestate-throws.js b/test/built-ins/DisposableStack/prototype/defer/this-does-not-have-internal-disposablestate-throws.js new file mode 100644 index 0000000000..74d38d49e2 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/defer/this-does-not-have-internal-disposablestate-throws.js @@ -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-disposablestack.prototype.defer +description: Throws a TypeError if this does not have a [[DisposableState]] internal slot +info: | + DisposableStack.prototype.defer ( ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + 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 DisposableStack.prototype.defer, 'function'); + +var defer = DisposableStack.prototype.defer; + +assert.throws(TypeError, function() { + defer.call({ ['[[DisposableState]]']: {} }); +}, 'Ordinary object without [[DisposableState]]'); + +assert.throws(TypeError, function() { + defer.call(DisposableStack.prototype); +}, 'DisposableStack.prototype does not have a [[DisposableState]] internal slot'); + +assert.throws(TypeError, function() { + defer.call(DisposableStack); +}, 'DisposableStack does not have a [[DisposableState]] internal slot'); + +var asyncStack = new AsyncDisposableStack(function() {}); +assert.throws(TypeError, function() { + defer.call(asyncStack); +}, 'AsyncDisposableStack instance'); diff --git a/test/built-ins/DisposableStack/prototype/defer/this-not-object-throws.js b/test/built-ins/DisposableStack/prototype/defer/this-not-object-throws.js new file mode 100644 index 0000000000..b02065bc07 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/defer/this-not-object-throws.js @@ -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-disposablestack.prototype.defer +description: Throws a TypeError if this is not an Object +info: | + DisposableStack.prototype.defer ( ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + ... + + RequireInternalSlot ( O, internalSlot ) + + 1. If O is not an Object, throw a TypeError exception. + ... + +features: [explicit-resource-management] +---*/ + +assert.sameValue(typeof DisposableStack.prototype.defer, 'function'); + +var defer = DisposableStack.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'); diff --git a/test/built-ins/DisposableStack/prototype/dispose/this-does-not-have-internal-disposablestate-throws.js b/test/built-ins/DisposableStack/prototype/dispose/this-does-not-have-internal-disposablestate-throws.js new file mode 100644 index 0000000000..8231e7296d --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/dispose/this-does-not-have-internal-disposablestate-throws.js @@ -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-disposablestack.prototype.dispose +description: Throws a TypeError if this does not have a [[DisposableState]] internal slot +info: | + DisposableStack.prototype.dispose ( ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + 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 DisposableStack.prototype.dispose, 'function'); + +var dispose = DisposableStack.prototype.dispose; + +assert.throws(TypeError, function() { + dispose.call({ ['[[DisposableState]]']: {} }); +}, 'Ordinary object without [[DisposableState]]'); + +assert.throws(TypeError, function() { + dispose.call(DisposableStack.prototype); +}, 'DisposableStack.prototype does not have a [[DisposableState]] internal slot'); + +assert.throws(TypeError, function() { + dispose.call(DisposableStack); +}, 'DisposableStack does not have a [[DisposableState]] internal slot'); + +var asyncStack = new AsyncDisposableStack(function() {}); +assert.throws(TypeError, function() { + dispose.call(asyncStack); +}, 'AsyncDisposableStack instance'); diff --git a/test/built-ins/DisposableStack/prototype/dispose/this-not-object-throws.js b/test/built-ins/DisposableStack/prototype/dispose/this-not-object-throws.js new file mode 100644 index 0000000000..3b966acb0e --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/dispose/this-not-object-throws.js @@ -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-disposablestack.prototype.dispose +description: Throws a TypeError if this is not an Object +info: | + DisposableStack.prototype.dispose ( ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + ... + + RequireInternalSlot ( O, internalSlot ) + + 1. If O is not an Object, throw a TypeError exception. + ... + +features: [explicit-resource-management] +---*/ + +assert.sameValue(typeof DisposableStack.prototype.dispose, 'function'); + +var dispose = DisposableStack.prototype.dispose; + +assert.throws(TypeError, function() { + dispose.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + dispose.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + dispose.call(true); +}, 'true'); + +assert.throws(TypeError, function() { + dispose.call(false); +}, 'false'); + +assert.throws(TypeError, function() { + dispose.call(1); +}, 'number'); + +assert.throws(TypeError, function() { + dispose.call('object'); +}, 'string'); + +var s = Symbol(); +assert.throws(TypeError, function() { + dispose.call(s); +}, 'symbol'); diff --git a/test/built-ins/DisposableStack/prototype/disposed/does-not-have-disposablestate-internal-slot.js b/test/built-ins/DisposableStack/prototype/disposed/does-not-have-disposablestate-internal-slot.js new file mode 100644 index 0000000000..aee0e3f398 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/disposed/does-not-have-disposablestate-internal-slot.js @@ -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: > + Throws a TypeError if `this` object does not have a [[DisposableState]] internal slot. +info: | + get DisposableStack.prototype.disposed + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + ... + + 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(DisposableStack.prototype, 'disposed'); + +var stack = new DisposableStack(); + +// Does not throw +descriptor.get.call(stack); + +assert.throws(TypeError, function() { + descriptor.get.call([]); +}); diff --git a/test/built-ins/DisposableStack/prototype/disposed/this-not-object-throw.js b/test/built-ins/DisposableStack/prototype/disposed/this-not-object-throw.js new file mode 100644 index 0000000000..d185b77396 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/disposed/this-not-object-throw.js @@ -0,0 +1,50 @@ +// 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: > + Throws a TypeError if `this` is not an Object. +info: | + get DisposableStack.prototype.disposed + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + ... + + RequireInternalSlot ( O, internalSlot ) + + 1. If O is not an Object, throw a TypeError exception. + ... + +features: [explicit-resource-management,Symbol] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(DisposableStack.prototype, 'disposed'); + +assert.throws(TypeError, function() { + descriptor.get.call(1); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(false); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(1); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(''); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(undefined); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(null); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(Symbol()); +}); diff --git a/test/built-ins/DisposableStack/prototype/move/this-does-not-have-internal-disposablestate-throws.js b/test/built-ins/DisposableStack/prototype/move/this-does-not-have-internal-disposablestate-throws.js new file mode 100644 index 0000000000..b39d507952 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/move/this-does-not-have-internal-disposablestate-throws.js @@ -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-disposablestack.prototype.move +description: Throws a TypeError if this does not have a [[DisposableState]] internal slot +info: | + DisposableStack.prototype.move ( ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + 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 DisposableStack.prototype.move, 'function'); + +var move = DisposableStack.prototype.move; + +assert.throws(TypeError, function() { + move.call({ ['[[DisposableState]]']: {} }); +}, 'Ordinary object without [[DisposableState]]'); + +assert.throws(TypeError, function() { + move.call(DisposableStack.prototype); +}, 'DisposableStack.prototype does not have a [[DisposableState]] internal slot'); + +assert.throws(TypeError, function() { + move.call(DisposableStack); +}, 'DisposableStack does not have a [[DisposableState]] internal slot'); + +var asyncStack = new AsyncDisposableStack(); +assert.throws(TypeError, function() { + move.call(asyncStack); +}, 'AsyncDisposableStack instance'); diff --git a/test/built-ins/DisposableStack/prototype/move/this-not-object-throws.js b/test/built-ins/DisposableStack/prototype/move/this-not-object-throws.js new file mode 100644 index 0000000000..973f7f0177 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/move/this-not-object-throws.js @@ -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-disposablestack.prototype.move +description: Throws a TypeError if this is not an Object +info: | + DisposableStack.prototype.move ( ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + ... + + RequireInternalSlot ( O, internalSlot ) + + 1. If O is not an Object, throw a TypeError exception. + ... + +features: [explicit-resource-management] +---*/ + +assert.sameValue(typeof DisposableStack.prototype.move, 'function'); + +var move = DisposableStack.prototype.move; + +assert.throws(TypeError, function() { + move.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + move.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + move.call(true); +}, 'true'); + +assert.throws(TypeError, function() { + move.call(false); +}, 'false'); + +assert.throws(TypeError, function() { + move.call(1); +}, 'number'); + +assert.throws(TypeError, function() { + move.call('object'); +}, 'string'); + +var s = Symbol(); +assert.throws(TypeError, function() { + move.call(s); +}, 'symbol'); diff --git a/test/built-ins/DisposableStack/prototype/use/this-does-not-have-internal-disposablestate-throws.js b/test/built-ins/DisposableStack/prototype/use/this-does-not-have-internal-disposablestate-throws.js new file mode 100644 index 0000000000..01283c7b61 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/use/this-does-not-have-internal-disposablestate-throws.js @@ -0,0 +1,44 @@ +// 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.use +description: Throws a TypeError if this does not have a [[DisposableState]] internal slot +info: | + DisposableStack.prototype.use ( value ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + 3. If disposableStack.[[DisposableState]] is disposed, throw a ReferenceError exception. + 4. Perform ? AddDisposableResource(disposableStack.[[DisposeCapability]], value, sync-dispose). + 5. Return value. + + 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 DisposableStack.prototype.use, 'function'); + +var use = DisposableStack.prototype.use; + +assert.throws(TypeError, function() { + use.call({ ['[[DisposableState]]']: {} }); +}, 'Ordinary object without [[DisposableState]]'); + +assert.throws(TypeError, function() { + use.call(DisposableStack.prototype); +}, 'DisposableStack.prototype does not have a [[DisposableState]] internal slot'); + +assert.throws(TypeError, function() { + use.call(DisposableStack); +}, 'DisposableStack does not have a [[DisposableState]] internal slot'); + +var asyncStack = new AsyncDisposableStack(function() {}); +assert.throws(TypeError, function() { + use.call(asyncStack); +}, 'AsyncDisposableStack instance'); diff --git a/test/built-ins/DisposableStack/prototype/use/this-not-object-throws.js b/test/built-ins/DisposableStack/prototype/use/this-not-object-throws.js new file mode 100644 index 0000000000..cf960789ab --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/use/this-not-object-throws.js @@ -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-disposablestack.prototype.use +description: Throws a TypeError if this is not an Object +info: | + DisposableStack.prototype.use ( value ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + ... + + RequireInternalSlot ( O, internalSlot ) + + 1. If O is not an Object, throw a TypeError exception. + ... + +features: [explicit-resource-management] +---*/ + +assert.sameValue(typeof DisposableStack.prototype.use, 'function'); + +var use = DisposableStack.prototype.use; + +assert.throws(TypeError, function() { + use.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + use.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + use.call(true); +}, 'true'); + +assert.throws(TypeError, function() { + use.call(false); +}, 'false'); + +assert.throws(TypeError, function() { + use.call(1); +}, 'number'); + +assert.throws(TypeError, function() { + use.call('object'); +}, 'string'); + +var s = Symbol(); +assert.throws(TypeError, function() { + use.call(s); +}, 'symbol'); diff --git a/test/built-ins/DisposableStack/prototype/use/throws-if-value-not-object.js b/test/built-ins/DisposableStack/prototype/use/throws-if-value-not-object.js new file mode 100644 index 0000000000..84836a6315 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/use/throws-if-value-not-object.js @@ -0,0 +1,48 @@ +// 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.use +description: Throws if the argument is not an object and is neither null nor undefined. +info: | + DisposableStack.prototype.use ( value ) + + 1. Let disposableStack be the this value. + 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). + 3. If disposableStack.[[DisposableState]] is disposed, throw a ReferenceError exception. + 4. Perform ? AddDisposableResource(disposableStack.[[DisposeCapability]], value, sync-dispose). + ... + + AddDisposableResource ( disposeCapability, V, hint [, method ] ) + + 1. If method is not present then, + a. If V is either null or undefined and hint is sync-dispose, then + i. Return unused + b. Let resource be ? CreateDisposableResource(V, hint). + ... + ... + +features: [explicit-resource-management] +---*/ + +var stack = new DisposableStack(); +assert.throws(TypeError, function() { + stack.use(true); +}, 'true'); + +assert.throws(TypeError, function() { + stack.use(false); +}, 'false'); + +assert.throws(TypeError, function() { + stack.use(1); +}, 'number'); + +assert.throws(TypeError, function() { + stack.use('object'); +}, 'string'); + +var s = Symbol(); +assert.throws(TypeError, function() { + stack.use(s); +}, 'symbol'); diff --git a/test/built-ins/NativeErrors/SuppressedError/message-undefined-no-prop.js b/test/built-ins/NativeErrors/SuppressedError/message-undefined-no-prop.js new file mode 100644 index 0000000000..7d5bd40003 --- /dev/null +++ b/test/built-ins/NativeErrors/SuppressedError/message-undefined-no-prop.js @@ -0,0 +1,33 @@ +// 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: > + If message is undefined, no property will be set to the new instance +info: | + SuppressedError ( error, suppressed, message ) + + ... + 5. If message is not undefined, then + a. Let msg be ? ToString(message). + b. Perform ! CreateMethodProperty(O, "message", msg). + 6. Return O. +features: [explicit-resource-management] +---*/ + +var case1 = new SuppressedError(undefined, undefined, undefined); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(case1, 'message'), + false, + 'explicit' +); + +var case2 = new SuppressedError([]); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(case2, 'message'), + false, + 'implicit' +); diff --git a/test/language/statements/await-using/throws-if-initializer-not-object.js b/test/language/statements/await-using/throws-if-initializer-not-object.js new file mode 100644 index 0000000000..c669a8e6c2 --- /dev/null +++ b/test/language/statements/await-using/throws-if-initializer-not-object.js @@ -0,0 +1,75 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +description: Throws if initialized value is not an Object +info: | + RS: Evaluation + AwaitUsingDeclaration : CoverAwaitExpressionAndAwaitUsingDeclarationHead BindingList ; + + 1. Perform ? BindingEvaluation of BindingList with argument async-dispose. + 2. Return empty. + + RS: BindingEvaluation + LexicalBinding : BindingIdentifier Initializer + + ... + 5. Return ? InitializeReferencedBinding(lhs, value, hint). + + InitializeReferencedBinding ( V, W ) + + ... + 4. Return ? base.InitializeBinding(V.[[ReferencedName]], W). + + InitializeBinding ( N, V, hint ) + + ... + 2. If hint is not normal, perform ? AddDisposableResource(envRec.[[DisposeCapability]], V, hint). + ... + + AddDisposableResource ( disposeCapability, V, hint [, method ] ) + + 1. If method is not present then, + a. If V is either null or undefined and hint is sync-dispose, then + i. Return unused. + b. Let resource be ? CreateDisposableResource(V, hint). + ... + + CreateDisposableResource ( V, hint [ , method ] ) + + 1. If method is not present, then + a. If V is either null or undefined, then + ... + b. Else, + i. If V is not an Object, throw a TypeError exception. + ... + ... + +flags: [async] +includes: [asyncHelpers.js] +features: [explicit-resource-management] +---*/ + +asyncTest(async function () { + await assert.throwsAsync(TypeError, async function() { + await using x = true; + }, 'true'); + + await assert.throwsAsync(TypeError, async function() { + await using x = false; + }, 'false'); + + await assert.throwsAsync(TypeError, async function() { + await using x = 1; + }, 'number'); + + await assert.throwsAsync(TypeError, async function() { + await using x = 'object'; + }, 'string'); + + var s = Symbol(); + await assert.throwsAsync(TypeError, async function() { + await using x = s; + }, 'symbol'); +}); diff --git a/test/language/statements/using/throws-if-initializer-not-object.js b/test/language/statements/using/throws-if-initializer-not-object.js new file mode 100644 index 0000000000..d3934e8016 --- /dev/null +++ b/test/language/statements/using/throws-if-initializer-not-object.js @@ -0,0 +1,71 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +description: Throws if initialized value is not an Object +info: | + RS: Evaluation + UsingDeclaration : using BindingList ; + + 1. Perform ? BindingEvaluation of BindingList with argument sync-dispose. + 2. Return empty. + + RS: BindingEvaluation + LexicalBinding : BindingIdentifier Initializer + + ... + 5. Return ? InitializeReferencedBinding(lhs, value, hint). + + InitializeReferencedBinding ( V, W ) + + ... + 4. Return ? base.InitializeBinding(V.[[ReferencedName]], W). + + InitializeBinding ( N, V, hint ) + + ... + 2. If hint is not normal, perform ? AddDisposableResource(envRec.[[DisposeCapability]], V, hint). + ... + + AddDisposableResource ( disposeCapability, V, hint [, method ] ) + + 1. If method is not present then, + a. If V is either null or undefined and hint is sync-dispose, then + i. Return unused. + b. Let resource be ? CreateDisposableResource(V, hint). + ... + + CreateDisposableResource ( V, hint [ , method ] ) + + 1. If method is not present, then + a. If V is either null or undefined, then + ... + b. Else, + i. If V is not an Object, throw a TypeError exception. + ... + ... + +features: [explicit-resource-management] +---*/ + +assert.throws(TypeError, function() { + using x = true; +}, 'true'); + +assert.throws(TypeError, function() { + using x = false; +}, 'false'); + +assert.throws(TypeError, function() { + using x = 1; +}, 'number'); + +assert.throws(TypeError, function() { + using x = 'object'; +}, 'string'); + +var s = Symbol(); +assert.throws(TypeError, function() { + using x = s; +}, 'symbol');