@@ -363,10 +363,7 @@ typedef struct JSVarRef {
363
363
struct {
364
364
int __gc_ref_count; /* corresponds to header.ref_count */
365
365
uint8_t __gc_mark; /* corresponds to header.mark/gc_obj_type */
366
- uint8_t is_detached : 1;
367
- uint8_t is_arg : 1;
368
- uint16_t var_idx; /* index of the corresponding function variable on
369
- the stack */
366
+ uint8_t is_detached;
370
367
};
371
368
};
372
369
JSValue *pvalue; /* pointer to the value, either on the stack or
@@ -15673,10 +15670,16 @@ static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf,
15673
15670
{
15674
15671
JSVarRef *var_ref;
15675
15672
struct list_head *el;
15673
+ JSValue *pvalue;
15674
+
15675
+ if (is_arg)
15676
+ pvalue = &sf->arg_buf[var_idx];
15677
+ else
15678
+ pvalue = &sf->var_buf[var_idx];
15676
15679
15677
15680
list_for_each(el, &sf->var_ref_list) {
15678
15681
var_ref = list_entry(el, JSVarRef, var_ref_link);
15679
- if (var_ref->var_idx == var_idx && var_ref->is_arg == is_arg ) {
15682
+ if (var_ref->pvalue == pvalue ) {
15680
15683
var_ref->header.ref_count++;
15681
15684
return var_ref;
15682
15685
}
@@ -15688,8 +15691,6 @@ static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf,
15688
15691
var_ref->header.ref_count = 1;
15689
15692
add_gc_object(ctx->rt, &var_ref->header, JS_GC_OBJ_TYPE_VAR_REF);
15690
15693
var_ref->is_detached = FALSE;
15691
- var_ref->is_arg = is_arg;
15692
- var_ref->var_idx = var_idx;
15693
15694
list_add_tail(&var_ref->var_ref_link, &sf->var_ref_list);
15694
15695
if (sf->js_mode & JS_MODE_ASYNC) {
15695
15696
/* The stack frame is detached and may be destroyed at any
@@ -15705,10 +15706,7 @@ static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf,
15705
15706
} else {
15706
15707
var_ref->async_func = NULL;
15707
15708
}
15708
- if (is_arg)
15709
- var_ref->pvalue = &sf->arg_buf[var_idx];
15710
- else
15711
- var_ref->pvalue = &sf->var_buf[var_idx];
15709
+ var_ref->pvalue = pvalue;
15712
15710
return var_ref;
15713
15711
}
15714
15712
@@ -15936,37 +15934,33 @@ static void close_var_refs(JSRuntime *rt, JSStackFrame *sf)
15936
15934
{
15937
15935
struct list_head *el, *el1;
15938
15936
JSVarRef *var_ref;
15939
- int var_idx;
15940
15937
15941
15938
list_for_each_safe(el, el1, &sf->var_ref_list) {
15942
15939
var_ref = list_entry(el, JSVarRef, var_ref_link);
15943
15940
/* no need to unlink var_ref->var_ref_link as the list is never used afterwards */
15944
15941
if (var_ref->async_func)
15945
15942
async_func_free(rt, var_ref->async_func);
15946
- var_idx = var_ref->var_idx;
15947
- if (var_ref->is_arg)
15948
- var_ref->value = JS_DupValueRT(rt, sf->arg_buf[var_idx]);
15949
- else
15950
- var_ref->value = JS_DupValueRT(rt, sf->var_buf[var_idx]);
15943
+ var_ref->value = JS_DupValueRT(rt, *var_ref->pvalue);
15951
15944
var_ref->pvalue = &var_ref->value;
15952
15945
/* the reference is no longer to a local variable */
15953
15946
var_ref->is_detached = TRUE;
15954
15947
}
15955
15948
}
15956
15949
15957
- static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int idx, int is_arg )
15950
+ static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int var_idx )
15958
15951
{
15952
+ JSValue *pvalue;
15959
15953
struct list_head *el, *el1;
15960
15954
JSVarRef *var_ref;
15961
- int var_idx = idx;
15962
15955
15956
+ pvalue = &sf->var_buf[var_idx];
15963
15957
list_for_each_safe(el, el1, &sf->var_ref_list) {
15964
15958
var_ref = list_entry(el, JSVarRef, var_ref_link);
15965
- if (var_idx == var_ref->var_idx && var_ref->is_arg == is_arg ) {
15959
+ if (var_ref->pvalue == pvalue ) {
15966
15960
list_del(&var_ref->var_ref_link);
15967
15961
if (var_ref->async_func)
15968
15962
async_func_free(ctx->rt, var_ref->async_func);
15969
- var_ref->value = JS_DupValue(ctx, sf->var_buf[var_idx] );
15963
+ var_ref->value = JS_DupValue(ctx, *var_ref->pvalue );
15970
15964
var_ref->pvalue = &var_ref->value;
15971
15965
/* the reference is no longer to a local variable */
15972
15966
var_ref->is_detached = TRUE;
@@ -17199,7 +17193,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
17199
17193
int idx;
17200
17194
idx = get_u16(pc);
17201
17195
pc += 2;
17202
- close_lexical_var(ctx, sf, idx, FALSE );
17196
+ close_lexical_var(ctx, sf, idx);
17203
17197
}
17204
17198
BREAK;
17205
17199
0 commit comments