about summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2024-01-08 18:39:58 +0100
committerbptato <nincsnevem662@gmail.com>2024-01-11 18:49:29 +0100
commit16910c34040f65f242ea5af36c943146c44b0539 (patch)
treeae3d327bb60ae27761b3a6036869ab06f6a364ca /lib
parent36b9761af06156099dec63ec6914e3cc109253f4 (diff)
downloadchawan-16910c34040f65f242ea5af36c943146c44b0539.tar.gz
fixed class name init in static initializers
Diffstat (limited to 'lib')
-rw-r--r--lib/quickjs/quickjs.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/lib/quickjs/quickjs.c b/lib/quickjs/quickjs.c
index c370a46d..8c79311e 100644
--- a/lib/quickjs/quickjs.c
+++ b/lib/quickjs/quickjs.c
@@ -23067,14 +23067,6 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
                 emit_atom(s, JS_ATOM_this);
                 emit_u16(s, 0);
                 // stack is now: fclosure this
-                /* XXX: should do it only once */
-                if (class_name != JS_ATOM_NULL) {
-                    // TODO(bnoordhuis) pass as argument to init method?
-                    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);
-                }
                 emit_op(s, OP_swap);
                 // stack is now: this fclosure
                 emit_op(s, OP_call_method);
@@ -23395,6 +23387,16 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
         emit_op(s, OP_add_brand);
     }
 
+    if (class_name != JS_ATOM_NULL) {
+        /* store the class name in the scoped class name variable (it
+           is independent from the class statement variable
+           definition) */
+        emit_op(s, OP_dup);
+        emit_op(s, OP_scope_put_var_init);
+        emit_atom(s, class_name);
+        emit_u16(s, fd->scope_level);
+    }
+
     /* initialize the static fields */
     if (class_fields[1].fields_init_fd != NULL) {
         ClassFieldsDef *cf = &class_fields[1];
@@ -23405,15 +23407,6 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
         emit_op(s, OP_drop);
     }
     
-    if (class_name != JS_ATOM_NULL) {
-        /* store the class name in the scoped class name variable (it
-           is independent from the class statement variable
-           definition) */
-        emit_op(s, OP_dup);
-        emit_op(s, OP_scope_put_var_init);
-        emit_atom(s, class_name);
-        emit_u16(s, fd->scope_level);
-    }
     pop_scope(s);
     pop_scope(s);