From 2166b7bc46419a78b9e22062959e7272dfb89692 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Thu, 15 Oct 2015 15:00:30 +0300 Subject: Fixed ret by var in js --- lib/system/jssys.nim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/system') diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index eb6080d38..5bcddc5e6 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -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) -- cgit 1.4.1-2-gfad0