summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorrec <44084068+recloser@users.noreply.github.com>2018-12-04 12:04:27 +0100
committerAndreas Rumpf <rumpf_a@web.de>2018-12-04 12:04:27 +0100
commite3e5ae287f9a10ab9ee350e64982f21c44238594 (patch)
tree7ae04f1401c62ef4b31cbbce5134dfb3555a20e9 /lib
parent07744b6e47ef1e83630d628c7d1eae4f3aa5bee5 (diff)
downloadNim-e3e5ae287f9a10ab9ee350e64982f21c44238594.tar.gz
Fix fat pointers, object copying, magic double evals on JS (#9411) [backport]
* Add a test for issue #9389

* Fixes #9389.

* Make object contructors copy objects properly by checking whether the expressions passed to them don't need to be copied.
* Make mArrToSeq implementation actually check if a copy needs to be made.

* Avoid unnecessary copy in mChr impl

* Assume set constructor elements need no copy

* Add a test for issue #9410

* Add a test

* fix passing fat pointers (#9410)

* Enhance tests

* More tests and fixes

* Add more (failing) tests [ci skip]

* Added equality operator for fat pointers, more tests and fixes

* Fix printing uninitialized strings

* Fix mInc, mDec double eval, add more tests

* Tests

* Refactored, fixed multiple evals, revamped the tests, added missing ops

* Fix ups

* Fix #9643 and #9644

* add pointer normalization
Diffstat (limited to 'lib')
-rw-r--r--lib/system.nim11
-rw-r--r--lib/system/jssys.nim7
-rw-r--r--lib/system/reprjs.nim4
3 files changed, 14 insertions, 8 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 9111ddd86..0bb53d9df 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -2522,12 +2522,13 @@ proc `==`*[T](x, y: seq[T]): bool {.noSideEffect.} =
     when not defined(JS):
       proc seqToPtr[T](x: seq[T]): pointer {.inline, nosideeffect.} =
         result = cast[pointer](x)
-    else:
-      proc seqToPtr[T](x: seq[T]): pointer {.asmNoStackFrame, nosideeffect.} =
-        asm """return `x`"""
 
-    if seqToPtr(x) == seqToPtr(y):
-      return true
+      if seqToPtr(x) == seqToPtr(y):
+        return true
+    else:
+      var sameObject = false
+      asm """`sameObject` = `x` === `y`"""
+      if sameObject: return true
 
   when not defined(nimNoNil):
     if x.isNil or y.isNil:
diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim
index 5ac0ca8b2..8be19e5b8 100644
--- a/lib/system/jssys.nim
+++ b/lib/system/jssys.nim
@@ -519,8 +519,11 @@ proc nimCopyAux(dest, src: JSRef, n: ptr TNimNode) {.compilerproc.} =
       `dest`[`n`.offset] = nimCopy(`dest`[`n`.offset], `src`[`n`.offset], `n`.typ);
     """
   of nkList:
-    for i in 0..n.len-1:
-      nimCopyAux(dest, src, n.sons[i])
+    asm """
+    for (var i = 0; i < `n`.sons.length; i++) {
+      nimCopyAux(`dest`, `src`, `n`.sons[i]);
+    }
+    """
   of nkCase:
     asm """
       `dest`[`n`.offset] = nimCopy(`dest`[`n`.offset], `src`[`n`.offset], `n`.typ);
diff --git a/lib/system/reprjs.nim b/lib/system/reprjs.nim
index 7cb25a252..fb231bbed 100644
--- a/lib/system/reprjs.nim
+++ b/lib/system/reprjs.nim
@@ -64,7 +64,9 @@ proc reprStrAux(result: var string, s: cstring, len: int) =
 
 proc reprStr(s: string): string {.compilerRtl.} =
   result = ""
-  if cast[pointer](s).isNil:
+  var sIsNil = false
+  asm """`sIsNil` = `s` === null"""
+  if sIsNil: # cast[pointer](s).isNil:
     # Handle nil strings here because they don't have a length field in js
     # TODO: check for null/undefined before generating call to length in js?
     # Also: c backend repr of a nil string is <pointer>"", but repr of an