Merge pull request #3273 from yglukhov/js-copy-fix

Fixed JS copying.
This commit is contained in:
Andreas Rumpf 2015-09-03 14:22:10 +02:00
commit 580855d2eb

View file

@ -547,18 +547,14 @@ proc nimCopyAux(dest, src: JSRef, n: ptr TNimNode) {.compilerproc.} =
of nkNone: sysAssert(false, "nimCopyAux") of nkNone: sysAssert(false, "nimCopyAux")
of nkSlot: of nkSlot:
asm """ asm """
var ddest = `dest`[`n`.offset]; `dest`[`n`.offset] = nimCopy(`dest`[`n`.offset], `src`[`n`.offset], `n`.typ);
if (ddest === undefined) ddest = null;
`dest`[`n`.offset] = nimCopy(ddest, `src`[`n`.offset], `n`.typ);
""" """
of nkList: of nkList:
for i in 0..n.len-1: for i in 0..n.len-1:
nimCopyAux(dest, src, n.sons[i]) nimCopyAux(dest, src, n.sons[i])
of nkCase: of nkCase:
asm """ asm """
var ddest = `dest`[`n`.offset]; `dest`[`n`.offset] = nimCopy(`dest`[`n`.offset], `src`[`n`.offset], `n`.typ);
if (ddest === undefined) ddest = null;
`dest`[`n`.offset] = nimCopy(ddest, `src`[`n`.offset], `n`.typ);
for (var i = 0; i < `n`.sons.length; ++i) { for (var i = 0; i < `n`.sons.length; ++i) {
nimCopyAux(`dest`, `src`, `n`.sons[i][1]); nimCopyAux(`dest`, `src`, `n`.sons[i][1]);
} }
@ -579,13 +575,13 @@ proc nimCopy(dest, src: JSRef, ti: PNimType): JSRef =
of tyTuple, tyObject: of tyTuple, tyObject:
if ti.base != nil: result = nimCopy(dest, src, ti.base) if ti.base != nil: result = nimCopy(dest, src, ti.base)
elif ti.kind == tyObject: elif ti.kind == tyObject:
asm "`result` = (`dest` === null) ? {m_type: `ti`} : `dest`;" asm "`result` = (`dest` === null || `dest` === undefined) ? {m_type: `ti`} : `dest`;"
else: else:
asm "`result` = (`dest` === null) ? {} : `dest`;" asm "`result` = (`dest` === null || `dest` === undefined) ? {} : `dest`;"
nimCopyAux(result, src, ti.node) nimCopyAux(result, src, ti.node)
of tySequence, tyArrayConstr, tyOpenArray, tyArray: of tySequence, tyArrayConstr, tyOpenArray, tyArray:
asm """ asm """
if (`dest` === null) { if (`dest` === null || `dest` === undefined) {
`dest` = new Array(`src`.length); `dest` = new Array(`src`.length);
} }
else { else {