From 957ab22773f621282c8ae5a4a479aa44447886c9 Mon Sep 17 00:00:00 2001 From: SkyCrystal Date: Thu, 26 Sep 2024 00:58:24 +0800 Subject: [PATCH] Add a test for Generator (#3729) --- .../try-finally-set-property-within-try.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/built-ins/GeneratorPrototype/return/try-finally-set-property-within-try.js diff --git a/test/built-ins/GeneratorPrototype/return/try-finally-set-property-within-try.js b/test/built-ins/GeneratorPrototype/return/try-finally-set-property-within-try.js new file mode 100644 index 0000000000..cd5995a827 --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-finally-set-property-within-try.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Bo Pang. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generator.prototype.return +description: > + When a generator is paused within a `try` block of a `try..finally` + statement, `return` should interrupt control flow as if a `return` + statement had appeared at that location in the function body. + The `finally` block is still evaluated, and may override the return value. +features: [generators] +---*/ + + +var obj = { foo: 'not modified' }; +function* g() { + try { + obj.foo = yield; + } finally { + return 1; + } +} +var iter = g(); +var result; + +iter.next(); +result = iter.return(45).value; +assert.sameValue(obj.foo, 'not modified', '`obj.foo` must not be set'); +assert.sameValue(result, 1, 'finally block must supersede return value');