fix for js strict mode (#18799)

* Assignments, which would accidentally create global
variables, instead throw an error in strict mode

* Assignment to a getter-only property

Co-authored-by: Sven Keller <s.keller@cortona.de>
This commit is contained in:
Sven Keller
2021-09-04 12:53:02 +02:00
committed by GitHub
parent 686096a912
commit 3c2edd142b
2 changed files with 2 additions and 5 deletions

View File

@@ -1769,7 +1769,7 @@ proc genVarInit(p: PProc, v: PSym, n: PNode) =
inc p.extraIndent
elif useGlobalPragmas:
lineF(p, "if (globalThis.$1 === undefined) {$n", varName)
varCode = $varName
varCode = "globalThis." & $varName
inc p.extraIndent
else:
varCode = "var $2"

View File

@@ -593,12 +593,9 @@ proc nimCopy(dest, src: JSRef, ti: PNimType): JSRef =
`result` = null;
}
else {
if (`dest` === null || `dest` === undefined) {
if (`dest` === null || `dest` === undefined || `dest`.length != `src`.length) {
`dest` = new Array(`src`.length);
}
else {
`dest`.length = `src`.length;
}
`result` = `dest`;
for (var i = 0; i < `src`.length; ++i) {
`result`[i] = nimCopy(`result`[i], `src`[i], `ti`.base);