Test Iterator Symbol.dispose calls return method

This commit is contained in:
Ron Buckton 2025-01-31 12:59:50 +05:30 committed by Philip Chimento
parent bc5c14176e
commit bdf546c60c
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,30 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%iteratorprototype%-@@dispose
description: Return value of @@dispose on %IteratorPrototype%
info: |
%IteratorPrototype% [ @@dispose ] ( )
1. Let O be the this value.
2. Let return be ? GetMethod(O, "return").
3. If return is not undefined, then
a. Perform ? Call(return, O, « »).
4. Return undefined.
features: [explicit-resource-management]
---*/
const IteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf([][Symbol.iterator]())
);
const iter = Object.create(IteratorPrototype);
var returnCalled = false;
iter.return = function () {
returnCalled = true;
return { done: true };
};
iter[Symbol.dispose]();
assert.sameValue(returnCalled, true);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%iteratorprototype%-@@dispose
description: Return value of @@dispose on %IteratorPrototype%
info: |
%IteratorPrototype% [ @@dispose ] ( )
1. Let O be the this value.
2. Let return be ? GetMethod(O, "return").
3. If return is not undefined, then
a. Perform ? Call(return, O, « »).
4. Return undefined.
features: [explicit-resource-management]
---*/
const IteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf([][Symbol.iterator]())
);
assert.sameValue(IteratorPrototype[Symbol.dispose](), undefined);