Expose class name to static initializers (#139)
Fixes: https://github.com/quickjs-ng/quickjs/issues/138
This commit is contained in:
parent
d4c1244045
commit
8df335a7b9
2 changed files with 17 additions and 0 deletions
|
@ -20972,6 +20972,14 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
|
|||
emit_atom(s, JS_ATOM_this);
|
||||
emit_u16(s, 0);
|
||||
|
||||
// expose class name to static initializers
|
||||
if (is_static && class_name != JS_ATOM_NULL) {
|
||||
emit_op(s, OP_dup);
|
||||
emit_op(s, OP_scope_put_var_init);
|
||||
emit_atom(s, class_name);
|
||||
emit_u16(s, s->cur_func->scope_level);
|
||||
}
|
||||
|
||||
if (name == JS_ATOM_NULL) {
|
||||
emit_op(s, OP_scope_get_var);
|
||||
emit_atom(s, field_var_name);
|
||||
|
|
|
@ -325,6 +325,15 @@ function test_class()
|
|||
/* test class name scope */
|
||||
var E1 = class E { static F() { return E; } };
|
||||
assert(E1 === E1.F());
|
||||
|
||||
class S {
|
||||
static x = 42;
|
||||
static y = S.x;
|
||||
static z = this.x;
|
||||
}
|
||||
assert(S.x === 42);
|
||||
assert(S.y === 42);
|
||||
assert(S.z === 42);
|
||||
};
|
||||
|
||||
function test_template()
|
||||
|
|
Loading…
Reference in a new issue