Skip to content

Commit 23bba1c

Browse files
authored
Builtin objects finalization should handle function properties with tagged template literal collection (#3896)
This patch fixes #3893. Co-authored-by: Dániel Bátyai [email protected] JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 38111c0 commit 23bba1c

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ ecma_gc_free_executable_object (ecma_object_t *object_p) /**< object */
906906
/**
907907
* Free properties of an object
908908
*/
909-
static void
909+
void
910910
ecma_gc_free_properties (ecma_object_t *object_p) /**< object */
911911
{
912912
jmem_cpointer_t prop_iter_cp = object_p->u1.property_list_cp;

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

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
void ecma_init_gc_info (ecma_object_t *object_p);
3030
void ecma_ref_object (ecma_object_t *object_p);
3131
void ecma_deref_object (ecma_object_t *object_p);
32+
void ecma_gc_free_properties (ecma_object_t *object_p);
3233
void ecma_gc_run (void);
3334
void ecma_free_unused_memory (jmem_pressure_t pressure);
3435

jerry-core/ecma/builtin-objects/ecma-builtins.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,22 @@ ecma_finalize_builtins (void)
539539
{
540540
if (JERRY_CONTEXT (ecma_builtin_objects)[id] != JMEM_CP_NULL)
541541
{
542-
ecma_deref_object (ECMA_GET_NON_NULL_POINTER (ecma_object_t, JERRY_CONTEXT (ecma_builtin_objects)[id]));
542+
ecma_object_t *obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, JERRY_CONTEXT (ecma_builtin_objects)[id]);
543+
ecma_deref_object (obj_p);
544+
545+
#if ENABLED (JERRY_ES2015)
546+
/* Note: In ES2015 a function object may contain tagged template literal collection. Whenever
547+
this function is assigned to a builtin function or function routine during the GC it may cause unresolvable
548+
circle since one part of the circle is a weak reference (marked by GC) and the other part is hard reference
549+
(reference count). In this case when the function which contains the tagged template literal collection
550+
is getting GC marked the arrays in the collection are still holding weak references to properties/prototypes
551+
which prevents these objects from getting freed. Releasing the property list and the prototype reference
552+
manually eliminates the existence of the unresolvable circle described above. */
553+
ecma_gc_free_properties (obj_p);
554+
obj_p->u1.property_list_cp = JMEM_CP_NULL;
555+
obj_p->u2.prototype_cp = JMEM_CP_NULL;
556+
#endif /* ENABLED (JERRY_ES2015) */
557+
543558
JERRY_CONTEXT (ecma_builtin_objects)[id] = JMEM_CP_NULL;
544559
}
545560
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
Object.prototype.toString = function () {
16+
return a`` ;
17+
};

0 commit comments

Comments
 (0)