summary refs log tree commit diff stats
path: root/lib/system/jssys.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/system/jssys.nim')
-rw-r--r--lib/system/jssys.nim12
1 files changed, 9 insertions, 3 deletions
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)