mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 08:34:20 +00:00
Fix add(string, cstring) when the lhs is null (#8951)
This commit is contained in:
@@ -2741,10 +2741,11 @@ type
|
||||
when defined(JS):
|
||||
proc add*(x: var string, y: cstring) {.asmNoStackFrame.} =
|
||||
asm """
|
||||
var len = `x`.length;
|
||||
if (`x` === null) { `x` = []; }
|
||||
var off = `x`.length;
|
||||
`x`.length += `y`.length;
|
||||
for (var i = 0; i < `y`.length; ++i) {
|
||||
`x`[len] = `y`.charCodeAt(i);
|
||||
++len;
|
||||
`x`[off+i] = `y`.charCodeAt(i);
|
||||
}
|
||||
"""
|
||||
proc add*(x: var cstring, y: cstring) {.magic: "AppendStrStr".}
|
||||
|
||||
4
tests/js/taddnilstr.nim
Normal file
4
tests/js/taddnilstr.nim
Normal file
@@ -0,0 +1,4 @@
|
||||
var x = "foo".cstring
|
||||
var y: string
|
||||
add(y, x)
|
||||
doAssert y == "foo"
|
||||
Reference in New Issue
Block a user