mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-25 16:53:59 +00:00
Correctly mangle this in the JS backend (#8853)
As shown in pragmagic/karax#67 using `this` as parameter name made the codegen output wrong code (and the user didn't notice the errors in the browser console).
This commit is contained in:
@@ -267,8 +267,8 @@ block:
|
||||
type TestObject = object
|
||||
a: int
|
||||
onWhatever: proc(e: int): int
|
||||
proc handleWhatever(that: TestObject, e: int): int =
|
||||
e + that.a
|
||||
proc handleWhatever(this: TestObject, e: int): int =
|
||||
e + this.a
|
||||
proc test(): bool =
|
||||
let obj = TestObject(a: 9, onWhatever: bindMethod(handleWhatever))
|
||||
obj.onWhatever(1) == 10
|
||||
|
||||
23
tests/js/tthismangle.nim
Normal file
23
tests/js/tthismangle.nim
Normal file
@@ -0,0 +1,23 @@
|
||||
proc moo1(this: int) =
|
||||
doAssert this == 42
|
||||
|
||||
proc moo2(x: int) =
|
||||
var this = x
|
||||
doAssert this == 42
|
||||
|
||||
proc moo3() =
|
||||
for this in [1,1,1]:
|
||||
doAssert this == 1
|
||||
|
||||
proc moo4() =
|
||||
type
|
||||
X = object
|
||||
this: int
|
||||
|
||||
var q = X(this: 42)
|
||||
doAssert q.this == 42
|
||||
|
||||
moo1(42)
|
||||
moo2(42)
|
||||
moo3()
|
||||
moo4()
|
||||
Reference in New Issue
Block a user