mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 21:45:04 +02:00
Merge pull request #4083 from tc39/chromium-export-7eb56ce860
[explicit-resource-management] Add move and disposed getter
This commit is contained in:
commit
9c94de66c8
@ -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…
x
Reference in New Issue
Block a user