[backport:1.4] JS cstring null fixes (#16979)
* [backport:1.4] JS cstring null fixes * fix JS move string * make it look cleaner
This commit is contained in:
parent
f3c39bf2d9
commit
81533a0014
5 changed files with 69 additions and 8 deletions
|
|
@ -2011,7 +2011,9 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
|
|||
gen(p, n[2], rhs)
|
||||
|
||||
if skipTypes(n[1].typ, abstractVarRange).kind == tyCString:
|
||||
r.res = "$1 += $2;" % [lhs.rdLoc, rhs.rdLoc]
|
||||
let (b, tmp) = maybeMakeTemp(p, n[2], rhs)
|
||||
r.res = "if (null != $1) { if (null == $2) $2 = $3; else $2 += $3; }" %
|
||||
[b, lhs.rdLoc, tmp]
|
||||
else:
|
||||
let (a, tmp) = maybeMakeTemp(p, n[1], lhs)
|
||||
r.res = "$1.push.apply($3, $2);" % [a, rhs.rdLoc, tmp]
|
||||
|
|
@ -2062,9 +2064,23 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
|
|||
of mDestroy: discard "ignore calls to the default destructor"
|
||||
of mOrd: genOrd(p, n, r)
|
||||
of mLengthStr, mLengthSeq, mLengthOpenArray, mLengthArray:
|
||||
unaryExpr(p, n, r, "", "($1).length")
|
||||
var x: TCompRes
|
||||
gen(p, n[1], x)
|
||||
if skipTypes(n[1].typ, abstractInst).kind == tyCString:
|
||||
let (a, tmp) = maybeMakeTemp(p, n[1], x)
|
||||
r.res = "(($1) == null ? 0 : ($2).length)" % [a, tmp]
|
||||
else:
|
||||
r.res = "($1).length" % [x.rdLoc]
|
||||
r.kind = resExpr
|
||||
of mHigh:
|
||||
unaryExpr(p, n, r, "", "(($1).length-1)")
|
||||
var x: TCompRes
|
||||
gen(p, n[1], x)
|
||||
if skipTypes(n[1].typ, abstractInst).kind == tyCString:
|
||||
let (a, tmp) = maybeMakeTemp(p, n[1], x)
|
||||
r.res = "(($1) == null ? -1 : ($2).length - 1)" % [a, tmp]
|
||||
else:
|
||||
r.res = "($1).length - 1" % [x.rdLoc]
|
||||
r.kind = resExpr
|
||||
of mInc:
|
||||
if n[1].typ.skipTypes(abstractRange).kind in {tyUInt..tyUInt64}:
|
||||
binaryUintExpr(p, n, r, "+", true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue