fixed duplicate static private setter/getter test

This commit is contained in:
Fabrice Bellard
2023-12-09 12:32:32 +01:00
parent b180cd2c43
commit 177af41665
2 changed files with 12 additions and 15 deletions

View File

@@ -552,6 +552,7 @@ 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 =
@@ -21739,7 +21740,7 @@ static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,
/* add a private field variable in the current scope */
static int add_private_class_field(JSParseState *s, JSFunctionDef *fd,
JSAtom name, JSVarKindEnum var_kind)
JSAtom name, JSVarKindEnum var_kind, BOOL is_static)
{
JSContext *ctx = s->ctx;
JSVarDef *vd;
@@ -21751,6 +21752,7 @@ static int add_private_class_field(JSParseState *s, JSFunctionDef *fd,
vd = &fd->vars[idx];
vd->is_lexical = 1;
vd->is_const = 1;
vd->is_static_private = is_static;
return idx;
}
@@ -22697,20 +22699,23 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
JSFunctionDef *method_fd;
if (is_private) {
int idx, var_kind;
int idx, var_kind, is_static1;
idx = find_private_class_field(ctx, fd, name, fd->scope_level);
if (idx >= 0) {
var_kind = fd->vars[idx].var_kind;
is_static1 = fd->vars[idx].is_static_private;
if (var_kind == JS_VAR_PRIVATE_FIELD ||
var_kind == JS_VAR_PRIVATE_METHOD ||
var_kind == JS_VAR_PRIVATE_GETTER_SETTER ||
var_kind == (JS_VAR_PRIVATE_GETTER + is_set)) {
var_kind == (JS_VAR_PRIVATE_GETTER + is_set) ||
(var_kind == (JS_VAR_PRIVATE_GETTER + 1 - is_set) &&
is_static != is_static1)) {
goto private_field_already_defined;
}
fd->vars[idx].var_kind = JS_VAR_PRIVATE_GETTER_SETTER;
} else {
if (add_private_class_field(s, fd, name,
JS_VAR_PRIVATE_GETTER + is_set) < 0)
JS_VAR_PRIVATE_GETTER + is_set, is_static) < 0)
goto fail;
}
if (add_brand(s, &class_fields[is_static]) < 0)
@@ -22736,7 +22741,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
goto fail;
emit_atom(s, setter_name);
ret = add_private_class_field(s, fd, setter_name,
JS_VAR_PRIVATE_SETTER);
JS_VAR_PRIVATE_SETTER, is_static);
JS_FreeAtom(ctx, setter_name);
if (ret < 0)
goto fail;
@@ -22771,7 +22776,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
goto private_field_already_defined;
}
if (add_private_class_field(s, fd, name,
JS_VAR_PRIVATE_FIELD) < 0)
JS_VAR_PRIVATE_FIELD, is_static) < 0)
goto fail;
emit_op(s, OP_private_symbol);
emit_atom(s, name);
@@ -22878,7 +22883,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
goto fail;
}
if (add_private_class_field(s, fd, name,
JS_VAR_PRIVATE_METHOD) < 0)
JS_VAR_PRIVATE_METHOD, is_static) < 0)
goto fail;
emit_op(s, OP_set_home_object);
emit_op(s, OP_set_name);