mirror of
https://github.com/tc39/test262.git
synced 2025-07-28 16:34:27 +02:00
Basic constructor and newtarget tests for DisposableStack
This commit is contained in:
parent
5bdc35ab46
commit
88d6c18030
15
test/built-ins/DisposableStack/constructor.js
Normal file
15
test/built-ins/DisposableStack/constructor.js
Normal file
@ -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'
|
||||||
|
);
|
42
test/built-ins/DisposableStack/prototype-from-newtarget-abrupt.js
vendored
Normal file
42
test/built-ins/DisposableStack/prototype-from-newtarget-abrupt.js
vendored
Normal file
@ -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);
|
45
test/built-ins/DisposableStack/prototype-from-newtarget-custom.js
vendored
Normal file
45
test/built-ins/DisposableStack/prototype-from-newtarget-custom.js
vendored
Normal file
@ -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');
|
34
test/built-ins/DisposableStack/prototype-from-newtarget.js
vendored
Normal file
34
test/built-ins/DisposableStack/prototype-from-newtarget.js
vendored
Normal file
@ -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);
|
18
test/built-ins/DisposableStack/undefined-newtarget-throws.js
Normal file
18
test/built-ins/DisposableStack/undefined-newtarget-throws.js
Normal file
@ -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();
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user