From 1438a4ca7bf43116a24903952d3a91c6545c2bde Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 30 Jan 2025 23:13:07 +0530 Subject: [PATCH 1/2] Basic constructor and newtarget tests for AsyncDisposableStack --- .../AsyncDisposableStack/constructor.js | 15 +++++++ .../prototype-from-newtarget-abrupt.js | 42 +++++++++++++++++ .../prototype-from-newtarget-custom.js | 45 +++++++++++++++++++ .../prototype-from-newtarget.js | 34 ++++++++++++++ .../undefined-newtarget-throws.js | 18 ++++++++ 5 files changed, 154 insertions(+) create mode 100644 test/built-ins/AsyncDisposableStack/constructor.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype-from-newtarget-abrupt.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype-from-newtarget-custom.js create mode 100644 test/built-ins/AsyncDisposableStack/prototype-from-newtarget.js create mode 100644 test/built-ins/AsyncDisposableStack/undefined-newtarget-throws.js diff --git a/test/built-ins/AsyncDisposableStack/constructor.js b/test/built-ins/AsyncDisposableStack/constructor.js new file mode 100644 index 00000000000..6e429796761 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/constructor.js @@ -0,0 +1,15 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncdisposablestack-constructor +description: > + The AsyncDisposableStack constructor is the %AsyncDisposableStack% intrinsic object and the initial + value of the AsyncDisposableStack property of the global object. +features: [explicit-resource-management] +---*/ + +assert.sameValue( + typeof AsyncDisposableStack, 'function', + 'typeof AsyncDisposableStack is function' +); diff --git a/test/built-ins/AsyncDisposableStack/prototype-from-newtarget-abrupt.js b/test/built-ins/AsyncDisposableStack/prototype-from-newtarget-abrupt.js new file mode 100644 index 00000000000..cde62713622 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype-from-newtarget-abrupt.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 +description: > + Return abrupt from getting the NewTarget prototype +info: | + AsyncDisposableStack ( ) + + ... + 2. Let asyncDisposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncDisposableStack.prototype%", « [[AsyncDisposableState]], [[DisposeCapability]] »). + 3. Set asyncDisposableStack.[[AsyncDisposableState]] to pending. + 4. Set asyncDisposableStack.[[DisposeCapability]] to NewDisposeCapability(). + 5. Return asyncDisposableStack. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + 3. Let proto be ? Get(constructor, 'prototype'). +features: [explicit-resource-management, Reflect.construct] +---*/ + +var calls = 0; +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, 'prototype', { + get: function() { + calls += 1; + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.construct(AsyncDisposableStack, [], newTarget); +}); + +assert.sameValue(calls, 1); diff --git a/test/built-ins/AsyncDisposableStack/prototype-from-newtarget-custom.js b/test/built-ins/AsyncDisposableStack/prototype-from-newtarget-custom.js new file mode 100644 index 00000000000..95351ba6bca --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype-from-newtarget-custom.js @@ -0,0 +1,45 @@ +// 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: > + The [[Prototype]] internal slot is computed from NewTarget. +info: | + AsyncDisposableStack ( ) + + ... + 2. Let asyncDisposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncDisposableStack.prototype%", « [[AsyncDisposableState]], [[DisposeCapability]] »). + 3. Set asyncDisposableStack.[[AsyncDisposableState]] to pending. + 4. Set asyncDisposableStack.[[DisposeCapability]] to NewDisposeCapability(). + 5. Return asyncDisposableStack. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + 3. Let proto be ? Get(constructor, 'prototype'). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [explicit-resource-management, Reflect.construct] +---*/ + +var stack; + +stack = Reflect.construct(AsyncDisposableStack, [], Object); +assert.sameValue(Object.getPrototypeOf(stack), Object.prototype, 'NewTarget is built-in Object constructor'); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, 'prototype', { + get: function() { + return Array.prototype; + } +}); +stack = Reflect.construct(AsyncDisposableStack, [], newTarget); +assert.sameValue(Object.getPrototypeOf(stack), Array.prototype, 'NewTarget is BoundFunction with accessor'); diff --git a/test/built-ins/AsyncDisposableStack/prototype-from-newtarget.js b/test/built-ins/AsyncDisposableStack/prototype-from-newtarget.js new file mode 100644 index 00000000000..47c937f8276 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/prototype-from-newtarget.js @@ -0,0 +1,34 @@ +// 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: > + The [[Prototype]] internal slot is computed from NewTarget. +info: | + AsyncDisposableStack ( ) + + ... + 2. Let asyncDisposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncDisposableStack.prototype%", « [[AsyncDisposableState]], [[DisposeCapability]] »). + 3. Set asyncDisposableStack.[[AsyncDisposableState]] to pending. + 4. Set asyncDisposableStack.[[DisposeCapability]] to NewDisposeCapability(). + 5. Return asyncDisposableStack. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + 3. Let proto be ? Get(constructor, 'prototype'). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [explicit-resource-management] +---*/ + +var stack = new AsyncDisposableStack(); +assert.sameValue(Object.getPrototypeOf(stack), AsyncDisposableStack.prototype); diff --git a/test/built-ins/AsyncDisposableStack/undefined-newtarget-throws.js b/test/built-ins/AsyncDisposableStack/undefined-newtarget-throws.js new file mode 100644 index 00000000000..e2349c84d97 --- /dev/null +++ b/test/built-ins/AsyncDisposableStack/undefined-newtarget-throws.js @@ -0,0 +1,18 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncdisposablestack +description: > + Throws a TypeError if NewTarget is undefined. +info: | + AsyncDisposableStack ( ) + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +features: [explicit-resource-management] +---*/ + +assert.throws(TypeError, function() { + AsyncDisposableStack(); +}); From 9daeec97130d5bb05553a1f0d6a6bc5ce211c894 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 30 Jan 2025 23:16:51 +0530 Subject: [PATCH 2/2] Basic constructor and newtarget tests for DisposableStack --- test/built-ins/DisposableStack/constructor.js | 15 +++++++ .../prototype-from-newtarget-abrupt.js | 42 +++++++++++++++++ .../prototype-from-newtarget-custom.js | 45 +++++++++++++++++++ .../prototype-from-newtarget.js | 34 ++++++++++++++ .../undefined-newtarget-throws.js | 18 ++++++++ 5 files changed, 154 insertions(+) create mode 100644 test/built-ins/DisposableStack/constructor.js create mode 100644 test/built-ins/DisposableStack/prototype-from-newtarget-abrupt.js create mode 100644 test/built-ins/DisposableStack/prototype-from-newtarget-custom.js create mode 100644 test/built-ins/DisposableStack/prototype-from-newtarget.js create mode 100644 test/built-ins/DisposableStack/undefined-newtarget-throws.js diff --git a/test/built-ins/DisposableStack/constructor.js b/test/built-ins/DisposableStack/constructor.js new file mode 100644 index 00000000000..4a314ed084f --- /dev/null +++ b/test/built-ins/DisposableStack/constructor.js @@ -0,0 +1,15 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-disposablestack-constructor +description: > + The DisposableStack constructor is the %DisposableStack% intrinsic object and the initial + value of the DisposableStack property of the global object. +features: [explicit-resource-management] +---*/ + +assert.sameValue( + typeof DisposableStack, 'function', + 'typeof DisposableStack is function' +); diff --git a/test/built-ins/DisposableStack/prototype-from-newtarget-abrupt.js b/test/built-ins/DisposableStack/prototype-from-newtarget-abrupt.js new file mode 100644 index 00000000000..9543b4a134b --- /dev/null +++ b/test/built-ins/DisposableStack/prototype-from-newtarget-abrupt.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 +description: > + Return abrupt from getting the NewTarget prototype +info: | + DisposableStack ( ) + + ... + 2. Let disposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%DisposableStack.prototype%", « [[DisposableState]], [[DisposeCapability]] »). + 3. Set disposableStack.[[DisposableState]] to pending. + 4. Set disposableStack.[[DisposeCapability]] to NewDisposeCapability(). + 5. Return disposableStack. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + 3. Let proto be ? Get(constructor, 'prototype'). +features: [explicit-resource-management, Reflect.construct] +---*/ + +var calls = 0; +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, 'prototype', { + get: function() { + calls += 1; + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.construct(DisposableStack, [], newTarget); +}); + +assert.sameValue(calls, 1); diff --git a/test/built-ins/DisposableStack/prototype-from-newtarget-custom.js b/test/built-ins/DisposableStack/prototype-from-newtarget-custom.js new file mode 100644 index 00000000000..edf91b33b4b --- /dev/null +++ b/test/built-ins/DisposableStack/prototype-from-newtarget-custom.js @@ -0,0 +1,45 @@ +// 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: > + The [[Prototype]] internal slot is computed from NewTarget. +info: | + DisposableStack ( ) + + ... + 2. Let disposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%DisposableStack.prototype%", « [[DisposableState]], [[DisposeCapability]] »). + 3. Set disposableStack.[[DisposableState]] to pending. + 4. Set disposableStack.[[DisposeCapability]] to NewDisposeCapability(). + 5. Return disposableStack. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + 3. Let proto be ? Get(constructor, 'prototype'). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [explicit-resource-management, Reflect.construct] +---*/ + +var stack; + +stack = Reflect.construct(DisposableStack, [], Object); +assert.sameValue(Object.getPrototypeOf(stack), Object.prototype, 'NewTarget is built-in Object constructor'); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, 'prototype', { + get: function() { + return Array.prototype; + } +}); +stack = Reflect.construct(DisposableStack, [], newTarget); +assert.sameValue(Object.getPrototypeOf(stack), Array.prototype, 'NewTarget is BoundFunction with accessor'); diff --git a/test/built-ins/DisposableStack/prototype-from-newtarget.js b/test/built-ins/DisposableStack/prototype-from-newtarget.js new file mode 100644 index 00000000000..4a01ae60380 --- /dev/null +++ b/test/built-ins/DisposableStack/prototype-from-newtarget.js @@ -0,0 +1,34 @@ +// 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: > + The [[Prototype]] internal slot is computed from NewTarget. +info: | + DisposableStack ( ) + + ... + 2. Let disposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%DisposableStack.prototype%", « [[DisposableState]], [[DisposeCapability]] »). + 3. Set disposableStack.[[DisposableState]] to pending. + 4. Set disposableStack.[[DisposeCapability]] to NewDisposeCapability(). + 5. Return disposableStack. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + 3. Let proto be ? Get(constructor, 'prototype'). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [explicit-resource-management] +---*/ + +var stack = new DisposableStack(); +assert.sameValue(Object.getPrototypeOf(stack), DisposableStack.prototype); diff --git a/test/built-ins/DisposableStack/undefined-newtarget-throws.js b/test/built-ins/DisposableStack/undefined-newtarget-throws.js new file mode 100644 index 00000000000..a37445a0238 --- /dev/null +++ b/test/built-ins/DisposableStack/undefined-newtarget-throws.js @@ -0,0 +1,18 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-disposablestack +description: > + Throws a TypeError if NewTarget is undefined. +info: | + DisposableStack ( ) + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +features: [explicit-resource-management] +---*/ + +assert.throws(TypeError, function() { + DisposableStack(); +});