diff options
Diffstat (limited to 'js/src/tests/test262/staging/explicit-resource-management')
9 files changed, 231 insertions, 0 deletions
diff --git a/js/src/tests/test262/staging/explicit-resource-management/Symbol/browser.js b/js/src/tests/test262/staging/explicit-resource-management/Symbol/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/staging/explicit-resource-management/Symbol/browser.js diff --git a/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/browser.js b/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/browser.js diff --git a/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/cross-realm.js b/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/cross-realm.js new file mode 100644 index 0000000000..40a3a9a54c --- /dev/null +++ b/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/cross-realm.js @@ -0,0 +1,17 @@ +// |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: Value shared by all realms +info: | + Unless otherwise specified, well-known symbols values are shared by all + realms. +features: [cross-realm, explicit-resource-management] +---*/ + +var OSymbol = $262.createRealm().global.Symbol; + +assert.sameValue(Symbol.dispose, OSymbol.dispose); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/prop-desc.js b/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/prop-desc.js new file mode 100644 index 0000000000..8f4330035c --- /dev/null +++ b/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/prop-desc.js @@ -0,0 +1,20 @@ +// |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: > + `Symbol.dispose` property descriptor +info: | + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [explicit-resource-management] +---*/ + +assert.sameValue(typeof Symbol.dispose, 'symbol'); +verifyNotEnumerable(Symbol, 'dispose'); +verifyNotWritable(Symbol, 'dispose'); +verifyNotConfigurable(Symbol, 'dispose'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/shell.js b/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/staging/explicit-resource-management/Symbol/dispose/shell.js diff --git a/js/src/tests/test262/staging/explicit-resource-management/Symbol/shell.js b/js/src/tests/test262/staging/explicit-resource-management/Symbol/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/staging/explicit-resource-management/Symbol/shell.js diff --git a/js/src/tests/test262/staging/explicit-resource-management/browser.js b/js/src/tests/test262/staging/explicit-resource-management/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/staging/explicit-resource-management/browser.js 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); diff --git a/js/src/tests/test262/staging/explicit-resource-management/shell.js b/js/src/tests/test262/staging/explicit-resource-management/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/staging/explicit-resource-management/shell.js |