1 // |reftest| skip -- explicit-resource-management is not supported
2 // Copyright (C) 2024 the V8 project authors. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
6 description: Test if disposed methods are called in correct syntax.
7 includes: [compareArray.js]
8 features: [explicit-resource-management]
11 // Block ----------------
14 (function TestUsingInBlock() {
25 assert.compareArray(blockValues, [43, 42]);
27 // CaseBlock --------------
28 let caseBlockValues = [];
30 (function TestUsingInCaseBlock() {
37 caseBlockValues.push(42);
41 caseBlockValues.push(43);
43 assert.compareArray(caseBlockValues, [42, 43]);
45 // ForStatement --------------
46 let forStatementValues = [];
48 (function TestUsingInForStatement() {
49 for (let i = 0; i < 3; i++) {
53 forStatementValues.push(this.value);
57 forStatementValues.push(3);
59 assert.compareArray(forStatementValues, [0, 1, 2, 3]);
61 // ForInStatement --------------
62 let forInStatementValues = [];
64 (function TestUsingInForInStatement() {
65 for (let i in [0, 1]) {
69 forInStatementValues.push(this.value);
73 forInStatementValues.push('2');
75 assert.compareArray(forInStatementValues, ['0', '1', '2']);
77 // ForOfStatement --------------
78 let forOfStatementValues = [];
80 (function TestUsingInForOfStatement() {
81 for (let i of [0, 1]) {
85 forOfStatementValues.push(this.value);
89 forOfStatementValues.push(2);
91 assert.compareArray(forOfStatementValues, [0, 1, 2]);
93 // FunctionBody --------------
94 let functionBodyValues = [];
96 (function TestUsingInFunctionBody() {
100 functionBodyValues.push(42);
106 functionBodyValues.push(43);
110 assert.compareArray(functionBodyValues, [43, 42]);
112 // GeneratorBody --------------
113 let generatorBodyValues = [];
119 generatorBodyValues.push(42);
125 (function TestUsingInGeneratorBody() {
129 generatorBodyValues.push(43);
131 assert.compareArray(generatorBodyValues, [42, 43]);
133 // ClassStaticBlockBody --------------
134 let classStaticBlockBodyValues = [];
136 class staticBlockClass {
141 classStaticBlockBodyValues.push(42);
147 (function TestUsingInAsyncFunctionBody() {
148 let example = new staticBlockClass();
150 assert.compareArray(classStaticBlockBodyValues, [42]);
152 // Derived constructor case
153 let derivedConstructorValues = [];
157 derivedConstructorValues.push(43);
161 class subClass extends baseClass {
167 derivedConstructorValues.push(42);
178 (function TestUsingInDerivedConstructor() {
179 let example = new subClass();
181 assert.compareArray(derivedConstructorValues, [42, 43]);
183 // Lack of dispose method
186 function TestUsingWithoutDisposeMethod() {
188 using x = {value: 1};
192 assert.throws(TypeError, TestUsingWithoutDisposeMethod, 'No dispose method');