Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc nim js #95

Open
1 task
timotheecour opened this issue Apr 6, 2020 · 12 comments
Open
1 task

misc nim js #95

timotheecour opened this issue Apr 6, 2020 · 12 comments
Labels

Comments

@timotheecour
Copy link
Owner

timotheecour commented Apr 6, 2020

links

https://developers.google.com/web/updates/2017/06/headless-karma-mocha-chai
https://developers.google.com/web/updates/2017/04/headless-chrome
cheerp: Cheerp | C/C++ to WebAssembly compiler

@timotheecour
Copy link
Owner Author

js target should use jstring everywhere instead of cstring; but we can introduce an alias type cstring = jstring

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 6, 2020

nim js -r -d:nimbrowser main should open simple html template that includes generated js in a browser
(analog to karun)
D20200405T220907

EDIT: could be via:
nim js -r --port:1234 -d:nimbrowser main

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 9, 2020

  • D20200408T181926 runnableExamples for js code (for -d:nimjsbrowser) should be runnable in browser in generated docs from nim doc
    see also D20200408T182006 and D20200405T220907 (which are different though)

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 9, 2020

  • D20200408T183728
    nim js should preserve style eg:
when defined case5:
  proc fooBar() =
    var barBaz = 1
    echo barBaz
  fooBar()

generates:

function foo_bar_13797801() {
    var bar_baz_13797804 = 1;
    rawEcho(cstrToNimstr((bar_baz_13797804)+""));

  
}
foo_bar_13797801();

=> should be fooBar_13797801 not foo_bar_13797801 etc (makes things easier to search, more consistent etc; plus we already have things like function cstrToNimstr( anyways

@timotheecour
Copy link
Owner Author

enhance openDefaultBrowser: option to open in new window (not new tab)
see D20200408T185200

@timotheecour
Copy link
Owner Author

nim-lang#13974 (comment)

but for nim doc -r main it should be as simple as opening the browser

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 21, 2020

  • I fixed it in a recent PR
    js stacktrace messed up, eg: doesn't show full paths:
$nimb js -r --excessivestacktrace $nim_prs_D/tests/system/tostring.nim
("bee", 3)
("bee", 3)
047FC620
0x10488fd08
(x1: 1, x2: 0x0, x3: @[nil, 0x10488fd08, 0x104892208], x4: 0x10488fd08)
Hint: 44960 LOC; 0.324 sec; 49.844MiB peakmem; Debug build; proj: tostring; out: tostring.js [SuccessX]
("bee", 3)
("bee\x00", 4)
/Users/timothee/git_clone/nim/Nim_prs/tests/system/tostring.js:581
    throw new Error(cbuf_3715201);
    ^

Error: Error: unhandled exception: /Users/timothee/git_clone/nim/Nim_prs/tests/system/tostring.nim(102, 12) `g == "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"`  [AssertionError]
Traceback (most recent call last)
tostring.stringCompare, line: 102
assertions.failedAssertImpl, line: 29
assertions.raiseAssert, line: 22
sysFatal.sysFatal, line: 49

    at unhandledException (/Users/timothee/git_clone/nim/Nim_prs/tests/system/tostring.js:581:11)
    at raiseException (/Users/timothee/git_clone/nim/Nim_prs/tests/system/tostring.js:319:5)
    at sys_fatal_3627618 (/Users/timothee/git_clone/nim/Nim_prs/tests/system/tostring.js:594:5)
    at raise_assert_3627614 (/Users/timothee/git_clone/nim/Nim_prs/tests/system/tostring.js:603:5)
    at failed_assert_impl_3627680 (/Users/timothee/git_clone/nim/Nim_prs/tests/system/tostring.js:612:5)
    at string_compare_13475214 (/Users/timothee/git_clone/nim/Nim_prs/tests/system/tostring.js:1743:5)
    at Object.<anonymous> (/Users/timothee/git_clone/nim/Nim_prs/tests/system/tostring.js:2148:1)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
Error: execution of an external program failed: '/usr/local/Cellar/node/13.12.0/bin/node /Users/timothee/git_clone/nim/Nim_prs/tests/system/tostring.js '
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp js <file>

@timotheecour
Copy link
Owner Author

timotheecour commented Apr 21, 2020

testament/testament --targets:js --nim:$nimb r tests/js/trefbyvar.nim doesn't work
(eg when file doesn't specify a target entry)

also, why is c appended to targets:

testament/testament --nim:$nimb r tests/js/trefbyvar.nim
gtk+3 3.24.14
PASS: tests/js/trefbyvar.nim C                                     ( 0.48 sec)
PASS: tests/js/trefbyvar.nim JS                                    ( 0.74 sec)
Used bin/nim.pr_dollar_ptr to run the tests. Use --nim to override.

=> nim-lang#14242

@timotheecour
Copy link
Owner Author

test all importjs automatically to make sure they're correct (avoiding errors like #87 (comment))

@timotheecour
Copy link
Owner Author

introduce jstring and remap cstring to Uint8Array
see cstring implicit conversion to pointer broken on JS · Issue #14097 · nim-lang/Nim

@timotheecour
Copy link
Owner Author

  • add: === to jsffi

refs: nim-lang#16409 (comment)

proc `===`[T1, T2](a: T1, b: T2): bool {.importjs: "# === #.}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant