diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /js/src/tests/test262/staging/explicit-resource-management/call-dispose-methods.js | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/staging/explicit-resource-management/call-dispose-methods.js')
-rw-r--r-- | js/src/tests/test262/staging/explicit-resource-management/call-dispose-methods.js | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/js/src/tests/test262/staging/explicit-resource-management/call-dispose-methods.js b/js/src/tests/test262/staging/explicit-resource-management/call-dispose-methods.js new file mode 100644 index 0000000000..55189d2150 --- /dev/null +++ b/js/src/tests/test262/staging/explicit-resource-management/call-dispose-methods.js @@ -0,0 +1,194 @@ +// |reftest| skip -- explicit-resource-management is not supported +// 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 if disposed methods are called in correct syntax. +includes: [compareArray.js] +features: [explicit-resource-management] +---*/ + +// Block ---------------- +let blockValues = []; + +(function TestUsingInBlock() { + { + using x = { + value: 1, + [Symbol.dispose]() { + blockValues.push(42); + } + }; + blockValues.push(43); + } +})(); +assert.compareArray(blockValues, [43, 42]); + +// CaseBlock -------------- +let caseBlockValues = []; + +(function TestUsingInCaseBlock() { + let label = 1; + switch (label) { + case 1: + using x = { + value: 1, + [Symbol.dispose]() { + caseBlockValues.push(42); + } + }; + } + caseBlockValues.push(43); +})(); +assert.compareArray(caseBlockValues, [42, 43]); + +// ForStatement -------------- +let forStatementValues = []; + +(function TestUsingInForStatement() { + for (let i = 0; i < 3; i++) { + using x = { + value: i, + [Symbol.dispose]() { + forStatementValues.push(this.value); + } + }; + } + forStatementValues.push(3); +})(); +assert.compareArray(forStatementValues, [0, 1, 2, 3]); + +// ForInStatement -------------- +let forInStatementValues = []; + +(function TestUsingInForInStatement() { + for (let i in [0, 1]) { + using x = { + value: i, + [Symbol.dispose]() { + forInStatementValues.push(this.value); + } + }; + } + forInStatementValues.push('2'); +})(); +assert.compareArray(forInStatementValues, ['0', '1', '2']); + +// ForOfStatement -------------- +let forOfStatementValues = []; + +(function TestUsingInForOfStatement() { + for (let i of [0, 1]) { + using x = { + value: i, + [Symbol.dispose]() { + forOfStatementValues.push(this.value); + } + }; + } + forOfStatementValues.push(2); +})(); +assert.compareArray(forOfStatementValues, [0, 1, 2]); + +// FunctionBody -------------- +let functionBodyValues = []; + +(function TestUsingInFunctionBody() { + using x = { + value: 1, + [Symbol.dispose]() { + functionBodyValues.push(42); + } + }; + using y = { + value: 2, + [Symbol.dispose]() { + functionBodyValues.push(43); + } + }; +})(); +assert.compareArray(functionBodyValues, [43, 42]); + +// GeneratorBody -------------- +let generatorBodyValues = []; + +function* gen() { + using x = { + value: 1, + [Symbol.dispose]() { + generatorBodyValues.push(42); + } + }; + yield x; +} + +(function TestUsingInGeneratorBody() { + let iter = gen(); + iter.next(); + iter.next(); + generatorBodyValues.push(43); +})(); +assert.compareArray(generatorBodyValues, [42, 43]); + +// ClassStaticBlockBody -------------- +let classStaticBlockBodyValues = []; + +class staticBlockClass { + static { + using x = { + value: 1, + [Symbol.dispose]() { + classStaticBlockBodyValues.push(42); + } + }; + } +} + +(function TestUsingInAsyncFunctionBody() { + let example = new staticBlockClass(); +})(); +assert.compareArray(classStaticBlockBodyValues, [42]); + +// Derived constructor case +let derivedConstructorValues = []; + +class baseClass { + constructor() { + derivedConstructorValues.push(43); + } +} + +class subClass extends baseClass { + constructor() { + try { + using x = { + value: 1, + [Symbol.dispose]() { + derivedConstructorValues.push(42); + } + }; + } catch (e) { + return; + } finally { + super(); + } + } +} + +(function TestUsingInDerivedConstructor() { + let example = new subClass(); +})(); +assert.compareArray(derivedConstructorValues, [42, 43]); + +// Lack of dispose method +let values = []; + +function TestUsingWithoutDisposeMethod() { + { + using x = {value: 1}; + values.push(43); + } +} +assert.throws(TypeError, TestUsingWithoutDisposeMethod, 'No dispose method'); + +reportCompare(0, 0); |