Skip to content

Commit 3686410

Browse files
authored
Mark generator as running during yield* (#5014)
Fixes #5013 JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 3360e35 commit 3686410

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

jerry-core/ecma/base/ecma-gc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ ecma_gc_mark_executable_object (ecma_object_t *object_p) /**< object */
677677
ecma_gc_set_object_visited (executable_object_p->frame_ctx.lex_env_p);
678678
ecma_gc_set_object_visited (executable_object_p->shared.function_object_p);
679679

680-
if (!ECMA_EXECUTABLE_OBJECT_IS_SUSPENDED (executable_object_p))
680+
if (!ECMA_EXECUTABLE_OBJECT_IS_SUSPENDED (executable_object_p)
681+
&& !(executable_object_p->extended_object.u.cls.u2.executable_obj_flags
682+
& ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD))
681683
{
682684
/* All objects referenced by running executable objects are strong roots,
683685
* and a finished executable object cannot refer to other values. */

jerry-core/ecma/builtin-objects/ecma-builtin-generator-prototype.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,20 @@ ecma_builtin_generator_prototype_object_do (vm_executable_object_t *generator_ob
9191
{
9292
if (generator_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD)
9393
{
94+
if (generator_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_RUNNING)
95+
{
96+
return ecma_raise_type_error (ECMA_ERR_GENERATOR_IS_CURRENTLY_UNDER_EXECUTION);
97+
}
98+
9499
ecma_value_t iterator = generator_object_p->iterator;
95100
ecma_value_t next_method = generator_object_p->frame_ctx.stack_top_p[-1];
96101

97102
bool done = false;
103+
104+
generator_object_p->extended_object.u.cls.u2.executable_obj_flags |= ECMA_EXECUTABLE_OBJECT_RUNNING;
98105
ecma_value_t result = ecma_op_iterator_do (resume_mode, iterator, next_method, arg, &done);
99106
ecma_free_value (arg);
107+
generator_object_p->extended_object.u.cls.u2.executable_obj_flags &= (uint8_t) ~ECMA_EXECUTABLE_OBJECT_RUNNING;
100108

101109
if (ECMA_IS_VALUE_ERROR (result))
102110
{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
function foo() {
16+
var a;
17+
function* bar() {
18+
try {
19+
yield* b;
20+
} catch (e) {
21+
a = e;
22+
}
23+
}
24+
var b = bar();
25+
b.next();
26+
27+
return a;
28+
}
29+
30+
foo();

0 commit comments

Comments
 (0)