Skip to content

Commit 11d076f

Browse files
author
Fabrice Bellard
committed
added get_array_el3 opcode - removed to_propkey2 opcode
1 parent 703de06 commit 11d076f

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

quickjs-opcode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ DEF( put_private_field, 1, 3, 0, none) /* obj value prop -> */
144144
DEF(define_private_field, 1, 3, 1, none) /* obj prop value -> obj */
145145
DEF( get_array_el, 1, 2, 1, none)
146146
DEF( get_array_el2, 1, 2, 2, none) /* obj prop -> obj value */
147+
DEF( get_array_el3, 1, 2, 3, none) /* obj prop -> obj prop1 value */
147148
DEF( put_array_el, 1, 3, 0, none)
148149
DEF(get_super_value, 1, 3, 1, none) /* this obj prop -> value */
149150
DEF(put_super_value, 1, 4, 0, none) /* this obj prop value -> */
@@ -189,7 +190,6 @@ DEF( nip_catch, 1, 2, 1, none) /* catch ... a -> a */
189190
DEF( to_object, 1, 1, 1, none)
190191
//DEF( to_string, 1, 1, 1, none)
191192
DEF( to_propkey, 1, 1, 1, none)
192-
DEF( to_propkey2, 1, 2, 2, none)
193193

194194
DEF( with_get_var, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
195195
DEF( with_put_var, 10, 2, 1, atom_label_u8) /* must be in the same order as scope_xxx */

quickjs.c

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18239,6 +18239,38 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
1823918239
}
1824018240
BREAK;
1824118241

18242+
CASE(OP_get_array_el3):
18243+
{
18244+
JSValue val;
18245+
18246+
switch (JS_VALUE_GET_TAG(sp[-2])) {
18247+
case JS_TAG_INT:
18248+
case JS_TAG_STRING:
18249+
case JS_TAG_SYMBOL:
18250+
/* undefined and null are tested in JS_GetPropertyValue() */
18251+
break;
18252+
default:
18253+
/* must be tested nefore JS_ToPropertyKey */
18254+
if (unlikely(JS_IsUndefined(sp[-2]) || JS_IsNull(sp[-2]))) {
18255+
JS_ThrowTypeError(ctx, "value has no property");
18256+
goto exception;
18257+
}
18258+
sf->cur_pc = pc;
18259+
ret_val = JS_ToPropertyKey(ctx, sp[-1]);
18260+
if (JS_IsException(ret_val))
18261+
goto exception;
18262+
JS_FreeValue(ctx, sp[-1]);
18263+
sp[-1] = ret_val;
18264+
break;
18265+
}
18266+
sf->cur_pc = pc;
18267+
val = JS_GetPropertyValue(ctx, sp[-2], JS_DupValue(ctx, sp[-1]));
18268+
*sp++ = val;
18269+
if (unlikely(JS_IsException(val)))
18270+
goto exception;
18271+
}
18272+
BREAK;
18273+
1824218274
CASE(OP_get_ref_value):
1824318275
{
1824418276
JSValue val;
@@ -18966,27 +18998,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
1896618998
}
1896718999
BREAK;
1896819000

18969-
CASE(OP_to_propkey2):
18970-
/* must be tested first */
18971-
if (unlikely(JS_IsUndefined(sp[-2]) || JS_IsNull(sp[-2]))) {
18972-
JS_ThrowTypeError(ctx, "value has no property");
18973-
goto exception;
18974-
}
18975-
switch (JS_VALUE_GET_TAG(sp[-1])) {
18976-
case JS_TAG_INT:
18977-
case JS_TAG_STRING:
18978-
case JS_TAG_SYMBOL:
18979-
break;
18980-
default:
18981-
sf->cur_pc = pc;
18982-
ret_val = JS_ToPropertyKey(ctx, sp[-1]);
18983-
if (JS_IsException(ret_val))
18984-
goto exception;
18985-
JS_FreeValue(ctx, sp[-1]);
18986-
sp[-1] = ret_val;
18987-
break;
18988-
}
18989-
BREAK;
1899019001
#if 0
1899119002
CASE(OP_to_string):
1899219003
if (JS_VALUE_GET_TAG(sp[-1]) != JS_TAG_STRING) {
@@ -24307,10 +24318,7 @@ static __exception int get_lvalue(JSParseState *s, int *popcode, int *pscope,
2430724318
emit_u16(s, scope);
2430824319
break;
2430924320
case OP_get_array_el:
24310-
/* XXX: replace by a single opcode ? */
24311-
emit_op(s, OP_to_propkey2);
24312-
emit_op(s, OP_dup2);
24313-
emit_op(s, OP_get_array_el);
24321+
emit_op(s, OP_get_array_el3);
2431424322
break;
2431524323
case OP_get_super_value:
2431624324
emit_op(s, OP_to_propkey);
@@ -24739,7 +24747,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
2473924747
continue;
2474024748
}
2474124749
if (prop_name == JS_ATOM_NULL) {
24742-
emit_op(s, OP_to_propkey2);
24750+
emit_op(s, OP_to_propkey);
2474324751
if (has_ellipsis) {
2474424752
/* define the property in excludeList */
2474524753
emit_op(s, OP_perm3);
@@ -33334,9 +33342,8 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s)
3333433342
goto no_change;
3333533343

3333633344
case OP_to_propkey:
33337-
case OP_to_propkey2:
3333833345
if (OPTIMIZE) {
33339-
/* remove redundant to_propkey/to_propkey2 opcodes when storing simple data */
33346+
/* remove redundant to_propkey opcodes when storing simple data */
3334033347
if (code_match(&cc, pos_next, M3(OP_get_loc, OP_get_arg, OP_get_var_ref), -1, OP_put_array_el, -1)
3334133348
|| code_match(&cc, pos_next, M3(OP_push_i32, OP_push_const, OP_push_atom_value), OP_put_array_el, -1)
3334233349
|| code_match(&cc, pos_next, M4(OP_undefined, OP_null, OP_push_true, OP_push_false), OP_put_array_el, -1)) {

0 commit comments

Comments
 (0)