Skip to content

Commit

Permalink
Adds [is/not]-a-constructor.js tests from @rbuckton's PR #3866
Browse files Browse the repository at this point in the history
to make reviewing easier.
  • Loading branch information
rbuckton authored and ptomato committed Jul 29, 2024
1 parent c916d81 commit cb8324f
Show file tree
Hide file tree
Showing 13 changed files with 390 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/built-ins/AsyncDisposableStack/is-a-constructor.js
Original file line number Diff line number Diff line change
@@ -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();
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-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');
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-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');
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-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');
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-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');
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-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');
23 changes: 23 additions & 0 deletions test/built-ins/DisposableStack/is-a-constructor.js
Original file line number Diff line number Diff line change
@@ -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();
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-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');
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-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');
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-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');
32 changes: 32 additions & 0 deletions test/built-ins/DisposableStack/prototype/move/not-a-constructor.js
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-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');
32 changes: 32 additions & 0 deletions test/built-ins/DisposableStack/prototype/use/not-a-constructor.js
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-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');
Loading

0 comments on commit cb8324f

Please sign in to comment.