mirror of https://github.com/tc39/test262.git
[explicit-resource-management] Add move and disposed getter
This CL adds move() function and a getter for disposed to DisposableStack prototype. Bug: 42203506 Change-Id: I8d7750b1d4aa199ebeb997bde7fe6d06c9ccbff0 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5528992 Commit-Queue: Rezvan Mahdavi Hezaveh <rezvan@chromium.org> Reviewed-by: Adam Klein <adamk@chromium.org> Reviewed-by: Shu-yu Guo <syg@chromium.org> Cr-Commit-Position: refs/heads/main@{#93931}
This commit is contained in:
parent
8b6b0f516d
commit
fb7ab87dd5
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2024 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Test DisposableStack constructor and prototype.
|
||||
includes: [propertyHelper.js]
|
||||
features: [globalThis, explicit-resource-management]
|
||||
---*/
|
||||
|
||||
// constructor --------
|
||||
assert.sameValue(
|
||||
typeof DisposableStack, 'function',
|
||||
'The value of `typeof DisposableStack` is "function"');
|
||||
|
||||
// prototype --------
|
||||
verifyProperty(DisposableStack, 'prototype', {
|
||||
value: DisposableStack.prototype,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
});
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2024 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Test `disposed` accessor property of DisposableStack.
|
||||
features: [explicit-resource-management]
|
||||
---*/
|
||||
|
||||
// disposed should be true --------
|
||||
(function TestDisposableStackDisposedTrue() {
|
||||
let stack = new DisposableStack();
|
||||
const disposable = {
|
||||
value: 1,
|
||||
[Symbol.dispose]() {
|
||||
return 42;
|
||||
}
|
||||
};
|
||||
stack.use(disposable);
|
||||
stack.dispose();
|
||||
assert.sameValue(stack.disposed, true, 'disposed should be true');
|
||||
})();
|
||||
|
||||
// disposed should be false --------
|
||||
(function TestDisposableStackDisposedFalse() {
|
||||
let stack = new DisposableStack();
|
||||
const disposable = {
|
||||
value: 1,
|
||||
[Symbol.dispose]() {
|
||||
return 42;
|
||||
}
|
||||
};
|
||||
stack.use(disposable);
|
||||
assert.sameValue(stack.disposed, false, 'disposed should be false');
|
||||
})();
|
|
@ -0,0 +1,66 @@
|
|||
// Copyright (C) 2024 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Test developer exposed DisposableStack protype method move.
|
||||
includes: [compareArray.js]
|
||||
features: [explicit-resource-management]
|
||||
---*/
|
||||
|
||||
// move() method on disposed stack --------
|
||||
function TestDisposableStackMoveOnDisposedStack() {
|
||||
let stack = new DisposableStack();
|
||||
stack.dispose();
|
||||
let newStack = stack.move();
|
||||
};
|
||||
|
||||
assert.throws(
|
||||
ReferenceError, () => TestDisposableStackMoveOnDisposedStack(),
|
||||
'Cannot move elements from a disposed stack!');
|
||||
|
||||
// move() method --------
|
||||
let valuesNormal = [];
|
||||
|
||||
(function TestDisposableStackMove() {
|
||||
let stack = new DisposableStack();
|
||||
const firstDisposable = {
|
||||
value: 1,
|
||||
[Symbol.dispose]() {
|
||||
valuesNormal.push(42);
|
||||
}
|
||||
};
|
||||
const secondDisposable = {
|
||||
value: 2,
|
||||
[Symbol.dispose]() {
|
||||
valuesNormal.push(43);
|
||||
}
|
||||
};
|
||||
stack.use(firstDisposable);
|
||||
stack.use(secondDisposable);
|
||||
let newStack = stack.move();
|
||||
newStack.dispose();
|
||||
// stack is already disposed, so the next line should do nothing.
|
||||
stack.dispose();
|
||||
})();
|
||||
assert.compareArray(valuesNormal, [43, 42]);
|
||||
|
||||
// Two stacks should not be the same--------
|
||||
(function TestDisposableStackMoveNotSameObjects() {
|
||||
let stack = new DisposableStack();
|
||||
const firstDisposable = {
|
||||
value: 1,
|
||||
[Symbol.dispose]() {
|
||||
return 42;
|
||||
}
|
||||
};
|
||||
const secondDisposable = {
|
||||
value: 2,
|
||||
[Symbol.dispose]() {
|
||||
return 43;
|
||||
}
|
||||
};
|
||||
stack.use(firstDisposable);
|
||||
stack.use(secondDisposable);
|
||||
let newStack = stack.move();
|
||||
assert.notSameValue(stack, newStack);
|
||||
})();
|
Loading…
Reference in New Issue