@@ -2818,13 +2818,20 @@ DUK_LOCAL void duk__nud_array_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *re
28182818 duk_uarridx_t start_idx ; /* start array index of current MPUTARR set */
28192819 duk_uarridx_t init_idx ; /* last array index explicitly initialized, +1 */
28202820 duk_bool_t require_comma ; /* next loop requires a comma */
2821+ #if !defined(DUK_USE_PREFER_SIZE )
2822+ duk_int_t pc_newarr ;
2823+ duk_compiler_instr * instr ;
2824+ #endif
28212825
28222826 /* DUK_TOK_LBRACKET already eaten, current token is right after that */
28232827 DUK_ASSERT (comp_ctx -> prev_token .t == DUK_TOK_LBRACKET );
28242828
28252829 max_init_values = DUK__MAX_ARRAY_INIT_VALUES ; /* XXX: depend on available temps? */
28262830
28272831 reg_obj = DUK__ALLOCTEMP (comp_ctx );
2832+ #if !defined(DUK_USE_PREFER_SIZE )
2833+ pc_newarr = duk__get_current_pc (comp_ctx );
2834+ #endif
28282835 duk__emit_bc (comp_ctx , DUK_OP_NEWARR , reg_obj ); /* XXX: patch initial size hint afterwards? */
28292836 temp_start = DUK__GETTEMP (comp_ctx );
28302837
@@ -2924,6 +2931,14 @@ DUK_LOCAL void duk__nud_array_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *re
29242931 }
29252932 }
29262933
2934+ /* Update initil size for NEWARR, doesn't need to be exact and is
2935+ * capped at A field limit.
2936+ */
2937+ #if !defined(DUK_USE_PREFER_SIZE )
2938+ instr = duk__get_instr_ptr (comp_ctx , pc_newarr );
2939+ instr -> ins |= DUK_ENC_OP_A (0 , curr_idx > DUK_BC_A_MAX ? DUK_BC_A_MAX : curr_idx );
2940+ #endif
2941+
29272942 DUK_ASSERT (comp_ctx -> curr_token .t == DUK_TOK_RBRACKET );
29282943 duk__advance (comp_ctx );
29292944
@@ -3008,8 +3023,8 @@ DUK_LOCAL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *r
30083023 duk_small_uint_t max_init_pairs ; /* max # of key-value pairs initialized in one MPUTOBJ set */
30093024 duk_bool_t first ; /* first value: comma must not precede the value */
30103025 duk_bool_t is_set , is_get ; /* temps */
3011- duk_int_t pc_newobj ;
30123026#if !defined(DUK_USE_PREFER_SIZE )
3027+ duk_int_t pc_newobj ;
30133028 duk_compiler_instr * instr ;
30143029#endif
30153030
@@ -3022,7 +3037,9 @@ DUK_LOCAL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *r
30223037 st .num_pairs = 0 ; /* number of key/value pairs emitted for current MPUTOBJ set */
30233038 st .num_total_pairs = 0 ; /* number of key/value pairs emitted overall */
30243039
3040+ #if !defined(DUK_USE_PREFER_SIZE )
30253041 pc_newobj = duk__get_current_pc (comp_ctx );
3042+ #endif
30263043 duk__emit_bc (comp_ctx , DUK_OP_NEWOBJ , st .reg_obj );
30273044
30283045 /*
@@ -3219,7 +3236,7 @@ DUK_LOCAL void duk__nud_object_literal(duk_compiler_ctx *comp_ctx, duk_ivalue *r
32193236 */
32203237#if !defined(DUK_USE_PREFER_SIZE )
32213238 instr = duk__get_instr_ptr (comp_ctx , pc_newobj );
3222- instr -> ins |= DUK_ENC_OP_A (0 , st .num_total_pairs > 255 ? 255 : st .num_total_pairs );
3239+ instr -> ins |= DUK_ENC_OP_A (0 , st .num_total_pairs > DUK_BC_A_MAX ? DUK_BC_A_MAX : st .num_total_pairs );
32233240#endif
32243241
32253242 DUK_ASSERT (comp_ctx -> curr_token .t == DUK_TOK_RCURLY );
0 commit comments