Skip to content

Commit 51bfe3d

Browse files
committed
Fix "unhandled exception occurs when a private variable increments"
1 parent 355ab24 commit 51bfe3d

File tree

2 files changed

+66
-18
lines changed

2 files changed

+66
-18
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -289,29 +289,34 @@ parser_emit_unary_lvalue_opcode (parser_context_t *context_p, /**< context */
289289
{
290290
context_p->last_cbc_opcode = PARSER_PUSH_PROP_LITERAL_TO_PUSH_LITERAL (context_p->last_cbc_opcode);
291291
}
292-
else
292+
else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL))
293293
{
294-
/* Invalid LeftHandSide expression. */
295294
if (opcode == CBC_DELETE_PUSH_RESULT)
296295
{
297-
if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL))
298-
{
299-
parser_raise_error (context_p, PARSER_ERR_DELETE_PRIVATE_FIELD);
300-
}
301-
302-
if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL)
303-
|| context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP))
304-
{
305-
parser_emit_cbc_ext (context_p, CBC_EXT_THROW_REFERENCE_ERROR);
306-
parser_emit_cbc (context_p, CBC_POP);
307-
return;
308-
}
296+
parser_raise_error (context_p, PARSER_ERR_DELETE_PRIVATE_FIELD);
297+
goto Invalid_LeftHandSide;
298+
}
299+
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL_REFERENCE);
300+
}
301+
else if (opcode == CBC_DELETE_PUSH_RESULT)
302+
{
303+
/* Invalid LeftHandSide expression. */
304+
Invalid_LeftHandSide:
309305

306+
if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL)
307+
|| context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP))
308+
{
309+
parser_emit_cbc_ext (context_p, CBC_EXT_THROW_REFERENCE_ERROR);
310310
parser_emit_cbc (context_p, CBC_POP);
311-
parser_emit_cbc (context_p, CBC_PUSH_TRUE);
312311
return;
313312
}
314313

314+
parser_emit_cbc (context_p, CBC_POP);
315+
parser_emit_cbc (context_p, CBC_PUSH_TRUE);
316+
return;
317+
}
318+
else
319+
{
315320
parser_check_invalid_new_target (context_p, opcode);
316321
if (opcode == CBC_PRE_INCR || opcode == CBC_PRE_DECR)
317322
{

jerry-core/vm/vm.c

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,6 +2955,20 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
29552955
case VM_OC_PROP_PRE_DECR:
29562956
case VM_OC_PROP_POST_INCR:
29572957
case VM_OC_PROP_POST_DECR:
2958+
if (byte_code_start_p[-3] == CBC_EXT_OPCODE
2959+
&& byte_code_start_p[-2] == CBC_EXT_PUSH_PRIVATE_PROP_LITERAL_REFERENCE)
2960+
{
2961+
if (opcode < CBC_PRE_INCR)
2962+
{
2963+
break;
2964+
}
2965+
result = right_value;
2966+
stack_top_p += 1;
2967+
left_value = right_value;
2968+
/* Use right_value as the marker for private field */
2969+
right_value = ECMA_VALUE_EMPTY;
2970+
}
2971+
else
29582972
{
29592973
result = vm_op_get_value (left_value, right_value);
29602974

@@ -3018,7 +3032,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
30183032
}
30193033

30203034
result = (ecma_value_t) (int_value + int_increase);
3021-
break;
3035+
goto unary_arithmetic_operation_break;
30223036
}
30233037
result_number = (ecma_number_t) ecma_get_integer_from_value (result);
30243038
}
@@ -3068,7 +3082,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
30683082
{
30693083
goto error;
30703084
}
3071-
break;
3085+
goto unary_arithmetic_operation_break;
30723086
}
30733087
#endif /* JERRY_BUILTIN_BIGINT */
30743088

@@ -3089,7 +3103,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
30893103
POST_INCREASE_DECREASE_PUT_RESULT (result);
30903104

30913105
result = ecma_make_number_value (result_number + increase);
3092-
break;
3106+
goto unary_arithmetic_operation_break;
30933107
}
30943108

30953109
if (ecma_is_value_integer_number (result))
@@ -3100,6 +3114,35 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
31003114
{
31013115
result = ecma_update_float_number (result, result_number + increase);
31023116
}
3117+
unary_arithmetic_operation_break:
3118+
if (JERRY_UNLIKELY (right_value == ECMA_VALUE_EMPTY))
3119+
{
3120+
right_value = ECMA_VALUE_UNDEFINED;
3121+
3122+
if (opcode_data & VM_OC_PUT_REFERENCE)
3123+
{
3124+
ecma_value_t property = *(--stack_top_p);
3125+
ecma_value_t base = *(--stack_top_p);
3126+
ecma_value_t set_value_result = opfunc_private_set (base, property, result);
3127+
ecma_free_value (base);
3128+
ecma_free_value (property);
3129+
3130+
if (ECMA_IS_VALUE_ERROR (set_value_result))
3131+
{
3132+
ecma_free_value (result);
3133+
result = set_value_result;
3134+
goto error;
3135+
}
3136+
3137+
if (!(opcode_data & (VM_OC_PUT_STACK | VM_OC_PUT_BLOCK)))
3138+
{
3139+
ecma_fast_free_value (result);
3140+
goto free_both_values;
3141+
}
3142+
3143+
opcode_data &= (uint32_t) ~VM_OC_PUT_REFERENCE;
3144+
}
3145+
}
31033146
break;
31043147
}
31053148
case VM_OC_ASSIGN:

0 commit comments

Comments
 (0)