Skip to content

Commit 411a949

Browse files
committed
Fix the private field crash for the Array object.
JerryScript-DCO-1.0-Signed-off-by: Baihe Jiang <baihe.jiang@outlook.com>
1 parent 47bd5d4 commit 411a949

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

jerry-core/vm/opcodes.c

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

917917
JERRY_ASSERT (prop_name_p->u.hash & ECMA_SYMBOL_FLAG_PRIVATE_INSTANCE_METHOD);
918918

919+
if (ecma_op_object_is_fast_array (this_obj_p))
920+
{
921+
ecma_fast_array_convert_to_normal (this_obj_p);
922+
}
923+
919924
prop_p = ecma_find_named_property (this_obj_p, prop_name_p);
920925
ecma_object_t *method_p = ecma_get_object_from_value (method);
921926

@@ -1366,6 +1371,11 @@ opfunc_private_field_add (ecma_value_t base, /**< base object */
13661371
ecma_string_t *prop_name_p = ecma_get_string_from_value (property);
13671372
ecma_string_t *private_key_p = NULL;
13681373

1374+
if (ecma_op_object_is_fast_array (obj_p))
1375+
{
1376+
ecma_fast_array_convert_to_normal (obj_p);
1377+
}
1378+
13691379
ecma_property_t *prop_p = opfunc_find_private_element (obj_p, prop_name_p, &private_key_p, false);
13701380

13711381
if (prop_p != NULL)

tests/jerry/private_fields.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,26 @@ 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);

0 commit comments

Comments
 (0)