Fixed ret by var in js

This commit is contained in:
Yuriy Glukhov 2015-10-15 15:00:30 +03:00
commit 2166b7bc46
8 changed files with 78 additions and 22 deletions

View file

@ -532,7 +532,7 @@ proc nimMax(a, b: int): int {.compilerproc.} = return if a >= b: a else: b
type NimString = string # hack for hti.nim
include "system/hti"
type JSRef = int # Fake type.
type JSRef = ref RootObj # Fake type.
proc isFatPointer(ti: PNimType): bool =
# This has to be consistent with the code generator!
@ -569,8 +569,14 @@ proc nimCopy(dest, src: JSRef, ti: PNimType): JSRef =
asm "`result` = [`src`[0], `src`[1]];"
of tySet:
asm """
`result` = {};
for (var key in `src`) { `result`[key] = `src`[key]; }
if (`dest` === null || `dest` === undefined) {
`dest` = {};
}
else {
for (var key in `dest`) { delete `dest`[key]; }
}
for (var key in `src`) { `dest`[key] = `src`[key]; }
`result` = `dest`;
"""
of tyTuple, tyObject:
if ti.base != nil: result = nimCopy(dest, src, ti.base)