Skip to content

Commit dba9533

Browse files
authored
Compiled code should hold strong reference for the object in the tagged template literal collection (#3876)
This patch fixes #3866. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
1 parent 7038325 commit dba9533

File tree

4 files changed

+40
-33
lines changed

4 files changed

+40
-33
lines changed

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ ecma_init_gc_info (ecma_object_t *object_p) /**< object */
115115
JERRY_CONTEXT (ecma_gc_objects_number)++;
116116
JERRY_CONTEXT (ecma_gc_new_objects)++;
117117

118-
JERRY_ASSERT (JERRY_CONTEXT (ecma_gc_new_objects) <= JERRY_CONTEXT (ecma_gc_objects_number));
119-
120118
JERRY_ASSERT (object_p->type_flags_refs < ECMA_OBJECT_REF_ONE);
121119
object_p->type_flags_refs = (uint16_t) (object_p->type_flags_refs | ECMA_OBJECT_REF_ONE);
122120

@@ -398,23 +396,6 @@ ecma_gc_mark_set_object (ecma_object_t *object_p) /**< object */
398396
#endif /* ENABLED (JERRY_ES2015_BUILTIN_SET) */
399397

400398
#if ENABLED (JERRY_ES2015)
401-
402-
/**
403-
* Mark tagged template literals of the compiled code.
404-
*/
405-
static void
406-
ecma_gc_mark_tagged_template_literals (const ecma_compiled_code_t *byte_code_p)
407-
{
408-
JERRY_ASSERT (byte_code_p->status_flags & CBC_CODE_FLAG_HAS_TAGGED_LITERALS);
409-
410-
ecma_collection_t *collection_p = ecma_compiled_code_get_tagged_template_collection (byte_code_p);
411-
412-
for (uint32_t i = 0; i < collection_p->item_count; i++)
413-
{
414-
ecma_gc_set_object_visited (ecma_get_object_from_value (collection_p->buffer_p[i]));
415-
}
416-
} /* ecma_gc_mark_tagged_template_literals */
417-
418399
/**
419400
* Mark objects referenced by inactive generator functions, async functions, etc.
420401
*/
@@ -702,11 +683,6 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
702683
#if ENABLED (JERRY_ES2015)
703684
const ecma_compiled_code_t *byte_code_p = ecma_op_function_get_compiled_code (ext_func_p);
704685

705-
if (byte_code_p->status_flags & CBC_CODE_FLAG_HAS_TAGGED_LITERALS)
706-
{
707-
ecma_gc_mark_tagged_template_literals (byte_code_p);
708-
}
709-
710686
if (byte_code_p->status_flags & CBC_CODE_FLAGS_ARROW_FUNCTION)
711687
{
712688
ecma_arrow_function_t *arrow_func_p = (ecma_arrow_function_t *) object_p;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,12 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
14411441
#if ENABLED (JERRY_ES2015)
14421442
if (bytecode_p->status_flags & CBC_CODE_FLAG_HAS_TAGGED_LITERALS)
14431443
{
1444-
ecma_collection_destroy (ecma_compiled_code_get_tagged_template_collection (bytecode_p));
1444+
ecma_collection_t *collection_p = ecma_compiled_code_get_tagged_template_collection (bytecode_p);
1445+
1446+
/* Since the objects in the tagged template collection are not strong referenced anymore by the compiled code
1447+
we can treat them as 'new' objects. */
1448+
JERRY_CONTEXT (ecma_gc_new_objects) += collection_p->item_count;
1449+
ecma_collection_free (collection_p);
14451450
}
14461451
#endif /* ENABLED (JERRY_ES2015) */
14471452

jerry-core/parser/js/js-parser.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,14 +1658,6 @@ parser_post_processing (parser_context_t *context_p) /**< context */
16581658
if (context_p->tagged_template_literal_cp != JMEM_CP_NULL)
16591659
{
16601660
base_p[-1] = (ecma_value_t) context_p->tagged_template_literal_cp;
1661-
1662-
ecma_collection_t *collection_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t,
1663-
context_p->tagged_template_literal_cp);
1664-
1665-
for (uint32_t i = 0; i < collection_p->item_count; i++)
1666-
{
1667-
ecma_free_value (collection_p->buffer_p[i]);
1668-
}
16691661
}
16701662
#endif /* ENABLED (JERRY_ES2015) */
16711663

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
var a;
16+
var b;
17+
var called = false;
18+
Promise.race([a, b]);
19+
Promise.race([b, a]);
20+
Promise.race([, b, a]);
21+
Promise.race().then(function() {}, function() {
22+
let str;
23+
function getStr() {
24+
return $ `$`
25+
}
26+
var $ = getStr()
27+
}).catch(e => {
28+
called = true;
29+
assert (e instanceof TypeError);
30+
})
31+
32+
function __checkAsync() {
33+
assert(called);
34+
}

0 commit comments

Comments
 (0)