remove with
This commit is contained in:
@@ -191,12 +191,6 @@ DEF( to_object, 1, 1, 1, none)
|
||||
//DEF( to_string, 1, 1, 1, none)
|
||||
DEF( to_propkey, 1, 1, 1, none)
|
||||
|
||||
DEF( with_get_var, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
|
||||
DEF( with_put_var, 10, 2, 1, atom_label_u8) /* must be in the same order as scope_xxx */
|
||||
DEF(with_delete_var, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
|
||||
DEF( with_make_ref, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
|
||||
DEF( with_get_ref, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
|
||||
|
||||
DEF( make_loc_ref, 7, 0, 2, atom_u16)
|
||||
DEF( make_arg_ref, 7, 0, 2, atom_u16)
|
||||
DEF(make_var_ref_ref, 7, 0, 2, atom_u16)
|
||||
|
||||
323
source/quickjs.c
323
source/quickjs.c
@@ -15191,24 +15191,6 @@ static __exception int js_operator_private_in(JSContext *ctx, JSValue *sp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static __exception int js_has_unscopable(JSContext *ctx, JSValueConst obj,
|
||||
JSAtom atom)
|
||||
{
|
||||
JSValue arr, val;
|
||||
int ret;
|
||||
|
||||
arr = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_unscopables);
|
||||
if (JS_IsException(arr))
|
||||
return -1;
|
||||
ret = 0;
|
||||
if (JS_IsObject(arr)) {
|
||||
val = JS_GetProperty(ctx, arr, atom);
|
||||
ret = JS_ToBoolFree(ctx, val);
|
||||
}
|
||||
JS_FreeValue(ctx, arr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __exception int js_operator_instanceof(JSContext *ctx, JSValue *sp)
|
||||
{
|
||||
JSValue op1, op2;
|
||||
@@ -19133,108 +19115,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
}
|
||||
BREAK;
|
||||
#endif
|
||||
CASE(OP_with_get_var):
|
||||
CASE(OP_with_put_var):
|
||||
CASE(OP_with_delete_var):
|
||||
CASE(OP_with_make_ref):
|
||||
CASE(OP_with_get_ref):
|
||||
{
|
||||
JSAtom atom;
|
||||
int32_t diff;
|
||||
JSValue obj, val;
|
||||
int ret, is_with;
|
||||
atom = get_u32(pc);
|
||||
diff = get_u32(pc + 4);
|
||||
is_with = pc[8];
|
||||
pc += 9;
|
||||
sf->cur_pc = pc;
|
||||
|
||||
obj = sp[-1];
|
||||
ret = JS_HasProperty(ctx, obj, atom);
|
||||
if (unlikely(ret < 0))
|
||||
goto exception;
|
||||
if (ret) {
|
||||
if (is_with) {
|
||||
ret = js_has_unscopable(ctx, obj, atom);
|
||||
if (unlikely(ret < 0))
|
||||
goto exception;
|
||||
if (ret)
|
||||
goto no_with;
|
||||
}
|
||||
switch (opcode) {
|
||||
case OP_with_get_var:
|
||||
/* in Object Environment Records, GetBindingValue() calls HasProperty() */
|
||||
ret = JS_HasProperty(ctx, obj, atom);
|
||||
if (unlikely(ret <= 0)) {
|
||||
if (ret < 0)
|
||||
goto exception;
|
||||
if (is_strict_mode(ctx)) {
|
||||
JS_ThrowReferenceErrorNotDefined(ctx, atom);
|
||||
goto exception;
|
||||
}
|
||||
val = JS_UNDEFINED;
|
||||
} else {
|
||||
val = JS_GetProperty(ctx, obj, atom);
|
||||
if (unlikely(JS_IsException(val)))
|
||||
goto exception;
|
||||
}
|
||||
set_value(ctx, &sp[-1], val);
|
||||
break;
|
||||
case OP_with_put_var: /* used e.g. in for in/of */
|
||||
/* in Object Environment Records, SetMutableBinding() calls HasProperty() */
|
||||
ret = JS_HasProperty(ctx, obj, atom);
|
||||
if (unlikely(ret <= 0)) {
|
||||
if (ret < 0)
|
||||
goto exception;
|
||||
if (is_strict_mode(ctx)) {
|
||||
JS_ThrowReferenceErrorNotDefined(ctx, atom);
|
||||
goto exception;
|
||||
}
|
||||
}
|
||||
ret = JS_SetPropertyInternal(ctx, obj, atom, sp[-2], obj,
|
||||
JS_PROP_THROW_STRICT);
|
||||
JS_FreeValue(ctx, sp[-1]);
|
||||
sp -= 2;
|
||||
if (unlikely(ret < 0))
|
||||
goto exception;
|
||||
break;
|
||||
case OP_with_delete_var:
|
||||
ret = JS_DeleteProperty(ctx, obj, atom, 0);
|
||||
if (unlikely(ret < 0))
|
||||
goto exception;
|
||||
JS_FreeValue(ctx, sp[-1]);
|
||||
sp[-1] = JS_NewBool(ctx, ret);
|
||||
break;
|
||||
case OP_with_make_ref:
|
||||
/* produce a pair object/propname on the stack */
|
||||
*sp++ = JS_AtomToValue(ctx, atom);
|
||||
break;
|
||||
case OP_with_get_ref:
|
||||
/* produce a pair object/method on the stack */
|
||||
/* in Object Environment Records, GetBindingValue() calls HasProperty() */
|
||||
ret = JS_HasProperty(ctx, obj, atom);
|
||||
if (unlikely(ret < 0))
|
||||
goto exception;
|
||||
if (!ret) {
|
||||
val = JS_UNDEFINED;
|
||||
} else {
|
||||
val = JS_GetProperty(ctx, obj, atom);
|
||||
if (unlikely(JS_IsException(val)))
|
||||
goto exception;
|
||||
}
|
||||
*sp++ = val;
|
||||
break;
|
||||
}
|
||||
pc += diff - 5;
|
||||
} else {
|
||||
no_with:
|
||||
/* if not jumping, drop the object argument */
|
||||
JS_FreeValue(ctx, sp[-1]);
|
||||
sp--;
|
||||
}
|
||||
}
|
||||
BREAK;
|
||||
|
||||
CASE(OP_await):
|
||||
ret_val = JS_NewInt32(ctx, FUNC_RET_AWAIT);
|
||||
goto done_generator;
|
||||
@@ -28116,36 +27996,6 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
|
||||
if (next_token(s))
|
||||
goto fail;
|
||||
break;
|
||||
case TOK_WITH:
|
||||
if (s->cur_func->js_mode & JS_MODE_STRICT) {
|
||||
js_parse_error(s, "invalid keyword: with");
|
||||
goto fail;
|
||||
} else {
|
||||
int with_idx;
|
||||
|
||||
if (next_token(s))
|
||||
goto fail;
|
||||
|
||||
if (js_parse_expr_paren(s))
|
||||
goto fail;
|
||||
|
||||
push_scope(s);
|
||||
with_idx = define_var(s, s->cur_func, JS_ATOM__with_,
|
||||
JS_VAR_DEF_WITH);
|
||||
if (with_idx < 0)
|
||||
goto fail;
|
||||
emit_op(s, OP_to_object);
|
||||
emit_op(s, OP_put_loc);
|
||||
emit_u16(s, with_idx);
|
||||
|
||||
set_eval_ret_undefined(s);
|
||||
if (js_parse_statement(s))
|
||||
goto fail;
|
||||
|
||||
/* Popping scope drops lexical context for the with object variable */
|
||||
pop_scope(s);
|
||||
}
|
||||
break;
|
||||
case TOK_FUNCTION:
|
||||
/* ES6 Annex B.3.2 and B.3.3 semantics */
|
||||
if (!(decl_mask & DECL_MASK_FUNC))
|
||||
@@ -30170,76 +30020,6 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)
|
||||
return JS_DupValue(ctx, m->promise);
|
||||
}
|
||||
|
||||
static __exception int js_parse_with_clause(JSParseState *s, JSReqModuleEntry *rme)
|
||||
{
|
||||
JSContext *ctx = s->ctx;
|
||||
JSAtom key;
|
||||
int ret;
|
||||
const uint8_t *key_token_ptr;
|
||||
|
||||
if (next_token(s))
|
||||
return -1;
|
||||
if (js_parse_expect(s, '{'))
|
||||
return -1;
|
||||
while (s->token.val != '}') {
|
||||
key_token_ptr = s->token.ptr;
|
||||
if (s->token.val == TOK_STRING) {
|
||||
key = JS_ValueToAtom(ctx, s->token.u.str.str);
|
||||
if (key == JS_ATOM_NULL)
|
||||
return -1;
|
||||
} else {
|
||||
if (!token_is_ident(s->token.val)) {
|
||||
js_parse_error(s, "identifier expected");
|
||||
return -1;
|
||||
}
|
||||
key = JS_DupAtom(ctx, s->token.u.ident.atom);
|
||||
}
|
||||
if (next_token(s))
|
||||
return -1;
|
||||
if (js_parse_expect(s, ':')) {
|
||||
JS_FreeAtom(ctx, key);
|
||||
return -1;
|
||||
}
|
||||
if (s->token.val != TOK_STRING) {
|
||||
js_parse_error_pos(s, key_token_ptr, "string expected");
|
||||
return -1;
|
||||
}
|
||||
if (JS_IsUndefined(rme->attributes)) {
|
||||
JSValue attributes = JS_NewObjectProto(ctx, JS_NULL);
|
||||
if (JS_IsException(attributes)) {
|
||||
JS_FreeAtom(ctx, key);
|
||||
return -1;
|
||||
}
|
||||
rme->attributes = attributes;
|
||||
}
|
||||
ret = JS_HasProperty(ctx, rme->attributes, key);
|
||||
if (ret != 0) {
|
||||
JS_FreeAtom(ctx, key);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
else
|
||||
return js_parse_error(s, "duplicate with key");
|
||||
}
|
||||
ret = JS_DefinePropertyValue(ctx, rme->attributes, key,
|
||||
JS_DupValue(ctx, s->token.u.str.str), JS_PROP_C_W_E);
|
||||
JS_FreeAtom(ctx, key);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
if (next_token(s))
|
||||
return -1;
|
||||
if (s->token.val != ',')
|
||||
break;
|
||||
if (next_token(s))
|
||||
return -1;
|
||||
}
|
||||
if (!JS_IsUndefined(rme->attributes) &&
|
||||
ctx->rt->module_check_attrs &&
|
||||
ctx->rt->module_check_attrs(ctx, ctx->rt->module_loader_opaque, rme->attributes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
return js_parse_expect(s, '}');
|
||||
}
|
||||
|
||||
/* return the module index in m->req_module_entries[] or < 0 if error */
|
||||
static __exception int js_parse_from_clause(JSParseState *s, JSModuleDef *m)
|
||||
{
|
||||
@@ -30268,10 +30048,6 @@ static __exception int js_parse_from_clause(JSParseState *s, JSModuleDef *m)
|
||||
JS_FreeAtom(s->ctx, module_name);
|
||||
if (idx < 0)
|
||||
return -1;
|
||||
if (s->token.val == TOK_WITH) {
|
||||
if (js_parse_with_clause(s, &m->req_module_entries[idx]))
|
||||
return -1;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
@@ -30497,10 +30273,6 @@ static __exception int js_parse_import(JSParseState *s)
|
||||
JS_FreeAtom(ctx, module_name);
|
||||
if (idx < 0)
|
||||
return -1;
|
||||
if (s->token.val == TOK_WITH) {
|
||||
if (js_parse_with_clause(s, &m->req_module_entries[idx]))
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (s->token.val == TOK_IDENT) {
|
||||
if (s->token.u.ident.is_reserved) {
|
||||
@@ -31315,14 +31087,6 @@ static int get_closure_var(JSContext *ctx, JSFunctionDef *s,
|
||||
var_kind);
|
||||
}
|
||||
|
||||
static int get_with_scope_opcode(int op)
|
||||
{
|
||||
if (op == OP_scope_get_var_undef)
|
||||
return OP_with_get_var;
|
||||
else
|
||||
return OP_with_get_var + (op - OP_scope_get_var);
|
||||
}
|
||||
|
||||
static BOOL can_opt_put_ref_value(const uint8_t *bc_buf, int pos)
|
||||
{
|
||||
int opcode = bc_buf[pos];
|
||||
@@ -31514,19 +31278,8 @@ static void var_object_test(JSContext *ctx, JSFunctionDef *s,
|
||||
JSAtom var_name, int op, DynBuf *bc,
|
||||
int *plabel_done, BOOL is_with)
|
||||
{
|
||||
dbuf_putc(bc, get_with_scope_opcode(op));
|
||||
dbuf_putc(bc, op);
|
||||
dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));
|
||||
if (*plabel_done < 0) {
|
||||
*plabel_done = new_label_fd(s);
|
||||
if (*plabel_done < 0) {
|
||||
dbuf_set_error(bc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
dbuf_put_u32(bc, *plabel_done);
|
||||
dbuf_putc(bc, is_with);
|
||||
update_label(s, *plabel_done, 1);
|
||||
s->jump_size++;
|
||||
}
|
||||
|
||||
/* return the position of the next opcode */
|
||||
@@ -31565,11 +31318,6 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
|
||||
}
|
||||
var_idx = idx;
|
||||
break;
|
||||
} else
|
||||
if (vd->var_name == JS_ATOM__with_ && !is_pseudo_var) {
|
||||
dbuf_putc(bc, OP_get_loc);
|
||||
dbuf_put_u16(bc, idx);
|
||||
var_object_test(ctx, s, var_name, op, bc, &label_done, 1);
|
||||
}
|
||||
idx = vd->scope_next;
|
||||
}
|
||||
@@ -31726,14 +31474,6 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
|
||||
}
|
||||
var_idx = idx;
|
||||
break;
|
||||
} else if (vd->var_name == JS_ATOM__with_ && !is_pseudo_var) {
|
||||
vd->is_captured = 1;
|
||||
idx = get_closure_var(ctx, s, fd, FALSE, idx, vd->var_name, FALSE, FALSE, JS_VAR_NORMAL);
|
||||
if (idx >= 0) {
|
||||
dbuf_putc(bc, OP_get_var_ref);
|
||||
dbuf_put_u16(bc, idx);
|
||||
var_object_test(ctx, s, var_name, op, bc, &label_done, 1);
|
||||
}
|
||||
}
|
||||
idx = vd->scope_next;
|
||||
}
|
||||
@@ -31809,9 +31549,7 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
|
||||
}
|
||||
goto has_idx;
|
||||
} else if ((cv->var_name == JS_ATOM__var_ ||
|
||||
cv->var_name == JS_ATOM__arg_var_ ||
|
||||
cv->var_name == JS_ATOM__with_) && !is_pseudo_var) {
|
||||
int is_with = (cv->var_name == JS_ATOM__with_);
|
||||
cv->var_name == JS_ATOM__arg_var_) && !is_pseudo_var) {
|
||||
if (fd != s) {
|
||||
idx = get_closure_var2(ctx, s, fd,
|
||||
FALSE,
|
||||
@@ -31823,7 +31561,7 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
|
||||
}
|
||||
dbuf_putc(bc, OP_get_var_ref);
|
||||
dbuf_put_u16(bc, idx);
|
||||
var_object_test(ctx, s, var_name, op, bc, &label_done, is_with);
|
||||
var_object_test(ctx, s, var_name, op, bc, &label_done, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33661,43 +33399,6 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s)
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case OP_with_get_var:
|
||||
case OP_with_put_var:
|
||||
case OP_with_delete_var:
|
||||
case OP_with_make_ref:
|
||||
case OP_with_get_ref:
|
||||
{
|
||||
JSAtom atom;
|
||||
int is_with;
|
||||
|
||||
atom = get_u32(bc_buf + pos + 1);
|
||||
label = get_u32(bc_buf + pos + 5);
|
||||
is_with = bc_buf[pos + 9];
|
||||
if (OPTIMIZE) {
|
||||
label = find_jump_target(s, label, &op1, NULL);
|
||||
}
|
||||
assert(label >= 0 && label < s->label_count);
|
||||
ls = &label_slots[label];
|
||||
add_pc2line_info(s, bc_out.size, line_num);
|
||||
#if SHORT_OPCODES
|
||||
jp = &s->jump_slots[s->jump_count++];
|
||||
jp->op = op;
|
||||
jp->size = 4;
|
||||
jp->pos = bc_out.size + 5;
|
||||
jp->label = label;
|
||||
#endif
|
||||
dbuf_putc(&bc_out, op);
|
||||
dbuf_put_u32(&bc_out, atom);
|
||||
dbuf_put_u32(&bc_out, ls->addr - bc_out.size);
|
||||
if (ls->addr == -1) {
|
||||
/* unresolved yet: create a new relocation entry */
|
||||
if (!add_reloc(ctx, ls, bc_out.size - 4, 4))
|
||||
goto fail;
|
||||
}
|
||||
dbuf_putc(&bc_out, is_with);
|
||||
}
|
||||
break;
|
||||
|
||||
case OP_drop:
|
||||
if (OPTIMIZE) {
|
||||
/* remove useless drops before return */
|
||||
@@ -34431,23 +34132,6 @@ static __exception int compute_stack_size(JSContext *ctx,
|
||||
if (ss_check(ctx, s, pos + 1 + diff, op, stack_len + 1, catch_pos))
|
||||
goto fail;
|
||||
break;
|
||||
case OP_with_get_var:
|
||||
case OP_with_delete_var:
|
||||
diff = get_u32(bc_buf + pos + 5);
|
||||
if (ss_check(ctx, s, pos + 5 + diff, op, stack_len + 1, catch_pos))
|
||||
goto fail;
|
||||
break;
|
||||
case OP_with_make_ref:
|
||||
case OP_with_get_ref:
|
||||
diff = get_u32(bc_buf + pos + 5);
|
||||
if (ss_check(ctx, s, pos + 5 + diff, op, stack_len + 2, catch_pos))
|
||||
goto fail;
|
||||
break;
|
||||
case OP_with_put_var:
|
||||
diff = get_u32(bc_buf + pos + 5);
|
||||
if (ss_check(ctx, s, pos + 5 + diff, op, stack_len - 1, catch_pos))
|
||||
goto fail;
|
||||
break;
|
||||
case OP_catch:
|
||||
diff = get_u32(bc_buf + pos + 1);
|
||||
if (ss_check(ctx, s, pos + 1 + diff, op, stack_len, catch_pos))
|
||||
@@ -34877,7 +34561,6 @@ static __exception int js_parse_directives(JSParseState *s)
|
||||
case TOK_TRY:
|
||||
case TOK_FUNCTION:
|
||||
case TOK_DEBUGGER:
|
||||
case TOK_WITH:
|
||||
case TOK_CLASS:
|
||||
case TOK_CONST:
|
||||
case TOK_ENUM:
|
||||
|
||||
Reference in New Issue
Block a user