remove typeof'
This commit is contained in:
@@ -38,7 +38,6 @@ DEF(def, "def")
|
||||
DEF(this, "this")
|
||||
DEF(delete, "delete")
|
||||
DEF(void, "void")
|
||||
DEF(typeof, "typeof")
|
||||
DEF(new, "new")
|
||||
DEF(in, "in")
|
||||
DEF(instanceof, "instanceof")
|
||||
|
||||
@@ -202,7 +202,6 @@ DEF( inc_loc, 2, 0, 0, loc8)
|
||||
DEF( add_loc, 2, 1, 0, loc8)
|
||||
DEF( not, 1, 1, 1, none)
|
||||
DEF( lnot, 1, 1, 1, none)
|
||||
DEF( typeof, 1, 1, 1, none)
|
||||
DEF( delete, 1, 2, 1, none)
|
||||
DEF( delete_var, 5, 0, 1, atom)
|
||||
|
||||
@@ -328,7 +327,6 @@ DEF( call2, 1, 1, 1, npopx)
|
||||
DEF( call3, 1, 1, 1, npopx)
|
||||
|
||||
DEF( is_null, 1, 1, 1, none)
|
||||
DEF( typeof_is_function, 1, 1, 1, none)
|
||||
#endif
|
||||
|
||||
#undef DEF
|
||||
|
||||
124
source/quickjs.c
124
source/quickjs.c
@@ -11696,48 +11696,6 @@ static __exception int js_operator_instanceof(JSContext *ctx, JSValue *sp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static __exception int js_operator_typeof(JSContext *ctx, JSValueConst op1)
|
||||
{
|
||||
JSAtom atom;
|
||||
uint32_t tag;
|
||||
|
||||
tag = JS_VALUE_GET_NORM_TAG(op1);
|
||||
switch(tag) {
|
||||
case JS_TAG_INT:
|
||||
case JS_TAG_FLOAT64:
|
||||
atom = JS_ATOM_number;
|
||||
break;
|
||||
case JS_TAG_BOOL:
|
||||
atom = JS_ATOM_boolean;
|
||||
break;
|
||||
case JS_TAG_STRING:
|
||||
case JS_TAG_STRING_ROPE:
|
||||
atom = JS_ATOM_string;
|
||||
break;
|
||||
case JS_TAG_OBJECT:
|
||||
{
|
||||
if (JS_IsFunction(ctx, op1))
|
||||
atom = JS_ATOM_function;
|
||||
else
|
||||
goto obj_type;
|
||||
}
|
||||
break;
|
||||
case JS_TAG_NULL:
|
||||
atom = JS_ATOM_null;
|
||||
break;
|
||||
obj_type:
|
||||
atom = JS_ATOM_object;
|
||||
break;
|
||||
case JS_TAG_SYMBOL:
|
||||
atom = JS_ATOM_symbol;
|
||||
break;
|
||||
default:
|
||||
atom = JS_ATOM_unknown;
|
||||
break;
|
||||
}
|
||||
return atom;
|
||||
}
|
||||
|
||||
static __exception int js_operator_delete(JSContext *ctx, JSValue *sp)
|
||||
{
|
||||
JSValue op1, op2;
|
||||
@@ -15553,17 +15511,6 @@ static JSValue JS_CallInternal_OLD(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
goto exception;
|
||||
sp--;
|
||||
BREAK;
|
||||
CASE(OP_typeof):
|
||||
{
|
||||
JSValue op1;
|
||||
JSAtom atom;
|
||||
|
||||
op1 = sp[-1];
|
||||
atom = js_operator_typeof(ctx, op1);
|
||||
JS_FreeValue(ctx, op1);
|
||||
sp[-1] = JS_AtomToString(ctx, atom);
|
||||
}
|
||||
BREAK;
|
||||
CASE(OP_delete):
|
||||
sf->cur_pc = pc;
|
||||
if (js_operator_delete(ctx, sp))
|
||||
@@ -15622,16 +15569,6 @@ static JSValue JS_CallInternal_OLD(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
} else {
|
||||
goto free_and_set_false;
|
||||
}
|
||||
#if SHORT_OPCODES
|
||||
CASE(OP_typeof_is_function):
|
||||
if (js_operator_typeof(ctx, sp[-1]) == JS_ATOM_function) {
|
||||
goto free_and_set_true;
|
||||
} else {
|
||||
goto free_and_set_false;
|
||||
}
|
||||
free_and_set_true:
|
||||
JS_FreeValue(ctx, sp[-1]);
|
||||
#endif
|
||||
set_true:
|
||||
sp[-1] = JS_TRUE;
|
||||
BREAK;
|
||||
@@ -15915,7 +15852,6 @@ enum {
|
||||
TOK_THIS,
|
||||
TOK_DELETE,
|
||||
TOK_VOID,
|
||||
TOK_TYPEOF,
|
||||
TOK_NEW,
|
||||
TOK_IN,
|
||||
TOK_INSTANCEOF,
|
||||
@@ -20459,23 +20395,6 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags)
|
||||
FALSE);
|
||||
}
|
||||
break;
|
||||
case TOK_TYPEOF:
|
||||
{
|
||||
JSFunctionDef *fd;
|
||||
if (next_token(s))
|
||||
return -1;
|
||||
if (js_parse_unary(s, PF_POW_FORBIDDEN))
|
||||
return -1;
|
||||
/* reference access should not return an exception, so we
|
||||
patch the get_var */
|
||||
fd = s->cur_func;
|
||||
if (get_prev_opcode(fd) == OP_scope_get_var) {
|
||||
fd->byte_code.buf[fd->last_opcode_pos] = OP_scope_get_var_undef;
|
||||
}
|
||||
emit_op(s, OP_typeof);
|
||||
parse_flags = 0;
|
||||
}
|
||||
break;
|
||||
case TOK_DELETE:
|
||||
if (js_parse_delete(s))
|
||||
return -1;
|
||||
@@ -25130,48 +25049,6 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s)
|
||||
}
|
||||
goto no_change;
|
||||
|
||||
#if SHORT_OPCODES
|
||||
case OP_typeof:
|
||||
if (OPTIMIZE) {
|
||||
/* simplify typeof tests */
|
||||
if (code_match(&cc, pos_next, OP_push_atom_value, M4(OP_strict_eq, OP_strict_neq, OP_eq, OP_neq), -1)) {
|
||||
if (cc.line_num >= 0) line_num = cc.line_num;
|
||||
int op1 = (cc.op == OP_strict_eq || cc.op == OP_eq) ? OP_strict_eq : OP_strict_neq;
|
||||
int op2 = -1;
|
||||
switch (cc.atom) {
|
||||
case JS_ATOM_null:
|
||||
op2 = OP_is_null;
|
||||
break;
|
||||
case JS_ATOM_function:
|
||||
op2 = OP_typeof_is_function;
|
||||
break;
|
||||
}
|
||||
if (op2 >= 0) {
|
||||
/* transform typeof(s) == "<type>" into is_<type> */
|
||||
if (op1 == OP_strict_eq) {
|
||||
add_pc2line_info(s, bc_out.size, line_num);
|
||||
dbuf_putc(&bc_out, op2);
|
||||
JS_FreeAtom(ctx, cc.atom);
|
||||
pos_next = cc.pos;
|
||||
break;
|
||||
}
|
||||
if (op1 == OP_strict_neq && code_match(&cc, cc.pos, OP_if_false, -1)) {
|
||||
/* transform typeof(s) != "<type>" if_false into is_<type> if_true */
|
||||
if (cc.line_num >= 0) line_num = cc.line_num;
|
||||
add_pc2line_info(s, bc_out.size, line_num);
|
||||
dbuf_putc(&bc_out, op2);
|
||||
JS_FreeAtom(ctx, cc.atom);
|
||||
pos_next = cc.pos;
|
||||
label = cc.label;
|
||||
op = OP_if_true;
|
||||
goto has_label;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
goto no_change;
|
||||
#endif
|
||||
|
||||
default:
|
||||
no_change:
|
||||
add_pc2line_info(s, bc_out.size, line_num);
|
||||
@@ -25873,7 +25750,6 @@ static __exception int js_parse_directives(JSParseState *s)
|
||||
case TOK_VAR:
|
||||
case TOK_THIS:
|
||||
case TOK_DELETE:
|
||||
case TOK_TYPEOF:
|
||||
case TOK_NEW:
|
||||
case TOK_DO:
|
||||
case TOK_WHILE:
|
||||
|
||||
Reference in New Issue
Block a user