Skip to content

Commit 3c8684d

Browse files
paintedveil5robertsipka
authored andcommitted
Fix the private field crash for the Array object.
Fixes the following issues: 5097, 5100, 5138 Additional test cases added by: Robert Sipka <robert.sipka@h-lab.eu> JerryScript-DCO-1.0-Signed-off-by: Baihe Jiang <baihe.jiang@outlook.com>
1 parent 00d12c0 commit 3c8684d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

jerry-core/vm/opcodes.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,11 @@ opfunc_private_method_or_accessor_add (ecma_object_t *class_object_p, /**< the f
919919

920920
JERRY_ASSERT (prop_name_p->u.hash & ECMA_SYMBOL_FLAG_PRIVATE_INSTANCE_METHOD);
921921

922+
if (ecma_op_object_is_fast_array (this_obj_p))
923+
{
924+
ecma_fast_array_convert_to_normal (this_obj_p);
925+
}
926+
922927
prop_p = ecma_find_named_property (this_obj_p, prop_name_p);
923928
ecma_object_t *method_p = ecma_get_object_from_value (method);
924929

@@ -1369,6 +1374,11 @@ opfunc_private_field_add (ecma_value_t base, /**< base object */
13691374
ecma_string_t *prop_name_p = ecma_get_string_from_value (property);
13701375
ecma_string_t *private_key_p = NULL;
13711376

1377+
if (ecma_op_object_is_fast_array (obj_p))
1378+
{
1379+
ecma_fast_array_convert_to_normal (obj_p);
1380+
}
1381+
13721382
ecma_property_t *prop_p = opfunc_find_private_element (obj_p, prop_name_p, &private_key_p, false);
13731383

13741384
if (prop_p != NULL)

tests/jerry/private_fields.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,41 @@ class O {
327327
var var16 = new O();
328328
var16.b();
329329
assert(var16.c() == 12);
330+
331+
// Private fields are accessible in Array object
332+
class P extends Array {
333+
#a = 1;
334+
b() {
335+
return this.#a;
336+
}
337+
}
338+
339+
var var17 = new P();
340+
assert(var17.b() == 1);
341+
342+
class Q extends Array {
343+
#a() {
344+
return 1;
345+
}
346+
b() {
347+
return this.#a();
348+
}
349+
}
350+
351+
var var18 = new Q();
352+
assert(var18.b() == 1);
353+
354+
// Issue 5097
355+
class Foo extends ([]).constructor {
356+
#g;
357+
}
358+
new Foo();
359+
360+
// Issue 5100
361+
class Foo2 extends Array {
362+
#x() {
363+
}
364+
}
365+
366+
var bar = new Foo2();
367+
bar[0] = 1;

0 commit comments

Comments
 (0)