fixes #4299 #12492 #10849; lambda lifting for JS backend (#23484)

fixes #4299 
fixes #12492 
fixes #10849

It binds `function` with `env`: `function.bind(:env)` to ease codegen
for now
This commit is contained in:
ringabout
2024-04-11 15:14:56 +08:00
committed by GitHub
parent 2bd2f28858
commit 779bc8474b
10 changed files with 118 additions and 71 deletions

View File

@@ -468,7 +468,7 @@ proc replaceSyms(n: NimNode): NimNode =
for i in 0..<n.len:
result[i] = replaceSyms(n[i])
macro bindMethod*(procedure: typed): auto =
macro bindMethod*(procedure: typed): auto {.deprecated: "Don't use it with closures".} =
## Takes the name of a procedure and wraps it into a lambda missing the first
## argument, which passes the JavaScript builtin `this` as the first
## argument to the procedure. Returns the resulting lambda.

View File

@@ -781,3 +781,15 @@ if (!Math.trunc) {
};
}
""".}
proc cmpClosures(a, b: JSRef): bool {.compilerproc, asmNoStackFrame.} =
# Both `a` and `b` need to be a closure
{.emit: """
if (`a` !== null && `a`.ClP_0 !== undefined &&
`b` !== null && `b`.ClP_0 !== undefined) {
return `a`.ClP_0 == `b`.ClP_0 && `a`.ClE_0 == `b`.ClE_0;
} else {
return `a` == `b`;
}
"""
.}