From b84f3c0fb5e4a37536a79348112596fe8a632366 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 29 Jul 2024 21:02:38 +0200 Subject: [PATCH] Adds [is/not]-a-constructor.js tests from @rbuckton's PR #3866 to make reviewing easier. --- .../AsyncDisposableStack/is-a-constructor.js | 23 +++++++++++++ .../prototype/adopt/not-a-constructor.js | 32 +++++++++++++++++++ .../prototype/defer/not-a-constructor.js | 32 +++++++++++++++++++ .../disposeAsync/not-a-constructor.js | 32 +++++++++++++++++++ .../prototype/move/not-a-constructor.js | 32 +++++++++++++++++++ .../prototype/use/not-a-constructor.js | 32 +++++++++++++++++++ .../DisposableStack/is-a-constructor.js | 23 +++++++++++++ .../prototype/adopt/not-a-constructor.js | 32 +++++++++++++++++++ .../prototype/defer/not-a-constructor.js | 32 +++++++++++++++++++ .../prototype/dispose/not-a-constructor.js | 32 +++++++++++++++++++ .../prototype/move/not-a-constructor.js | 32 +++++++++++++++++++ .../prototype/use/not-a-constructor.js | 32 +++++++++++++++++++ .../SuppressedError/is-a-constructor.js | 24 ++++++++++++++ 13 files changed, 390 insertions(+) create mode 100644 test/built-ins/AsyncDisposableStack/is-a-constructor.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/adopt/not-a-constructor.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/defer/not-a-constructor.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/disposeAsync/not-a-constructor.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/move/not-a-constructor.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype/use/not-a-constructor.js create mode 100644 test/built-ins/DisposableStack/is-a-constructor.js create mode 100644 test/built-ins/DisposableStack/prototype/adopt/not-a-constructor.js create mode 100644 test/built-ins/DisposableStack/prototype/defer/not-a-constructor.js create mode 100644 test/built-ins/DisposableStack/prototype/dispose/not-a-constructor.js create mode 100644 test/built-ins/DisposableStack/prototype/move/not-a-constructor.js create mode 100644 test/built-ins/DisposableStack/prototype/use/not-a-constructor.js create mode 100644 test/built-ins/NativeErrors/SuppressedError/is-a-constructor.js diff --git a/test/built-ins/AsyncDisposableStack/is-a-constructor.js b/test/built-ins/AsyncDisposableStack/is-a-constructor.js new file mode 100644 index 00000000000..7c34ccfd7a3 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/is-a-constructor.js @@ -0,0 +1,23 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The AsyncDisposableStack constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [explicit-resource-management, Reflect.construct] +---*/ + +assert.sameValue(isConstructor(AsyncDisposableStack), true, 'isConstructor(AsyncDisposableStack) must return true'); +new AsyncDisposableStack(); diff --git a/test/built-ins/AsyncDisposableStack/prototype/adopt/not-a-constructor.js b/test/built-ins/AsyncDisposableStack/prototype/adopt/not-a-constructor.js new file mode 100644 index 00000000000..4624f8651a8 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/adopt/not-a-constructor.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-asyncdisposablestack.prototype.adopt +description: > + AsyncDisposableStack.prototype.adopt does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management, arrow-function] +---*/ + +assert.sameValue( + isConstructor(AsyncDisposableStack.prototype.adopt), + false, + 'isConstructor(AsyncDisposableStack.prototype.adopt) must return false' +); + +assert.throws(TypeError, () => { + let stack = new AsyncDisposableStack({}); new stack.adopt(); +}, '`let stack = new AsyncDisposableStack({}); new stack.adopt()` throws TypeError'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/defer/not-a-constructor.js b/test/built-ins/AsyncDisposableStack/prototype/defer/not-a-constructor.js new file mode 100644 index 00000000000..e1f2c8539ea --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/defer/not-a-constructor.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-asyncdisposablestack.prototype.defer +description: > + AsyncDisposableStack.prototype.defer does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management, arrow-function] +---*/ + +assert.sameValue( + isConstructor(AsyncDisposableStack.prototype.defer), + false, + 'isConstructor(AsyncDisposableStack.prototype.defer) must return false' +); + +assert.throws(TypeError, () => { + let stack = new AsyncDisposableStack({}); new stack.defer(); +}, '`let stack = new AsyncDisposableStack({}); new stack.defer()` throws TypeError'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/disposeAsync/not-a-constructor.js b/test/built-ins/AsyncDisposableStack/prototype/disposeAsync/not-a-constructor.js new file mode 100644 index 00000000000..8b56fb29cf6 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/disposeAsync/not-a-constructor.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-asyncdisposablestack.prototype.disposeAsync +description: > + AsyncDisposableStack.prototype.disposeAsync does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management, arrow-function] +---*/ + +assert.sameValue( + isConstructor(AsyncDisposableStack.prototype.disposeAsync), + false, + 'isConstructor(AsyncDisposableStack.prototype.disposeAsync) must return false' +); + +assert.throws(TypeError, () => { + let stack = new AsyncDisposableStack({}); new stack.disposeAsync(); +}, '`let stack = new AsyncDisposableStack({}); new stack.disposeAsync()` throws TypeError'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/move/not-a-constructor.js b/test/built-ins/AsyncDisposableStack/prototype/move/not-a-constructor.js new file mode 100644 index 00000000000..5d7b0d97fd0 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/move/not-a-constructor.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-asyncdisposablestack.prototype.move +description: > + AsyncDisposableStack.prototype.move does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management, arrow-function] +---*/ + +assert.sameValue( + isConstructor(AsyncDisposableStack.prototype.move), + false, + 'isConstructor(AsyncDisposableStack.prototype.move) must return false' +); + +assert.throws(TypeError, () => { + let stack = new AsyncDisposableStack({}); new stack.move(); +}, '`let stack = new AsyncDisposableStack({}); new stack.move()` throws TypeError'); diff --git a/test/built-ins/AsyncDisposableStack/prototype/use/not-a-constructor.js b/test/built-ins/AsyncDisposableStack/prototype/use/not-a-constructor.js new file mode 100644 index 00000000000..e407a9aa812 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype/use/not-a-constructor.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-asyncdisposablestack.prototype.use +description: > + AsyncDisposableStack.prototype.use does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management, arrow-function] +---*/ + +assert.sameValue( + isConstructor(AsyncDisposableStack.prototype.use), + false, + 'isConstructor(AsyncDisposableStack.prototype.use) must return false' +); + +assert.throws(TypeError, () => { + let stack = new AsyncDisposableStack({}); new stack.use(); +}, '`let stack = new AsyncDisposableStack({}); new stack.use()` throws TypeError'); diff --git a/test/built-ins/DisposableStack/is-a-constructor.js b/test/built-ins/DisposableStack/is-a-constructor.js new file mode 100644 index 00000000000..01b4ec9c906 --- /dev/null +++ b/test/built-ins/DisposableStack/is-a-constructor.js @@ -0,0 +1,23 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The DisposableStack constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [explicit-resource-management, Reflect.construct] +---*/ + +assert.sameValue(isConstructor(DisposableStack), true, 'isConstructor(DisposableStack) must return true'); +new DisposableStack(); diff --git a/test/built-ins/DisposableStack/prototype/adopt/not-a-constructor.js b/test/built-ins/DisposableStack/prototype/adopt/not-a-constructor.js new file mode 100644 index 00000000000..f958f5028d0 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/adopt/not-a-constructor.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-disposablestack.prototype.adopt +description: > + DisposableStack.prototype.adopt does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management, arrow-function] +---*/ + +assert.sameValue( + isConstructor(DisposableStack.prototype.adopt), + false, + 'isConstructor(DisposableStack.prototype.adopt) must return false' +); + +assert.throws(TypeError, () => { + let stack = new DisposableStack({}); new stack.adopt(); +}, '`let stack = new DisposableStack({}); new stack.adopt()` throws TypeError'); diff --git a/test/built-ins/DisposableStack/prototype/defer/not-a-constructor.js b/test/built-ins/DisposableStack/prototype/defer/not-a-constructor.js new file mode 100644 index 00000000000..cbb41f33568 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/defer/not-a-constructor.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-disposablestack.prototype.defer +description: > + DisposableStack.prototype.defer does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management, arrow-function] +---*/ + +assert.sameValue( + isConstructor(DisposableStack.prototype.defer), + false, + 'isConstructor(DisposableStack.prototype.defer) must return false' +); + +assert.throws(TypeError, () => { + let stack = new DisposableStack({}); new stack.defer(); +}, '`let stack = new DisposableStack({}); new stack.defer()` throws TypeError'); diff --git a/test/built-ins/DisposableStack/prototype/dispose/not-a-constructor.js b/test/built-ins/DisposableStack/prototype/dispose/not-a-constructor.js new file mode 100644 index 00000000000..c71599ad367 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/dispose/not-a-constructor.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-disposablestack.prototype.dispose +description: > + DisposableStack.prototype.dispose does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management, arrow-function] +---*/ + +assert.sameValue( + isConstructor(DisposableStack.prototype.dispose), + false, + 'isConstructor(DisposableStack.prototype.dispose) must return false' +); + +assert.throws(TypeError, () => { + let stack = new DisposableStack({}); new stack.dispose(); +}, '`let stack = new DisposableStack({}); new stack.dispose()` throws TypeError'); diff --git a/test/built-ins/DisposableStack/prototype/move/not-a-constructor.js b/test/built-ins/DisposableStack/prototype/move/not-a-constructor.js new file mode 100644 index 00000000000..93490d98d48 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/move/not-a-constructor.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-disposablestack.prototype.move +description: > + DisposableStack.prototype.move does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management, arrow-function] +---*/ + +assert.sameValue( + isConstructor(DisposableStack.prototype.move), + false, + 'isConstructor(DisposableStack.prototype.move) must return false' +); + +assert.throws(TypeError, () => { + let stack = new DisposableStack({}); new stack.move(); +}, '`let stack = new DisposableStack({}); new stack.move()` throws TypeError'); diff --git a/test/built-ins/DisposableStack/prototype/use/not-a-constructor.js b/test/built-ins/DisposableStack/prototype/use/not-a-constructor.js new file mode 100644 index 00000000000..67dbdae4153 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype/use/not-a-constructor.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-disposablestack.prototype.use +description: > + DisposableStack.prototype.use does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management, arrow-function] +---*/ + +assert.sameValue( + isConstructor(DisposableStack.prototype.use), + false, + 'isConstructor(DisposableStack.prototype.use) must return false' +); + +assert.throws(TypeError, () => { + let stack = new DisposableStack({}); new stack.use(); +}, '`let stack = new DisposableStack({}); new stack.use()` throws TypeError'); diff --git a/test/built-ins/NativeErrors/SuppressedError/is-a-constructor.js b/test/built-ins/NativeErrors/SuppressedError/is-a-constructor.js new file mode 100644 index 00000000000..5afd11d1e19 --- /dev/null +++ b/test/built-ins/NativeErrors/SuppressedError/is-a-constructor.js @@ -0,0 +1,24 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The SuppressedError constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, explicit-resource-management] +---*/ + +assert.sameValue(isConstructor(SuppressedError), true, 'isConstructor(SuppressedError) must return true'); +new SuppressedError(); +