Skip to content

Commit eadd0d7

Browse files
authored
Initialize newString in js [backport:1.6] (nim-lang#22745)
```nim echo newString(8) ``` results in: ``` D:\User\test.js:25 var code_33556944 = c_33556931.toString(16); ^ TypeError: Cannot read properties of undefined (reading 'toString') at toJSStr (D:\User\test.js:25:50) at rawEcho (D:\User\test.js:70:16) at Object.<anonymous> (D:\User\test.js:101:1) at Module._compile (node:internal/modules/cjs/loader:1095:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10) at Module.load (node:internal/modules/cjs/loader:975:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:17:47 Node.js v17.0.1 Error: execution of an external program failed: '"C:\Program Files\nodejs\node.exe" --unhandled-rejections=strict D:\User\test.js' ```
1 parent b10a809 commit eadd0d7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/system/jssys.nim

+3-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ proc toJSStr(s: string): cstring {.compilerproc.} =
278278

279279
proc mnewString(len: int): string {.asmNoStackFrame, compilerproc.} =
280280
asm """
281-
return new Array(`len`);
281+
var result = new Array(`len`);
282+
for (var i = 0; i < `len`; i++) {result[i] = 0;}
283+
return result;
282284
"""
283285

284286
proc SetCard(a: int): int {.compilerproc, asmNoStackFrame.} =

0 commit comments

Comments
 (0)