mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-02 03:54:44 +00:00
[backport:1.4] JS cstring null fixes (#16979)
* [backport:1.4] JS cstring null fixes
* fix JS move string
* make it look cleaner
(cherry picked from commit 81533a0014)
This commit is contained in:
@@ -1957,8 +1957,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;
|
||||
@@ -1967,7 +1973,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.}
|
||||
|
||||
@@ -634,7 +634,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` = [];
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user