From b48e178969e7de319d0a96fcb4c60aeb0e057df5 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 29 Apr 2016 17:56:06 +0200 Subject: JS target improvements --- compiler/jsgen.nim | 7 +++++-- lib/system/jssys.nim | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 840a68e99..ea58bb7dd 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1648,8 +1648,11 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) = of mChr, mArrToSeq: gen(p, n.sons[1], r) # nothing to do of mOrd: genOrd(p, n, r) of mLengthStr: - unaryExpr(p, n, r, "", "($1 != null ? $1.length-1 : 0)" | - "strlen($1)") + if p.target == targetJS and n.sons[1].typ.skipTypes(abstractInst).kind == tyCString: + unaryExpr(p, n, r, "", "($1 != null ? $1.length : 0)") + else: + unaryExpr(p, n, r, "", "($1 != null ? $1.length-1 : 0)" | + "strlen($1)") of mXLenStr: unaryExpr(p, n, r, "", "$1.length-1" | "strlen($1)") of mLengthSeq, mLengthOpenArray, mLengthArray: unaryExpr(p, n, r, "", "($1 != null ? $1.length : 0)" | diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index 1b98883b9..cdaf7dae6 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -97,6 +97,8 @@ proc rawWriteStackTrace(): string = else: result = "No stack traceback available\n" +proc getStackTrace*(): string = rawWriteStackTrace() + proc unhandledException(e: ref Exception) {. compilerproc, asmNoStackFrame.} = when NimStackTrace: -- cgit 1.4.1-2-gfad0