diff options
author | hlaaftana <10591326+hlaaftana@users.noreply.github.com> | 2021-02-11 19:04:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-11 17:04:32 +0100 |
commit | 81533a0014a8372207426dc9d067aff4b59db8af (patch) | |
tree | 8f34f7f70a0a2b2b7e1400315f74e9c97c51fdf2 /lib | |
parent | f3c39bf2d99d964c5b8fd88c3b8940b0cf5c1b9b (diff) | |
download | Nim-81533a0014a8372207426dc9d067aff4b59db8af.tar.gz |
[backport:1.4] JS cstring null fixes (#16979)
* [backport:1.4] JS cstring null fixes * fix JS move string * make it look cleaner
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system.nim | 18 | ||||
-rw-r--r-- | lib/system/jssys.nim | 2 |
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/system.nim b/lib/system.nim index 82b8a6586..09a7faca9 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2029,8 +2029,14 @@ type when NimStackTraceMsgs: frameMsgLen*: int ## end position in frameMsgBuf for this frame. -when defined(js): +when defined(js) or defined(nimdoc): proc add*(x: var string, y: cstring) {.asmNoStackFrame.} = + ## Appends `y` to `x` in place. + runnableExamples: + var tmp = "" + tmp.add(cstring("ab")) + tmp.add(cstring("cd")) + doAssert tmp == "abcd" asm """ if (`x` === null) { `x` = []; } var off = `x`.length; @@ -2039,7 +2045,15 @@ when defined(js): `x`[off+i] = `y`.charCodeAt(i); } """ - proc add*(x: var cstring, y: cstring) {.magic: "AppendStrStr".} + proc add*(x: var cstring, y: cstring) {.magic: "AppendStrStr".} = + ## Appends `y` to `x` in place. + ## Only implemented for JS backend. + runnableExamples: + when defined(js): + var tmp: cstring = "" + tmp.add(cstring("ab")) + tmp.add(cstring("cd")) + doAssert tmp == cstring("abcd") elif hasAlloc: {.push stackTrace: off, profiler: off.} diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index 64c766482..ef06437e5 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -645,7 +645,7 @@ proc genericReset(x: JSRef, ti: PNimType): JSRef {.compilerproc.} = asm "`result` = {m_type: `ti`};" else: asm "`result` = {};" - of tySequence, tyOpenArray: + of tySequence, tyOpenArray, tyString: asm """ `result` = []; """ |