feat: implement closure over "this" in methods and fix upvalue closing order
Add support for closing over "this" in function closures defined inside methods by naming the receiver local variable "this" in method compilers. Fix upvalue closing to copy the actual value instead of the stack top, and reorder return handling to close upvalues before storing the result. Add test cases for closure over "this", nested closures, and nested classes.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
class Foo {
|
||||
getClosure {
|
||||
return fn {
|
||||
return this.toString
|
||||
}
|
||||
}
|
||||
|
||||
toString { return "Foo" }
|
||||
}
|
||||
|
||||
var closure = (new Foo).getClosure
|
||||
io.write(closure.call) // expect: Foo
|
||||
Reference in New Issue
Block a user