Skip to content

Commit deea56a

Browse files
author
Sosuke Suzuki
committed
Add tests for rejected %AsyncIteratorPrototype%.@@asyncDispose
1 parent 93d6396 commit deea56a

3 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2025 Sosuke Suzuki. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
esid: sec-%asynciteratorprototype%-@@asyncDispose
5+
description: %AsyncIteratorPrototype%.@@asyncDispose should rejects if `return` returns rejected promise
6+
info: |
7+
%AsyncIteratorPrototype% [ @@asyncDispose ] ( )
8+
9+
...
10+
6. Else,
11+
a. Let result be Call(return, O, « undefined »).
12+
b. IfAbruptRejectPromise(result, promiseCapability).
13+
...
14+
15+
features: [explicit-resource-management]
16+
includes: [asyncHelpers.js]
17+
---*/
18+
19+
async function* generator() {}
20+
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(generator.prototype));
21+
22+
var returnCount = 0;
23+
24+
function CatchError() {}
25+
26+
const obj = {
27+
return() {
28+
returnCount++;
29+
return Promise.reject(new CatchError());
30+
}
31+
};
32+
33+
asyncTest(async function () {
34+
await assert.throwsAsync(CatchError, function () {
35+
return AsyncIteratorPrototype[Symbol.asyncDispose].call(obj);
36+
}, "Promise should be rejected");
37+
assert.sameValue(returnCount, 1);
38+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2025 Sosuke Suzuki. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
esid: sec-%asynciteratorprototype%-@@asyncDispose
5+
description: %AsyncIteratorPrototype%.@@asyncDispose should rejects if `return` getter throws
6+
info: |
7+
%AsyncIteratorPrototype% [ @@asyncDispose ] ( )
8+
9+
1. Let O be the this value.
10+
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
11+
3. Let return be GetMethod(O, "return").
12+
4. IfAbruptRejectPromise(return, promiseCapability).
13+
...
14+
15+
features: [explicit-resource-management]
16+
includes: [asyncHelpers.js]
17+
---*/
18+
19+
async function* generator() {}
20+
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(generator.prototype));
21+
22+
var returnGetCount = 0;
23+
24+
function CatchError() {}
25+
26+
const obj = {
27+
get return() {
28+
returnGetCount++;
29+
throw new CatchError();
30+
}
31+
};
32+
33+
asyncTest(async function () {
34+
await assert.throwsAsync(CatchError, function () {
35+
return AsyncIteratorPrototype[Symbol.asyncDispose].call(obj);
36+
}, "Promise should be rejected");
37+
assert.sameValue(returnGetCount, 1);
38+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2025 Sosuke Suzuki. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
esid: sec-%asynciteratorprototype%-@@asyncDispose
5+
description: %AsyncIteratorPrototype%.@@asyncDispose should rejects if `return` throws
6+
info: |
7+
%AsyncIteratorPrototype% [ @@asyncDispose ] ( )
8+
9+
...
10+
6. Else,
11+
a. Let result be Call(return, O, « undefined »).
12+
b. IfAbruptRejectPromise(result, promiseCapability).
13+
...
14+
15+
features: [explicit-resource-management]
16+
includes: [asyncHelpers.js]
17+
---*/
18+
19+
async function* generator() {}
20+
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(generator.prototype));
21+
22+
var returnCount = 0;
23+
24+
function CatchError() {}
25+
26+
const obj = {
27+
return() {
28+
returnCount++;
29+
throw new CatchError();
30+
}
31+
};
32+
33+
asyncTest(async function () {
34+
await assert.throwsAsync(CatchError, function () {
35+
return AsyncIteratorPrototype[Symbol.asyncDispose].call(obj);
36+
}, "Promise should be rejected");
37+
assert.sameValue(returnCount, 1);
38+
});

0 commit comments

Comments
 (0)