summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorrecloser <44084068+recloser@users.noreply.github.com>2018-10-21 21:18:10 +0200
committerrecloser <44084068+recloser@users.noreply.github.com>2018-10-21 21:18:10 +0200
commit2b03bed2db195c132bcd68939f4f9f5a3f4fcf9f (patch)
tree2305052c9bd0f3452dd01bf2b0ba498917e83030 /lib
parentce05a850a55a651bcdd01e7af9af9702c8af5caf (diff)
downloadNim-2b03bed2db195c132bcd68939f4f9f5a3f4fcf9f.tar.gz
Fix printing and comparing uninitialized strings
Diffstat (limited to 'lib')
-rw-r--r--lib/system/jssys.nim3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim
index 836ac198d..5ac0ca8b2 100644
--- a/lib/system/jssys.nim
+++ b/lib/system/jssys.nim
@@ -228,6 +228,7 @@ proc cstrToNimstr(c: cstring): string {.asmNoStackFrame, compilerproc.} =
 
 proc toJSStr(s: string): cstring {.asmNoStackFrame, compilerproc.} =
   asm """
+  if (`s` === null) return "";
   var len = `s`.length;
   var asciiPart = new Array(len);
   var fcc = String.fromCharCode;
@@ -330,6 +331,8 @@ proc cmp(x, y: string): int =
 proc eqStrings(a, b: string): bool {.asmNoStackFrame, compilerProc.} =
   asm """
     if (`a` == `b`) return true;
+    if (`a` === null && `b`.length == 0) return true;
+    if (`b` === null && `a`.length == 0) return true;
     if ((!`a`) || (!`b`)) return false;
     var alen = `a`.length;
     if (alen != `b`.length) return false;