Skip to content

Commit baf50f9

Browse files
Fabrice Bellardbnoordhuis
authored andcommitted
fixed duplicate static private setter/getter test
1 parent e8b9704 commit baf50f9

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

quickjs.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ typedef struct JSVarDef {
521521
uint8_t is_const : 1;
522522
uint8_t is_lexical : 1;
523523
uint8_t is_captured : 1;
524+
uint8_t is_static_private : 1; /* only used during private class field parsing */
524525
uint8_t var_kind : 4; /* see JSVarKindEnum */
525526
/* only used during compilation: function pool index for lexical
526527
variables with var_kind =
@@ -20098,7 +20099,7 @@ static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,
2009820099

2009920100
/* add a private field variable in the current scope */
2010020101
static int add_private_class_field(JSParseState *s, JSFunctionDef *fd,
20101-
JSAtom name, JSVarKindEnum var_kind)
20102+
JSAtom name, JSVarKindEnum var_kind, BOOL is_static)
2010220103
{
2010320104
JSContext *ctx = s->ctx;
2010420105
JSVarDef *vd;
@@ -20110,6 +20111,7 @@ static int add_private_class_field(JSParseState *s, JSFunctionDef *fd,
2011020111
vd = &fd->vars[idx];
2011120112
vd->is_lexical = 1;
2011220113
vd->is_const = 1;
20114+
vd->is_static_private = is_static;
2011320115
return idx;
2011420116
}
2011520117

@@ -21139,20 +21141,23 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
2113921141
JSFunctionDef *method_fd;
2114021142

2114121143
if (is_private) {
21142-
int idx, var_kind;
21144+
int idx, var_kind, is_static1;
2114321145
idx = find_private_class_field(ctx, fd, name, fd->scope_level);
2114421146
if (idx >= 0) {
2114521147
var_kind = fd->vars[idx].var_kind;
21148+
is_static1 = fd->vars[idx].is_static_private;
2114621149
if (var_kind == JS_VAR_PRIVATE_FIELD ||
2114721150
var_kind == JS_VAR_PRIVATE_METHOD ||
2114821151
var_kind == JS_VAR_PRIVATE_GETTER_SETTER ||
21149-
var_kind == (JS_VAR_PRIVATE_GETTER + is_set)) {
21152+
var_kind == (JS_VAR_PRIVATE_GETTER + is_set) ||
21153+
(var_kind == (JS_VAR_PRIVATE_GETTER + 1 - is_set) &&
21154+
is_static != is_static1)) {
2115021155
goto private_field_already_defined;
2115121156
}
2115221157
fd->vars[idx].var_kind = JS_VAR_PRIVATE_GETTER_SETTER;
2115321158
} else {
2115421159
if (add_private_class_field(s, fd, name,
21155-
JS_VAR_PRIVATE_GETTER + is_set) < 0)
21160+
JS_VAR_PRIVATE_GETTER + is_set, is_static) < 0)
2115621161
goto fail;
2115721162
}
2115821163
if (add_brand(s, &class_fields[is_static]) < 0)
@@ -21178,7 +21183,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
2117821183
goto fail;
2117921184
emit_atom(s, setter_name);
2118021185
ret = add_private_class_field(s, fd, setter_name,
21181-
JS_VAR_PRIVATE_SETTER);
21186+
JS_VAR_PRIVATE_SETTER, is_static);
2118221187
JS_FreeAtom(ctx, setter_name);
2118321188
if (ret < 0)
2118421189
goto fail;
@@ -21213,7 +21218,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
2121321218
goto private_field_already_defined;
2121421219
}
2121521220
if (add_private_class_field(s, fd, name,
21216-
JS_VAR_PRIVATE_FIELD) < 0)
21221+
JS_VAR_PRIVATE_FIELD, is_static) < 0)
2121721222
goto fail;
2121821223
emit_op(s, OP_private_symbol);
2121921224
emit_atom(s, name);
@@ -21328,7 +21333,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
2132821333
goto fail;
2132921334
}
2133021335
if (add_private_class_field(s, fd, name,
21331-
JS_VAR_PRIVATE_METHOD) < 0)
21336+
JS_VAR_PRIVATE_METHOD, is_static) < 0)
2133221337
goto fail;
2133321338
emit_op(s, OP_set_home_object);
2133421339
emit_op(s, OP_set_name);

test262_errors.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,5 @@ test262/test/language/statements/class/elements/private-method-double-initialisa
117117
test262/test/language/statements/class/elements/private-method-double-initialisation-set.js:32: strict mode: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
118118
test262/test/language/statements/class/elements/private-method-double-initialisation.js:32: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
119119
test262/test/language/statements/class/elements/private-method-double-initialisation.js:32: strict mode: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
120-
test262/test/language/statements/class/private-non-static-getter-static-setter-early-error.js:13: unexpected error type: Test262: This statement should not be evaluated.
121-
test262/test/language/statements/class/private-non-static-getter-static-setter-early-error.js:13: strict mode: unexpected error type: Test262: This statement should not be evaluated.
122-
test262/test/language/statements/class/private-non-static-setter-static-getter-early-error.js:13: unexpected error type: Test262: This statement should not be evaluated.
123-
test262/test/language/statements/class/private-non-static-setter-static-getter-early-error.js:13: strict mode: unexpected error type: Test262: This statement should not be evaluated.
124-
test262/test/language/statements/class/private-static-getter-non-static-setter-early-error.js:13: unexpected error type: Test262: This statement should not be evaluated.
125-
test262/test/language/statements/class/private-static-getter-non-static-setter-early-error.js:13: strict mode: unexpected error type: Test262: This statement should not be evaluated.
126-
test262/test/language/statements/class/private-static-setter-non-static-getter-early-error.js:13: unexpected error type: Test262: This statement should not be evaluated.
127-
test262/test/language/statements/class/private-static-setter-non-static-getter-early-error.js:13: strict mode: unexpected error type: Test262: This statement should not be evaluated.
128120
test262/test/language/statements/for-of/head-lhs-async-invalid.js:14: unexpected error type: Test262: This statement should not be evaluated.
129121
test262/test/language/statements/for-of/head-lhs-async-invalid.js:14: strict mode: unexpected error type: Test262: This statement should not be evaluated.

0 commit comments

Comments
 (0)