summary refs log tree commit diff stats
path: root/tests/js
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2020-10-30 22:34:07 +0800
committerGitHub <noreply@github.com>2020-10-30 15:34:07 +0100
commit2cfe5e0745cf33ed5698378dd16e01ce542f05e5 (patch)
treedc02bae647a25dc5c54875d62866823247dd85b7 /tests/js
parent6fe2e8977d0227a454cfb606c821cc455a9d0e07 (diff)
downloadNim-2cfe5e0745cf33ed5698378dd16e01ce542f05e5.tar.gz
[closes #11625 and closes #2488]add global and threadvar(with `--threads:off` mode ) pragmas supports for JS backend (#15772)
* add global pragma support for js backend

* globalThis

* add support for threadvar

* more tests

* Update compiler/jsgen.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Diffstat (limited to 'tests/js')
-rw-r--r--tests/js/tglobal.nim30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/js/tglobal.nim b/tests/js/tglobal.nim
new file mode 100644
index 000000000..38f5eec34
--- /dev/null
+++ b/tests/js/tglobal.nim
@@ -0,0 +1,30 @@
+block global:
+  proc getState(): int =
+    var state0 {.global.}: int
+    inc state0
+    result = state0
+
+  for i in 0 ..< 3:
+    doAssert getState() == i + 1
+
+  for i in 0 ..< 3:
+    once:
+      doAssert i == 0
+
+
+block threadvar:
+  proc getThreadState0(): int =
+    var state0 {.threadvar.}: int
+    inc state0
+    result = state0
+
+  for i in 0 ..< 3:
+    doAssert getThreadState0() == i + 1
+
+  proc getThreadState1(): int =
+    var state1 {.threadvar.}: int
+    inc state1
+    result = state1
+
+  for i in 0 ..< 3:
+    doAssert getThreadState1() == i + 1