mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-28 02:03:59 +00:00
fixes #4299 fixes #12492 fixes #10849 It binds `function` with `env`: `function.bind(:env)` to ease codegen for now
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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`;
|
||||
}
|
||||
"""
|
||||
.}
|
||||
|
||||
Reference in New Issue
Block a user