style: 自动格式化
This commit is contained in:
@@ -149,7 +149,10 @@ impl Compiler {
|
|||||||
}
|
}
|
||||||
// Check if target is a captured cell
|
// Check if target is a captured cell
|
||||||
if ctx.scopes.symbols.lookup_is_captured(name) {
|
if ctx.scopes.symbols.lookup_is_captured(name) {
|
||||||
let cell_idx = ctx.scopes.cell_registry.iter()
|
let cell_idx = ctx
|
||||||
|
.scopes
|
||||||
|
.cell_registry
|
||||||
|
.iter()
|
||||||
.find(|(n, _)| n == name)
|
.find(|(n, _)| n == name)
|
||||||
.map(|(_, idx)| *idx)
|
.map(|(_, idx)| *idx)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|||||||
@@ -70,7 +70,10 @@ impl Compiler {
|
|||||||
|
|
||||||
// Check if the owner's binding is captured (cell access)
|
// Check if the owner's binding is captured (cell access)
|
||||||
if ctx.scopes.symbols.lookup_is_captured(name) {
|
if ctx.scopes.symbols.lookup_is_captured(name) {
|
||||||
let cell_idx = ctx.scopes.cell_registry.iter()
|
let cell_idx = ctx
|
||||||
|
.scopes
|
||||||
|
.cell_registry
|
||||||
|
.iter()
|
||||||
.find(|(n, _)| n == name)
|
.find(|(n, _)| n == name)
|
||||||
.map(|(_, idx)| *idx)
|
.map(|(_, idx)| *idx)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|||||||
@@ -163,7 +163,9 @@ impl Vm {
|
|||||||
if cell_ptr.is_null() {
|
if cell_ptr.is_null() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
unsafe { (*cell_ptr).value = src_val; }
|
unsafe {
|
||||||
|
(*cell_ptr).value = src_val;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +199,9 @@ impl Vm {
|
|||||||
if uv_idx < upvals.len() {
|
if uv_idx < upvals.len() {
|
||||||
let cell = upvals[uv_idx];
|
let cell = upvals[uv_idx];
|
||||||
if !cell.is_null() {
|
if !cell.is_null() {
|
||||||
unsafe { (*cell).value = src_val; }
|
unsafe {
|
||||||
|
(*cell).value = src_val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ fn closure_nested_decl_reads_outer_var() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn closure_counter_escape() {
|
fn closure_counter_escape() {
|
||||||
let result = eval("function counter(){ var n=0; return function(){ return ++n; }; } var c=counter(); c(); c()").unwrap();
|
let result =
|
||||||
|
eval("function counter(){ var n=0; return function(){ return ++n; }; } var c=counter(); c(); c()").unwrap();
|
||||||
assert_eq!(result.as_int(), 2);
|
assert_eq!(result.as_int(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user