@@ -364,15 +364,7 @@ typedef struct JSVarRef {
364
364
struct {
365
365
int __gc_ref_count; /* corresponds to header.ref_count */
366
366
uint8_t __gc_mark; /* corresponds to header.mark/gc_obj_type */
367
-
368
- /* 0 : the JSVarRef is on the stack. header.link is an element
369
- of JSStackFrame.var_ref_list.
370
- 1 : the JSVarRef is detached. header.link has the normal meanning
371
- */
372
- uint8_t is_detached : 1;
373
- uint8_t is_arg : 1;
374
- uint16_t var_idx; /* index of the corresponding function variable on
375
- the stack */
367
+ bool is_detached;
376
368
};
377
369
};
378
370
JSValue *pvalue; /* pointer to the value, either on the stack or
@@ -14440,10 +14432,16 @@ static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf,
14440
14432
{
14441
14433
JSVarRef *var_ref;
14442
14434
struct list_head *el;
14435
+ JSValue *pvalue;
14436
+
14437
+ if (is_arg)
14438
+ pvalue = &sf->arg_buf[var_idx];
14439
+ else
14440
+ pvalue = &sf->var_buf[var_idx];
14443
14441
14444
14442
list_for_each(el, &sf->var_ref_list) {
14445
14443
var_ref = list_entry(el, JSVarRef, header.link);
14446
- if (var_ref->var_idx == var_idx && var_ref->is_arg == is_arg ) {
14444
+ if (var_ref->pvalue == pvalue ) {
14447
14445
var_ref->header.ref_count++;
14448
14446
return var_ref;
14449
14447
}
@@ -14454,13 +14452,8 @@ static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf,
14454
14452
return NULL;
14455
14453
var_ref->header.ref_count = 1;
14456
14454
var_ref->is_detached = false;
14457
- var_ref->is_arg = is_arg;
14458
- var_ref->var_idx = var_idx;
14459
14455
list_add_tail(&var_ref->header.link, &sf->var_ref_list);
14460
- if (is_arg)
14461
- var_ref->pvalue = &sf->arg_buf[var_idx];
14462
- else
14463
- var_ref->pvalue = &sf->var_buf[var_idx];
14456
+ var_ref->pvalue = pvalue;
14464
14457
var_ref->value = JS_UNDEFINED;
14465
14458
return var_ref;
14466
14459
}
@@ -14689,32 +14682,28 @@ static void close_var_refs(JSRuntime *rt, JSStackFrame *sf)
14689
14682
{
14690
14683
struct list_head *el, *el1;
14691
14684
JSVarRef *var_ref;
14692
- int var_idx;
14693
14685
14694
14686
list_for_each_safe(el, el1, &sf->var_ref_list) {
14695
14687
var_ref = list_entry(el, JSVarRef, header.link);
14696
- var_idx = var_ref->var_idx;
14697
- if (var_ref->is_arg)
14698
- var_ref->value = js_dup(sf->arg_buf[var_idx]);
14699
- else
14700
- var_ref->value = js_dup(sf->var_buf[var_idx]);
14688
+ var_ref->value = js_dup(*var_ref->pvalue);
14701
14689
var_ref->pvalue = &var_ref->value;
14702
14690
/* the reference is no longer to a local variable */
14703
14691
var_ref->is_detached = true;
14704
14692
add_gc_object(rt, &var_ref->header, JS_GC_OBJ_TYPE_VAR_REF);
14705
14693
}
14706
14694
}
14707
14695
14708
- static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int idx, int is_arg )
14696
+ static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int var_idx )
14709
14697
{
14698
+ JSValue *pvalue;
14710
14699
struct list_head *el, *el1;
14711
14700
JSVarRef *var_ref;
14712
- int var_idx = idx;
14713
14701
14702
+ pvalue = &sf->var_buf[var_idx];
14714
14703
list_for_each_safe(el, el1, &sf->var_ref_list) {
14715
14704
var_ref = list_entry(el, JSVarRef, header.link);
14716
- if (var_idx == var_ref->var_idx && var_ref->is_arg == is_arg ) {
14717
- var_ref->value = js_dup(sf->var_buf[var_idx] );
14705
+ if (var_ref->pvalue == pvalue ) {
14706
+ var_ref->value = js_dup(*var_ref->pvalue );
14718
14707
var_ref->pvalue = &var_ref->value;
14719
14708
list_del(&var_ref->header.link);
14720
14709
/* the reference is no longer to a local variable */
@@ -15976,7 +15965,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
15976
15965
int idx;
15977
15966
idx = get_u16(pc);
15978
15967
pc += 2;
15979
- close_lexical_var(ctx, sf, idx, FALSE );
15968
+ close_lexical_var(ctx, sf, idx);
15980
15969
}
15981
15970
BREAK;
15982
15971
0 commit comments