diff --git a/meson.build b/meson.build index c88eab2f..c414d03c 100644 --- a/meson.build +++ b/meson.build @@ -161,7 +161,6 @@ else endif endif -# Try to find system-installed qjs-layout first miniz_dep = dependency('miniz', static: true, required: false) if not miniz_dep.found() message('⚙ System miniz not found, building subproject...') diff --git a/source/quickjs-opcode.h b/source/quickjs-opcode.h index 3f070f05..e267402a 100644 --- a/source/quickjs-opcode.h +++ b/source/quickjs-opcode.h @@ -107,18 +107,12 @@ DEF( array_from, 3, 0, 1, npop) /* arguments are not counted in n_pop */ DEF( apply, 3, 3, 1, u16) DEF( return, 1, 1, 0, none) DEF( return_undef, 1, 0, 0, none) -DEF(check_ctor_return, 1, 1, 2, none) -DEF( check_ctor, 1, 0, 0, none) -DEF( init_ctor, 1, 0, 1, none) -DEF( check_brand, 1, 2, 2, none) /* this_obj func -> this_obj func */ -DEF( add_brand, 1, 2, 0, none) /* this_obj home_obj -> */ DEF( throw, 1, 1, 0, none) DEF( throw_error, 6, 0, 0, atom_u8) DEF( eval, 5, 1, 1, npop_u16) /* func args... -> ret_val */ DEF( apply_eval, 3, 2, 1, u16) /* func array -> ret_eval */ DEF( regexp, 1, 2, 1, none) /* create a RegExp object from the pattern and a bytecode string */ -DEF( get_super, 1, 1, 1, none) DEF( check_var, 5, 0, 1, atom) /* check if a variable exists */ DEF( get_var_undef, 5, 0, 1, atom) /* push undefined if the variable does not exist */ @@ -143,13 +137,10 @@ DEF( get_array_el, 1, 2, 1, none) DEF( get_array_el2, 1, 2, 2, none) /* obj prop -> obj value */ DEF( get_array_el3, 1, 2, 3, none) /* obj prop -> obj prop1 value */ DEF( put_array_el, 1, 3, 0, none) -DEF(get_super_value, 1, 3, 1, none) /* this obj prop -> value */ -DEF(put_super_value, 1, 4, 0, none) /* this obj prop value -> */ DEF( define_field, 5, 2, 1, atom) DEF( set_name, 5, 1, 1, atom) DEF(set_name_computed, 1, 2, 2, none) DEF( set_proto, 1, 2, 1, none) -DEF(set_home_object, 1, 2, 2, none) DEF(define_array_el, 1, 3, 2, none) DEF( append, 1, 3, 2, none) /* append enumerated object, update length */ DEF(copy_data_properties, 2, 3, 3, u8) @@ -248,7 +239,6 @@ DEF( and, 1, 2, 1, none) DEF( xor, 1, 2, 1, none) DEF( or, 1, 2, 1, none) DEF(is_undefined_or_null, 1, 1, 1, none) -DEF( private_in, 1, 2, 1, none) DEF(push_bigint_i32, 5, 0, 1, i32) /* must be the last non short and non temporary opcode */ DEF( nop, 1, 0, 0, none) diff --git a/source/quickjs.c b/source/quickjs.c index 98172446..60420444 100644 --- a/source/quickjs.c +++ b/source/quickjs.c @@ -548,7 +548,6 @@ typedef struct JSVarDef { uint8_t is_const : 1; uint8_t is_lexical : 1; uint8_t is_captured : 1; - uint8_t is_static_private : 1; /* only used during private class field parsing */ uint8_t var_kind : 4; /* see JSVarKindEnum */ /* only used during compilation: function pool index for lexical variables with var_kind = @@ -572,12 +571,8 @@ typedef struct JSFunctionBytecode { uint8_t has_prototype : 1; /* true if a prototype field is necessary */ uint8_t has_simple_parameter_list : 1; uint8_t is_derived_class_constructor : 1; - /* true if home_object needs to be initialized */ - uint8_t need_home_object : 1; uint8_t func_kind : 2; uint8_t new_target_allowed : 1; - uint8_t super_call_allowed : 1; - uint8_t super_allowed : 1; uint8_t arguments_allowed : 1; uint8_t has_debug : 1; uint8_t read_only_bytecode : 1; @@ -793,7 +788,6 @@ struct JSObject { struct { /* JS_CLASS_BYTECODE_FUNCTION: 12/24 bytes */ struct JSFunctionBytecode *function_bytecode; JSVarRef **var_refs; - JSObject *home_object; /* for 'super' access */ } func; struct { /* JS_CLASS_C_FUNCTION: 12/20 bytes */ JSContext *realm; @@ -4959,31 +4953,6 @@ static JSFunctionBytecode *JS_GetFunctionBytecode(JSValueConst val) return p->u.func.function_bytecode; } -static void js_method_set_home_object(JSContext *ctx, JSValueConst func_obj, - JSValueConst home_obj) -{ - JSObject *p, *p1; - JSFunctionBytecode *b; - - if (JS_VALUE_GET_TAG(func_obj) != JS_TAG_OBJECT) - return; - p = JS_VALUE_GET_OBJ(func_obj); - if (!js_class_has_bytecode(p->class_id)) - return; - b = p->u.func.function_bytecode; - if (b->need_home_object) { - p1 = p->u.func.home_object; - if (p1) { - JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p1)); - } - if (JS_VALUE_GET_TAG(home_obj) == JS_TAG_OBJECT) - p1 = JS_VALUE_GET_OBJ(JS_DupValue(ctx, home_obj)); - else - p1 = NULL; - p->u.func.home_object = p1; - } -} - static JSValue js_get_function_name(JSContext *ctx, JSAtom name) { JSValue name_str; @@ -5015,7 +4984,6 @@ static int js_method_set_properties(JSContext *ctx, JSValueConst func_obj, if (JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_name, name_str, JS_PROP_CONFIGURABLE) < 0) return -1; - js_method_set_home_object(ctx, func_obj, home_obj); return 0; } @@ -5307,15 +5275,11 @@ static void js_c_function_mark(JSRuntime *rt, JSValueConst val, static void js_bytecode_function_finalizer(JSRuntime *rt, JSValue val) { - JSObject *p1, *p = JS_VALUE_GET_OBJ(val); + JSObject *p = JS_VALUE_GET_OBJ(val); JSFunctionBytecode *b; JSVarRef **var_refs; int i; - p1 = p->u.func.home_object; - if (p1) { - JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, p1)); - } b = p->u.func.function_bytecode; if (b) { var_refs = p->u.func.var_refs; @@ -5336,10 +5300,6 @@ static void js_bytecode_function_mark(JSRuntime *rt, JSValueConst val, JSFunctionBytecode *b = p->u.func.function_bytecode; int i; - if (p->u.func.home_object) { - JS_MarkValue(rt, JS_MKPTR(JS_TAG_OBJECT, p->u.func.home_object), - mark_func); - } if (b) { if (var_refs) { for(i = 0; i < b->closure_var_count; i++) { @@ -5439,7 +5399,6 @@ static void free_object(JSRuntime *rt, JSObject *p) p->class_id = 0; p->u.opaque = NULL; p->u.func.var_refs = NULL; - p->u.func.home_object = NULL; remove_gc_object(&p->header); if (rt->gc_phase == JS_GC_PHASE_REMOVE_CYCLES) { @@ -7381,96 +7340,6 @@ static int JS_SetPrivateField(JSContext *ctx, JSValueConst obj, return 0; } -/* add a private brand field to 'home_obj' if not already present and - if obj is != null add a private brand to it */ -static int JS_AddBrand(JSContext *ctx, JSValueConst obj, JSValueConst home_obj) -{ - JSObject *p, *p1; - JSShapeProperty *prs; - JSProperty *pr; - JSValue brand; - JSAtom brand_atom; - - if (unlikely(JS_VALUE_GET_TAG(home_obj) != JS_TAG_OBJECT)) { - JS_ThrowTypeErrorNotAnObject(ctx); - return -1; - } - p = JS_VALUE_GET_OBJ(home_obj); - prs = find_own_property(&pr, p, JS_ATOM_Private_brand); - if (!prs) { - /* if the brand is not present, add it */ - brand = JS_NewSymbolFromAtom(ctx, JS_ATOM_brand, JS_ATOM_TYPE_PRIVATE); - if (JS_IsException(brand)) - return -1; - pr = add_property(ctx, p, JS_ATOM_Private_brand, JS_PROP_C_W_E); - if (!pr) { - JS_FreeValue(ctx, brand); - return -1; - } - pr->u.value = JS_DupValue(ctx, brand); - } else { - brand = JS_DupValue(ctx, pr->u.value); - } - brand_atom = js_symbol_to_atom(ctx, brand); - - if (JS_IsObject(obj)) { - p1 = JS_VALUE_GET_OBJ(obj); - prs = find_own_property(&pr, p1, brand_atom); - if (unlikely(prs)) { - JS_FreeAtom(ctx, brand_atom); - JS_ThrowTypeError(ctx, "private method is already present"); - return -1; - } - pr = add_property(ctx, p1, brand_atom, JS_PROP_C_W_E); - JS_FreeAtom(ctx, brand_atom); - if (!pr) - return -1; - pr->u.value = JS_UNDEFINED; - } else { - JS_FreeAtom(ctx, brand_atom); - } - return 0; -} - -/* return a boolean telling if the brand of the home object of 'func' - is present on 'obj' or -1 in case of exception */ -static int JS_CheckBrand(JSContext *ctx, JSValueConst obj, JSValueConst func) -{ - JSObject *p, *p1, *home_obj; - JSShapeProperty *prs; - JSProperty *pr; - JSValueConst brand; - - /* get the home object of 'func' */ - if (unlikely(JS_VALUE_GET_TAG(func) != JS_TAG_OBJECT)) - goto not_obj; - p1 = JS_VALUE_GET_OBJ(func); - if (!js_class_has_bytecode(p1->class_id)) - goto not_obj; - home_obj = p1->u.func.home_object; - if (!home_obj) - goto not_obj; - prs = find_own_property(&pr, home_obj, JS_ATOM_Private_brand); - if (!prs) { - JS_ThrowTypeError(ctx, "expecting private field"); - return -1; - } - brand = pr->u.value; - /* safety check */ - if (unlikely(JS_VALUE_GET_TAG(brand) != JS_TAG_SYMBOL)) - goto not_obj; - - /* get the brand array of 'obj' */ - if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)) { - not_obj: - JS_ThrowTypeErrorNotAnObject(ctx); - return -1; - } - p = JS_VALUE_GET_OBJ(obj); - prs = find_own_property(&pr, p, js_symbol_to_atom(ctx, (JSValue)brand)); - return (prs != NULL); -} - static uint32_t js_string_obj_get_length(JSContext *ctx, JSValueConst obj) { @@ -13064,11 +12933,6 @@ static void js_print_object(JSPrintValueState *s, JSObject *p) } js_printf(s, " ]"); } - if (p->u.func.home_object) { - js_print_comma(s, &comma_state); - js_printf(s, "[[HomeObject]]: "); - js_print_value(s, JS_MKPTR(JS_TAG_OBJECT, p->u.func.home_object)); - } } if (!is_array) { @@ -14759,43 +14623,6 @@ static __exception int js_operator_in(JSContext *ctx, JSValue *sp) return 0; } -static __exception int js_operator_private_in(JSContext *ctx, JSValue *sp) -{ - JSValue op1, op2; - int ret; - - op1 = sp[-2]; /* object */ - op2 = sp[-1]; /* field name or method function */ - - if (JS_VALUE_GET_TAG(op1) != JS_TAG_OBJECT) { - JS_ThrowTypeError(ctx, "invalid 'in' operand"); - return -1; - } - if (JS_IsObject(op2)) { - /* method: use the brand */ - ret = JS_CheckBrand(ctx, op1, op2); - if (ret < 0) - return -1; - } else { - JSAtom atom; - JSObject *p; - JSShapeProperty *prs; - JSProperty *pr; - /* field */ - atom = JS_ValueToAtom(ctx, op2); - if (unlikely(atom == JS_ATOM_NULL)) - return -1; - p = JS_VALUE_GET_OBJ(op1); - prs = find_own_property(&pr, p, atom); - JS_FreeAtom(ctx, atom); - ret = (prs != NULL); - } - JS_FreeValue(ctx, op1); - JS_FreeValue(ctx, op2); - sp[-2] = JS_NewBool(ctx, ret); - return 0; -} - static __exception int js_has_unscopable(JSContext *ctx, JSValueConst obj, JSAtom atom) { @@ -15818,7 +15645,6 @@ static JSValue js_closure2(JSContext *ctx, JSValue func_obj, p = JS_VALUE_GET_OBJ(func_obj); p->u.func.function_bytecode = b; - p->u.func.home_object = NULL; p->u.func.var_refs = NULL; if (b->closure_var_count) { var_refs = js_mallocz(ctx, sizeof(var_refs[0]) * b->closure_var_count); @@ -15958,7 +15784,7 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, bfunc = JS_UNDEFINED; if (JS_IsException(ctor)) goto fail; - js_method_set_home_object(ctx, ctor, proto); + JS_SetConstructorBit(ctx, ctor, TRUE); JS_DefinePropertyValue(ctx, ctor, JS_ATOM_length, @@ -16223,7 +16049,6 @@ typedef enum { OP_SPECIAL_OBJECT_MAPPED_ARGUMENTS, OP_SPECIAL_OBJECT_THIS_FUNC, OP_SPECIAL_OBJECT_NEW_TARGET, - OP_SPECIAL_OBJECT_HOME_OBJECT, OP_SPECIAL_OBJECT_VAR_OBJECT, } OPSpecialObjectEnum; @@ -16457,16 +16282,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, case OP_SPECIAL_OBJECT_NEW_TARGET: *sp++ = JS_DupValue(ctx, new_target); break; - case OP_SPECIAL_OBJECT_HOME_OBJECT: - { - JSObject *p1; - p1 = p->u.func.home_object; - if (unlikely(!p1)) - *sp++ = JS_UNDEFINED; - else - *sp++ = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p1)); - } - break; case OP_SPECIAL_OBJECT_VAR_OBJECT: *sp++ = JS_NewObjectProto(ctx, JS_NULL); if (unlikely(JS_IsException(sp[-1]))) @@ -16751,61 +16566,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, ret_val = JS_UNDEFINED; goto done; - CASE(OP_check_ctor_return): - /* return TRUE if 'this' should be returned */ - if (!JS_IsObject(sp[-1])) { - if (!JS_IsUndefined(sp[-1])) { - JS_ThrowTypeError(caller_ctx, "derived class constructor must return an object or undefined"); - goto exception; - } - sp[0] = JS_TRUE; - } else { - sp[0] = JS_FALSE; - } - sp++; - BREAK; - CASE(OP_check_ctor): - if (JS_IsUndefined(new_target)) { - non_ctor_call: - JS_ThrowTypeError(ctx, "class constructors must be invoked with 'new'"); - goto exception; - } - BREAK; - CASE(OP_init_ctor): - { - JSValue super, ret; - sf->cur_pc = pc; - if (JS_IsUndefined(new_target)) - goto non_ctor_call; - super = JS_GetPrototype(ctx, func_obj); - if (JS_IsException(super)) - goto exception; - ret = JS_CallConstructor2(ctx, super, new_target, argc, (JSValueConst *)argv); - JS_FreeValue(ctx, super); - if (JS_IsException(ret)) - goto exception; - *sp++ = ret; - } - BREAK; - CASE(OP_check_brand): - { - int ret = JS_CheckBrand(ctx, sp[-2], sp[-1]); - if (ret < 0) - goto exception; - if (!ret) { - JS_ThrowTypeError(ctx, "invalid brand on object"); - goto exception; - } - } - BREAK; - CASE(OP_add_brand): - if (JS_AddBrand(ctx, sp[-2], sp[-1]) < 0) - goto exception; - JS_FreeValue(ctx, sp[-2]); - JS_FreeValue(ctx, sp[-1]); - sp -= 2; - BREAK; - CASE(OP_throw): JS_Throw(ctx, *--sp); goto exception; @@ -16814,7 +16574,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, #define JS_THROW_VAR_RO 0 #define JS_THROW_VAR_REDECL 1 #define JS_THROW_VAR_UNINITIALIZED 2 -#define JS_THROW_ERROR_DELETE_SUPER 3 #define JS_THROW_ERROR_ITERATOR_THROW 4 { JSAtom atom; @@ -16831,9 +16590,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (type == JS_THROW_VAR_UNINITIALIZED) JS_ThrowReferenceErrorUninitialized(ctx, atom); else - if (type == JS_THROW_ERROR_DELETE_SUPER) - JS_ThrowReferenceError(ctx, "unsupported reference to 'super'"); - else if (type == JS_THROW_ERROR_ITERATOR_THROW) JS_ThrowTypeError(ctx, "iterator does not have a throw method"); else @@ -16912,18 +16668,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } BREAK; - CASE(OP_get_super): - { - JSValue proto; - sf->cur_pc = pc; - proto = JS_GetPrototype(ctx, sp[-1]); - if (JS_IsException(proto)) - goto exception; - JS_FreeValue(ctx, sp[-1]); - sp[-1] = proto; - } - BREAK; - CASE(OP_check_var): { int ret; @@ -17714,9 +17458,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp--; } BREAK; - CASE(OP_set_home_object): - js_method_set_home_object(ctx, sp[-1], sp[-2]); - BREAK; CASE(OP_define_method): CASE(OP_define_method_computed): { @@ -17889,26 +17630,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } BREAK; - CASE(OP_get_super_value): - { - JSValue val; - JSAtom atom; - sf->cur_pc = pc; - atom = JS_ValueToAtom(ctx, sp[-1]); - if (unlikely(atom == JS_ATOM_NULL)) - goto exception; - val = JS_GetPropertyInternal(ctx, sp[-2], atom, sp[-3], FALSE); - JS_FreeAtom(ctx, atom); - if (unlikely(JS_IsException(val))) - goto exception; - JS_FreeValue(ctx, sp[-1]); - JS_FreeValue(ctx, sp[-2]); - JS_FreeValue(ctx, sp[-3]); - sp[-3] = val; - sp -= 2; - } - BREAK; - CASE(OP_put_array_el): { int ret; @@ -17961,30 +17682,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } BREAK; - CASE(OP_put_super_value): - { - int ret; - JSAtom atom; - sf->cur_pc = pc; - if (JS_VALUE_GET_TAG(sp[-3]) != JS_TAG_OBJECT) { - JS_ThrowTypeErrorNotAnObject(ctx); - goto exception; - } - atom = JS_ValueToAtom(ctx, sp[-2]); - if (unlikely(atom == JS_ATOM_NULL)) - goto exception; - ret = JS_SetPropertyInternal(ctx, sp[-3], atom, sp[-1], sp[-4], - JS_PROP_THROW_STRICT); - JS_FreeAtom(ctx, atom); - JS_FreeValue(ctx, sp[-4]); - JS_FreeValue(ctx, sp[-3]); - JS_FreeValue(ctx, sp[-2]); - sp -= 4; - if (ret < 0) - goto exception; - } - BREAK; - CASE(OP_define_array_el): { int ret; @@ -18505,12 +18202,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, goto exception; sp--; BREAK; - CASE(OP_private_in): - sf->cur_pc = pc; - if (js_operator_private_in(ctx, sp)) - goto exception; - sp--; - BREAK; CASE(OP_instanceof): sf->cur_pc = pc; if (js_operator_instanceof(ctx, sp)) @@ -19157,7 +18848,6 @@ typedef struct JSFunctionDef { BOOL is_global_var; /* TRUE if variables are not defined locally: eval global, eval module or non strict eval */ BOOL is_func_expr; /* TRUE if function expression */ - BOOL has_home_object; /* TRUE if the home object is available */ BOOL has_prototype; /* true if a prototype field is necessary */ BOOL has_simple_parameter_list; BOOL has_parameter_expressions; /* if true, an argument scope is created */ @@ -19169,8 +18859,6 @@ typedef struct JSFunctionDef { available in the function */ BOOL new_target_allowed; /* true if the 'new.target' does not throw a syntax error */ - BOOL super_call_allowed; /* true if super() is allowed */ - BOOL super_allowed; /* true if super. or super[] is allowed */ BOOL arguments_allowed; /* true if the 'arguments' identifier is allowed */ BOOL is_derived_class_constructor; BOOL in_function_body; @@ -19196,8 +18884,6 @@ typedef struct JSFunctionDef { int this_var_idx; /* variable containg the 'this' value, -1 if none */ int new_target_var_idx; /* variable containg the 'new.target' value, -1 if none */ int this_active_func_var_idx; /* variable containg the 'this.active_func' value, -1 if none */ - int home_object_var_idx; - BOOL need_home_object; int scope_level; /* index into fd->scopes if the current lexical scope */ int scope_first; /* index into vd->vars of first lexically scoped variable */ @@ -19347,7 +19033,6 @@ static void free_token(JSParseState *s, JSToken *token) JS_FreeValue(s->ctx, token->u.regexp.flags); break; case TOK_IDENT: - case TOK_PRIVATE_NAME: JS_FreeAtom(s->ctx, token->u.ident.atom); break; default: @@ -20115,31 +19800,6 @@ static __exception int next_token(JSParseState *s) s->token.val = TOK_IDENT; update_token_ident(s); break; - case '#': - /* private name */ - { - const uint8_t *p1; - p++; - p1 = p; - c = *p1++; - if (c == '\\' && *p1 == 'u') { - c = lre_parse_escape(&p1, TRUE); - } else if (c >= 128) { - c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p1); - } - if (!lre_js_is_ident_first(c)) { - js_parse_error(s, "invalid first character of private name"); - goto fail; - } - p = p1; - ident_has_escape = FALSE; /* not used */ - atom = parse_ident(s, &p, &ident_has_escape, c, TRUE); - if (atom == JS_ATOM_NULL) - goto fail; - s->token.u.ident.atom = atom; - s->token.val = TOK_PRIVATE_NAME; - } - break; case '.': if (p[1] == '.' && p[2] == '.') { p += 3; @@ -21513,24 +21173,6 @@ static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name, return idx; } -/* add a private field variable in the current scope */ -static int add_private_class_field(JSParseState *s, JSFunctionDef *fd, - JSAtom name, JSVarKindEnum var_kind, BOOL is_static) -{ - JSContext *ctx = s->ctx; - JSVarDef *vd; - int idx; - - idx = add_scope_var(ctx, fd, name, var_kind); - if (idx < 0) - return idx; - vd = &fd->vars[idx]; - vd->is_lexical = 1; - vd->is_const = 1; - vd->is_static_private = is_static; - return idx; -} - static __exception int js_parse_expr(JSParseState *s); static __exception int js_parse_function_decl(JSParseState *s, JSParseFunctionEnum func_type, @@ -21765,11 +21407,6 @@ static int __exception js_parse_property_name(JSParseState *s, if (js_parse_expect(s, ']')) goto fail; name = JS_ATOM_NULL; - } else if (s->token.val == TOK_PRIVATE_NAME && allow_private) { - name = JS_DupAtom(s->ctx, s->token.u.ident.atom); - if (next_token(s)) - goto fail1; - is_private = PROP_TYPE_PRIVATE; } else { goto invalid_prop; } @@ -22150,12 +21787,6 @@ static __exception int js_parse_left_hand_side_expr(JSParseState *s) return js_parse_postfix_expr(s, PF_POSTFIX_CALL); } -/* build a private setter function name from the private getter name */ -static JSAtom get_private_setter_name(JSContext *ctx, JSAtom name) -{ - return js_atom_concat_str(ctx, name, ""); -} - static __exception int js_parse_array_literal(JSParseState *s) { uint32_t idx; @@ -22332,17 +21963,9 @@ static __exception int get_lvalue(JSParseState *s, int *popcode, int *pscope, name = get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1); depth = 1; break; - case OP_scope_get_private_field: - name = get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1); - scope = get_u16(fd->byte_code.buf + fd->last_opcode_pos + 5); - depth = 1; - break; case OP_get_array_el: depth = 2; break; - case OP_get_super_value: - depth = 3; - break; default: invalid_lvalue: if (tok == TOK_FOR) { @@ -22378,19 +22001,9 @@ static __exception int get_lvalue(JSParseState *s, int *popcode, int *pscope, emit_op(s, OP_get_field2); emit_atom(s, name); break; - case OP_scope_get_private_field: - emit_op(s, OP_scope_get_private_field2); - emit_atom(s, name); - emit_u16(s, scope); - break; case OP_get_array_el: emit_op(s, OP_get_array_el3); break; - case OP_get_super_value: - emit_op(s, OP_to_propkey); - emit_op(s, OP_dup3); - emit_op(s, OP_get_super_value); - break; default: abort(); } @@ -22440,7 +22053,6 @@ static void put_lvalue(JSParseState *s, int opcode, int scope, { switch(opcode) { case OP_get_field: - case OP_scope_get_private_field: /* depth = 1 */ switch(special) { case PUT_LVALUE_NOKEEP: @@ -22485,25 +22097,6 @@ static void put_lvalue(JSParseState *s, int opcode, int scope, abort(); } break; - case OP_get_super_value: - /* depth = 3 */ - switch(special) { - case PUT_LVALUE_NOKEEP: - case PUT_LVALUE_NOKEEP_DEPTH: - break; - case PUT_LVALUE_KEEP_TOP: - emit_op(s, OP_insert4); /* this obj prop v -> v this obj prop v */ - break; - case PUT_LVALUE_KEEP_SECOND: - emit_op(s, OP_perm5); /* this obj prop v0 v -> v0 this obj prop v */ - break; - case PUT_LVALUE_NOKEEP_BOTTOM: - emit_op(s, OP_rot4l); - break; - default: - abort(); - } - break; default: break; } @@ -22520,20 +22113,12 @@ static void put_lvalue(JSParseState *s, int opcode, int scope, emit_op(s, OP_put_field); emit_u32(s, name); /* name has refcount */ break; - case OP_scope_get_private_field: - emit_op(s, OP_scope_put_private_field); - emit_u32(s, name); /* name has refcount */ - emit_u16(s, scope); - break; case OP_get_array_el: emit_op(s, OP_put_array_el); break; case OP_get_ref_value: emit_op(s, OP_put_ref_value); break; - case OP_get_super_value: - emit_op(s, OP_put_super_value); - break; default: abort(); } @@ -23138,7 +22723,6 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg, typedef enum FuncCallType { FUNC_CALL_NORMAL, FUNC_CALL_NEW, - FUNC_CALL_SUPER_CTOR, FUNC_CALL_TEMPLATE, } FuncCallType; @@ -23408,11 +22992,6 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) opcode = OP_get_field; } break; - case OP_scope_get_private_field: - /* keep the object on the stack */ - fd->byte_code.buf[fd->last_opcode_pos] = OP_scope_get_private_field2; - drop_count = 2; - break; case OP_get_array_el: /* keep the object on the stack */ fd->byte_code.buf[fd->last_opcode_pos] = OP_get_array_el2; @@ -23463,12 +23042,6 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) drop_count = 1; } break; - case OP_get_super_value: - fd->byte_code.buf[fd->last_opcode_pos] = OP_get_array_el; - /* on stack: this func_obj */ - opcode = OP_get_array_el; - drop_count = 2; - break; default: opcode = OP_invalid; drop_count = 1; @@ -23486,16 +23059,6 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) if (js_parse_template(s, 1, &arg_count)) return -1; goto emit_func_call; - } else if (call_type == FUNC_CALL_SUPER_CTOR) { - emit_op(s, OP_scope_get_var); - emit_atom(s, JS_ATOM_this_active_func); - emit_u16(s, 0); - - emit_op(s, OP_get_super); - - emit_op(s, OP_scope_get_var); - emit_atom(s, JS_ATOM_new_target); - emit_u16(s, 0); } else if (call_type == FUNC_CALL_NEW) { emit_op(s, OP_dup); /* new.target = function */ } @@ -23580,7 +23143,6 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) /* apply function call */ switch(opcode) { case OP_get_field: - case OP_scope_get_private_field: case OP_get_array_el: case OP_scope_get_ref: /* obj func array -> func obj array */ @@ -23615,7 +23177,6 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) emit_source_pos(s, op_token_ptr); switch(opcode) { case OP_get_field: - case OP_scope_get_private_field: case OP_get_array_el: case OP_scope_get_ref: emit_op(s, OP_call_method); @@ -23645,38 +23206,14 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) return -1; parse_property: emit_source_pos(s, op_token_ptr); - if (s->token.val == TOK_PRIVATE_NAME) { - /* private class field */ - if (get_prev_opcode(fd) == OP_get_super) { - return js_parse_error(s, "private class field forbidden after super"); - } - if (has_optional_chain) { - optional_chain_test(s, &optional_chaining_label, 1); - } - emit_op(s, OP_scope_get_private_field); - emit_atom(s, s->token.u.ident.atom); - emit_u16(s, s->cur_func->scope_level); - } else { - if (!token_is_ident(s->token.val)) { - return js_parse_error(s, "expecting field name"); - } - if (get_prev_opcode(fd) == OP_get_super) { - JSValue val; - int ret; - val = JS_AtomToValue(s->ctx, s->token.u.ident.atom); - ret = emit_push_const(s, val, 1); - JS_FreeValue(s->ctx, val); - if (ret) - return -1; - emit_op(s, OP_get_super_value); - } else { - if (has_optional_chain) { - optional_chain_test(s, &optional_chaining_label, 1); - } - emit_op(s, OP_get_field); - emit_atom(s, s->token.u.ident.atom); - } + if (!token_is_ident(s->token.val)) { + return js_parse_error(s, "expecting field name"); } + if (has_optional_chain) { + optional_chain_test(s, &optional_chaining_label, 1); + } + emit_op(s, OP_get_field); + emit_atom(s, s->token.u.ident.atom); if (next_token(s)) return -1; } else if (s->token.val == '[') { @@ -23694,11 +23231,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) if (js_parse_expect(s, ']')) return -1; emit_source_pos(s, op_token_ptr); - if (prev_op == OP_get_super) { - emit_op(s, OP_get_super_value); - } else { - emit_op(s, OP_get_array_el); - } + emit_op(s, OP_get_array_el); } else { break; } @@ -23797,15 +23330,6 @@ static __exception int js_parse_delete(JSParseState *s) fd->byte_code.buf[fd->last_opcode_pos] = OP_scope_delete_var; } break; - case OP_scope_get_private_field: - return js_parse_error(s, "cannot delete a private class field"); - case OP_get_super_value: - fd->byte_code.size = fd->last_opcode_pos; - fd->last_opcode_pos = -1; - emit_op(s, OP_throw_error); - emit_atom(s, JS_ATOM_NULL); - emit_u8(s, JS_THROW_ERROR_DELETE_SUPER); - break; default: ret_true: emit_op(s, OP_drop); @@ -23951,28 +23475,6 @@ static __exception int js_parse_expr_binary(JSParseState *s, int level, if (level == 0) { return js_parse_unary(s, PF_POW_ALLOWED); - } else if (s->token.val == TOK_PRIVATE_NAME && - (parse_flags & PF_IN_ACCEPTED) && level == 4 && - peek_token(s, FALSE) == TOK_IN) { - JSAtom atom; - - atom = JS_DupAtom(s->ctx, s->token.u.ident.atom); - if (next_token(s)) - goto fail_private_in; - if (s->token.val != TOK_IN) - goto fail_private_in; - if (next_token(s)) - goto fail_private_in; - if (js_parse_expr_binary(s, level - 1, parse_flags)) { - fail_private_in: - JS_FreeAtom(s->ctx, atom); - return -1; - } - emit_op(s, OP_scope_in_private_field); - emit_atom(s, atom); - emit_u16(s, s->cur_func->scope_level); - JS_FreeAtom(s->ctx, atom); - return 0; } else { if (js_parse_expr_binary(s, level - 1, parse_flags)) return -1; @@ -24464,30 +23966,9 @@ static void emit_return(JSParseState *s, BOOL hasval) } top = top->prev; } - if (s->cur_func->is_derived_class_constructor) { - int label_return; - /* 'this' can be uninitialized, so it may be accessed only if - the derived class constructor does not return an object */ - if (hasval) { - emit_op(s, OP_check_ctor_return); - label_return = emit_goto(s, OP_if_false, -1); - emit_op(s, OP_drop); - } else { - label_return = -1; - } + emit_op(s, hasval ? OP_return : OP_return_undef); - /* The error should be raised in the caller context, so we use - a specific opcode */ - emit_op(s, OP_scope_get_var_checkthis); - emit_atom(s, JS_ATOM_this); - emit_u16(s, 0); - - emit_label(s, label_return); - emit_op(s, OP_return); - } else { - emit_op(s, hasval ? OP_return : OP_return_undef); - } } #define DECL_MASK_FUNC (1 << 0) /* allow normal function declaration */ @@ -24941,10 +24422,6 @@ static __exception int js_parse_statement_or_decl(JSParseState *s, js_parse_error(s, "return not in a function"); goto fail; } - if (s->cur_func->func_type == JS_PARSE_FUNC_CLASS_STATIC_INIT) { - js_parse_error(s, "return in a static initializer block"); - goto fail; - } op_token_ptr = s->token.ptr; if (next_token(s)) goto fail; @@ -25590,7 +25067,6 @@ static __exception int js_parse_statement_or_decl(JSParseState *s, case TOK_ENUM: case TOK_EXPORT: - case TOK_EXTENDS: js_unsupported_keyword(s, s->token.u.ident.atom); goto fail; @@ -25686,7 +25162,6 @@ static JSFunctionDef *js_new_function_def(JSContext *ctx, fd->this_var_idx = -1; fd->new_target_var_idx = -1; fd->this_active_func_var_idx = -1; - fd->home_object_var_idx = -1; /* XXX: should distinguish arg, var and var object and body scopes */ fd->scopes = fd->def_scope_array; @@ -26484,12 +25959,6 @@ static int resolve_pseudo_var(JSContext *ctx, JSFunctionDef *s, if (!s->has_this_binding) return -1; switch(var_name) { - case JS_ATOM_home_object: - /* 'home_object' pseudo variable */ - if (s->home_object_var_idx < 0) - s->home_object_var_idx = add_var(ctx, s, var_name); - var_idx = s->home_object_var_idx; - break; case JS_ATOM_this_active_func: /* 'this.active_func' pseudo variable */ if (s->this_active_func_var_idx < 0) @@ -27001,168 +26470,6 @@ static void get_loc_or_ref(DynBuf *bc, BOOL is_ref, int idx) dbuf_put_u16(bc, idx); } -static int resolve_scope_private_field1(JSContext *ctx, - BOOL *pis_ref, int *pvar_kind, - JSFunctionDef *s, - JSAtom var_name, int scope_level) -{ - int idx, var_kind; - JSFunctionDef *fd; - BOOL is_ref; - - fd = s; - is_ref = FALSE; - for(;;) { - idx = find_private_class_field_all(ctx, fd, var_name, scope_level); - if (idx >= 0) { - var_kind = fd->vars[idx].var_kind; - if (is_ref) { - idx = get_closure_var(ctx, s, fd, FALSE, idx, var_name, - TRUE, TRUE, JS_VAR_NORMAL); - if (idx < 0) - return -1; - } - break; - } - scope_level = fd->parent_scope_level; - if (!fd->parent) { - if (fd->is_eval) { - /* closure of the eval function (top level) */ - for (idx = 0; idx < fd->closure_var_count; idx++) { - JSClosureVar *cv = &fd->closure_var[idx]; - if (cv->var_name == var_name) { - var_kind = cv->var_kind; - is_ref = TRUE; - if (fd != s) { - idx = get_closure_var2(ctx, s, fd, - FALSE, - cv->is_arg, idx, - cv->var_name, cv->is_const, - cv->is_lexical, - cv->var_kind); - if (idx < 0) - return -1; - } - goto done; - } - } - } - /* XXX: no line number info */ - JS_ThrowSyntaxErrorAtom(ctx, "undefined private field '%s'", - var_name); - return -1; - } else { - fd = fd->parent; - } - is_ref = TRUE; - } - done: - *pis_ref = is_ref; - *pvar_kind = var_kind; - return idx; -} - -/* return 0 if OK or -1 if the private field could not be resolved */ -static int resolve_scope_private_field(JSContext *ctx, JSFunctionDef *s, - JSAtom var_name, int scope_level, int op, - DynBuf *bc) -{ - int idx, var_kind; - BOOL is_ref; - - idx = resolve_scope_private_field1(ctx, &is_ref, &var_kind, s, - var_name, scope_level); - if (idx < 0) - return -1; - assert(var_kind != JS_VAR_NORMAL); - switch (op) { - case OP_scope_get_private_field: - case OP_scope_get_private_field2: - switch(var_kind) { - case JS_VAR_PRIVATE_FIELD: - if (op == OP_scope_get_private_field2) - dbuf_putc(bc, OP_dup); - get_loc_or_ref(bc, is_ref, idx); - dbuf_putc(bc, OP_get_private_field); - break; - case JS_VAR_PRIVATE_METHOD: - get_loc_or_ref(bc, is_ref, idx); - dbuf_putc(bc, OP_check_brand); - if (op != OP_scope_get_private_field2) - dbuf_putc(bc, OP_nip); - break; - case JS_VAR_PRIVATE_GETTER: - case JS_VAR_PRIVATE_GETTER_SETTER: - if (op == OP_scope_get_private_field2) - dbuf_putc(bc, OP_dup); - get_loc_or_ref(bc, is_ref, idx); - dbuf_putc(bc, OP_check_brand); - dbuf_putc(bc, OP_call_method); - dbuf_put_u16(bc, 0); - break; - case JS_VAR_PRIVATE_SETTER: - /* XXX: add clearer error message */ - dbuf_putc(bc, OP_throw_error); - dbuf_put_u32(bc, JS_DupAtom(ctx, var_name)); - dbuf_putc(bc, JS_THROW_VAR_RO); - break; - default: - abort(); - } - break; - case OP_scope_put_private_field: - switch(var_kind) { - case JS_VAR_PRIVATE_FIELD: - get_loc_or_ref(bc, is_ref, idx); - dbuf_putc(bc, OP_put_private_field); - break; - case JS_VAR_PRIVATE_METHOD: - case JS_VAR_PRIVATE_GETTER: - /* XXX: add clearer error message */ - dbuf_putc(bc, OP_throw_error); - dbuf_put_u32(bc, JS_DupAtom(ctx, var_name)); - dbuf_putc(bc, JS_THROW_VAR_RO); - break; - case JS_VAR_PRIVATE_SETTER: - case JS_VAR_PRIVATE_GETTER_SETTER: - { - JSAtom setter_name = get_private_setter_name(ctx, var_name); - if (setter_name == JS_ATOM_NULL) - return -1; - idx = resolve_scope_private_field1(ctx, &is_ref, - &var_kind, s, - setter_name, scope_level); - JS_FreeAtom(ctx, setter_name); - if (idx < 0) - return -1; - assert(var_kind == JS_VAR_PRIVATE_SETTER); - get_loc_or_ref(bc, is_ref, idx); - dbuf_putc(bc, OP_swap); - /* obj func value */ - dbuf_putc(bc, OP_rot3r); - /* value obj func */ - dbuf_putc(bc, OP_check_brand); - dbuf_putc(bc, OP_rot3l); - /* obj func value */ - dbuf_putc(bc, OP_call_method); - dbuf_put_u16(bc, 1); - dbuf_putc(bc, OP_drop); - } - break; - default: - abort(); - } - break; - case OP_scope_in_private_field: - get_loc_or_ref(bc, is_ref, idx); - dbuf_putc(bc, OP_private_in); - break; - default: - abort(); - } - return 0; -} - static void mark_eval_captured_variables(JSContext *ctx, JSFunctionDef *s, int scope_level) { @@ -27214,8 +26521,6 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s) s->new_target_var_idx = add_var(ctx, s, JS_ATOM_new_target); if (s->is_derived_class_constructor && s->this_active_func_var_idx < 0) s->this_active_func_var_idx = add_var(ctx, s, JS_ATOM_this_active_func); - if (s->has_home_object && s->home_object_var_idx < 0) - s->home_object_var_idx = add_var(ctx, s, JS_ATOM_home_object); } has_arguments_binding = s->has_arguments_binding; if (has_arguments_binding) { @@ -27250,8 +26555,6 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s) fd->new_target_var_idx = add_var(ctx, fd, JS_ATOM_new_target); if (fd->is_derived_class_constructor && fd->this_active_func_var_idx < 0) fd->this_active_func_var_idx = add_var(ctx, fd, JS_ATOM_this_active_func); - if (fd->has_home_object && fd->home_object_var_idx < 0) - fd->home_object_var_idx = add_var(ctx, fd, JS_ATOM_home_object); has_this_binding = TRUE; } /* add 'arguments' if it was not previously added */ @@ -27839,20 +27142,6 @@ static __exception int resolve_variables(JSContext *ctx, JSFunctionDef *s) JS_FreeAtom(ctx, var_name); } break; - case OP_scope_get_private_field: - case OP_scope_get_private_field2: - case OP_scope_put_private_field: - case OP_scope_in_private_field: - { - int ret; - var_name = get_u32(bc_buf + pos + 1); - scope = get_u16(bc_buf + pos + 5); - ret = resolve_scope_private_field(ctx, s, var_name, scope, op, &bc_out); - if (ret < 0) - goto fail; - JS_FreeAtom(ctx, var_name); - } - break; case OP_gosub: s->jump_size++; if (OPTIMIZE) { @@ -28382,12 +27671,6 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) s->line_number_last_pc = 0; } - /* initialize the 'home_object' variable if needed */ - if (s->home_object_var_idx >= 0) { - dbuf_putc(&bc_out, OP_special_object); - dbuf_putc(&bc_out, OP_SPECIAL_OBJECT_HOME_OBJECT); - put_short_code(&bc_out, OP_put_loc, s->home_object_var_idx); - } /* initialize the 'this.active_func' variable if needed */ if (s->this_active_func_var_idx >= 0) { dbuf_putc(&bc_out, OP_special_object); @@ -29687,11 +28970,7 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) b->has_simple_parameter_list = fd->has_simple_parameter_list; b->js_mode = fd->js_mode; b->is_derived_class_constructor = fd->is_derived_class_constructor; - b->need_home_object = (fd->home_object_var_idx >= 0 || - fd->need_home_object); b->new_target_allowed = fd->new_target_allowed; - b->super_call_allowed = fd->super_call_allowed; - b->super_allowed = fd->super_allowed; b->arguments_allowed = fd->arguments_allowed; b->is_direct_or_indirect_eval = (fd->eval_type == JS_EVAL_TYPE_DIRECT || fd->eval_type == JS_EVAL_TYPE_INDIRECT); @@ -29816,19 +29095,13 @@ static __exception int js_parse_directives(JSParseState *s) case TOK_FUNCTION: case TOK_DEBUGGER: case TOK_WITH: - case TOK_CLASS: case TOK_CONST: case TOK_ENUM: case TOK_EXPORT: case TOK_IMPORT: - case TOK_SUPER: case TOK_INTERFACE: case TOK_LET: case TOK_PACKAGE: - case TOK_PRIVATE: - case TOK_PROTECTED: - case TOK_PUBLIC: - case TOK_STATIC: /* automatic insertion of ';' */ if (s->got_lf) has_semi = TRUE; @@ -29903,32 +29176,6 @@ duplicate: return js_parse_error(s, "duplicate argument names not allowed in this context"); } -/* create a function to initialize class fields */ -static JSFunctionDef *js_parse_function_class_fields_init(JSParseState *s) -{ - JSFunctionDef *fd; - - fd = js_new_function_def(s->ctx, s->cur_func, FALSE, FALSE, - s->filename, s->buf_start, - &s->get_line_col_cache); - if (!fd) - return NULL; - fd->func_name = JS_ATOM_NULL; - fd->has_prototype = FALSE; - fd->has_home_object = TRUE; - - fd->has_arguments_binding = FALSE; - fd->has_this_binding = TRUE; - fd->is_derived_class_constructor = FALSE; - fd->new_target_allowed = TRUE; - fd->super_call_allowed = FALSE; - fd->super_allowed = fd->has_home_object; - fd->arguments_allowed = FALSE; - - fd->func_type = JS_PARSE_FUNC_METHOD; - return fd; -} - /* func_name must be JS_ATOM_NULL for JS_PARSE_FUNC_STATEMENT and JS_PARSE_FUNC_EXPR, JS_PARSE_FUNC_ARROW and JS_PARSE_FUNC_VAR */ static __exception int js_parse_function_decl2(JSParseState *s, @@ -30036,29 +29283,19 @@ static __exception int js_parse_function_decl2(JSParseState *s, fd->has_prototype = (func_type == JS_PARSE_FUNC_STATEMENT || func_type == JS_PARSE_FUNC_VAR || func_type == JS_PARSE_FUNC_EXPR); - fd->has_home_object = (func_type == JS_PARSE_FUNC_METHOD || - func_type == JS_PARSE_FUNC_GETTER || - func_type == JS_PARSE_FUNC_SETTER || - func_type == JS_PARSE_FUNC_CLASS_CONSTRUCTOR || - func_type == JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR); + fd->has_arguments_binding = (func_type != JS_PARSE_FUNC_ARROW && func_type != JS_PARSE_FUNC_CLASS_STATIC_INIT); fd->has_this_binding = fd->has_arguments_binding; fd->is_derived_class_constructor = (func_type == JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR); if (func_type == JS_PARSE_FUNC_ARROW) { fd->new_target_allowed = fd->parent->new_target_allowed; - fd->super_call_allowed = fd->parent->super_call_allowed; - fd->super_allowed = fd->parent->super_allowed; fd->arguments_allowed = fd->parent->arguments_allowed; } else if (func_type == JS_PARSE_FUNC_CLASS_STATIC_INIT) { fd->new_target_allowed = TRUE; // although new.target === undefined - fd->super_call_allowed = FALSE; - fd->super_allowed = TRUE; fd->arguments_allowed = FALSE; } else { fd->new_target_allowed = TRUE; - fd->super_call_allowed = fd->is_derived_class_constructor; - fd->super_allowed = fd->has_home_object; fd->arguments_allowed = TRUE; } @@ -30067,12 +29304,6 @@ static __exception int js_parse_function_decl2(JSParseState *s, regular identifiers for other function kinds. */ fd->func_type = func_type; - if (func_type == JS_PARSE_FUNC_CLASS_CONSTRUCTOR || - func_type == JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR) { - /* error if not invoked as a constructor */ - emit_op(s, OP_check_ctor); - } - /* parse arguments */ fd->has_simple_parameter_list = TRUE; fd->has_parameter_expressions = FALSE; @@ -30301,10 +29532,8 @@ static __exception int js_parse_function_decl2(JSParseState *s, } } - if (func_type != JS_PARSE_FUNC_CLASS_STATIC_INIT) { - if (js_parse_expect(s, '{')) - goto fail; - } + if (js_parse_expect(s, '{')) + goto fail; if (js_parse_directives(s)) goto fail; @@ -30353,18 +29582,14 @@ static __exception int js_parse_function_decl2(JSParseState *s, fd->parent_cpool_idx = idx; if (is_expr) { - /* for constructors, no code needs to be generated here */ - if (func_type != JS_PARSE_FUNC_CLASS_CONSTRUCTOR && - func_type != JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR) { - /* OP_fclosure creates the function object from the bytecode - and adds the scope information */ - emit_op(s, OP_fclosure); - emit_u32(s, idx); - if (func_name == JS_ATOM_NULL) { - emit_op(s, OP_set_name); - emit_u32(s, JS_ATOM_NULL); - } - } + /* OP_fclosure creates the function object from the bytecode + and adds the scope information */ + emit_op(s, OP_fclosure); + emit_u32(s, idx); + if (func_name == JS_ATOM_NULL) { + emit_op(s, OP_set_name); + emit_u32(s, JS_ATOM_NULL); + } } else if (func_type == JS_PARSE_FUNC_VAR) { emit_op(s, OP_fclosure); emit_u32(s, idx); @@ -30579,13 +29804,9 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj, fd->has_this_binding = (eval_type != JS_EVAL_TYPE_DIRECT); if (eval_type == JS_EVAL_TYPE_DIRECT) { fd->new_target_allowed = b->new_target_allowed; - fd->super_call_allowed = b->super_call_allowed; - fd->super_allowed = b->super_allowed; fd->arguments_allowed = b->arguments_allowed; } else { fd->new_target_allowed = FALSE; - fd->super_call_allowed = FALSE; - fd->super_allowed = FALSE; fd->arguments_allowed = TRUE; } fd->js_mode = js_mode; @@ -31144,11 +30365,8 @@ static int JS_WriteFunctionTag(BCWriterState *s, JSValueConst obj) bc_set_flags(&flags, &idx, b->has_prototype, 1); bc_set_flags(&flags, &idx, b->has_simple_parameter_list, 1); bc_set_flags(&flags, &idx, b->is_derived_class_constructor, 1); - bc_set_flags(&flags, &idx, b->need_home_object, 1); bc_set_flags(&flags, &idx, b->func_kind, 2); bc_set_flags(&flags, &idx, b->new_target_allowed, 1); - bc_set_flags(&flags, &idx, b->super_call_allowed, 1); - bc_set_flags(&flags, &idx, b->super_allowed, 1); bc_set_flags(&flags, &idx, b->arguments_allowed, 1); bc_set_flags(&flags, &idx, b->has_debug, 1); bc_set_flags(&flags, &idx, b->is_direct_or_indirect_eval, 1); @@ -31968,11 +31186,8 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s) bc.has_prototype = bc_get_flags(v16, &idx, 1); bc.has_simple_parameter_list = bc_get_flags(v16, &idx, 1); bc.is_derived_class_constructor = bc_get_flags(v16, &idx, 1); - bc.need_home_object = bc_get_flags(v16, &idx, 1); bc.func_kind = bc_get_flags(v16, &idx, 2); bc.new_target_allowed = bc_get_flags(v16, &idx, 1); - bc.super_call_allowed = bc_get_flags(v16, &idx, 1); - bc.super_allowed = bc_get_flags(v16, &idx, 1); bc.arguments_allowed = bc_get_flags(v16, &idx, 1); bc.has_debug = bc_get_flags(v16, &idx, 1); bc.is_direct_or_indirect_eval = bc_get_flags(v16, &idx, 1);