diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2015-10-07 09:31:47 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2015-10-07 09:31:47 +0200 |
commit | 050e4815d0f79cb15df57e2743d3fb0791e80e77 (patch) | |
tree | e862660c8cefa0e9ce18da591c663de3f5bf5c5d /tests | |
parent | 52342a11f6e413646a504a77587108398881a28a (diff) | |
parent | d1b67cb9bbf81fbc55aaa4359f626fae71f3ed7a (diff) | |
download | Nim-050e4815d0f79cb15df57e2743d3fb0791e80e77.tar.gz |
Merge pull request #3314 from haiodo/emscripten-support
Emscripten support
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gc/gcemscripten.nim | 59 | ||||
-rw-r--r-- | tests/testament/categories.nim | 1 |
2 files changed, 60 insertions, 0 deletions
diff --git a/tests/gc/gcemscripten.nim b/tests/gc/gcemscripten.nim new file mode 100644 index 000000000..bbef13d98 --- /dev/null +++ b/tests/gc/gcemscripten.nim @@ -0,0 +1,59 @@ +discard """ + outputsub: "77\n77" +""" + +## Check how GC/Alloc works in Emscripten +import strutils + +type + X = ref XObj + XObj = object + name: string + value: int +when defined(allow_print): + const print = true +else: + const print = false + +proc myResult3*(i:int):X {.exportc.} = + if print: echo "3" + new(result) + if print: echo "3-2" + result.value = i + +proc myResult5*(i:int, x:X):X {.exportc.} = + if print: echo "5" + system.GC_fullCollect() + new(result) + if print: echo "5-2" + result.value = i + x.value = i+1 + if result.value == x.value: + echo "This should not happen. Just allocated variable points to parameter" + +proc myResult2*(val: string, i: int): X {.exportc.} = + if print: echo "2-1" + result = myResult3(i) + if print: echo "2-2" + system.GC_fullCollect() + if print: echo "2-3" + var t = new(X) + if print: echo "2-4" + result.name = val + if t.name == "qwe": + echo "This should not happen. Variable is GC collected and new one on same place are allocated." + if print: echo "2-5" + +proc myResult4*(val: string, i: int): X {.exportc.} = + if print: echo "4-1" + result = myResult5(i, X()) + if print: echo "4-2" + +var x = myResult2("qwe", 77) +echo intToStr(x.value) + +var x2 = myResult4("qwe", 77) +echo intToStr(x2.value) + + + diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 9de33acb1..57b28620e 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -124,6 +124,7 @@ proc gcTests(r: var TResults, cat: Category, options: string) = testSpec r, makeTest("tests/gc" / filename, options & " -d:release --gc:markAndSweep", cat, actionRun) + test "gcemscripten" test "growobjcrash" test "gcbench" test "gcleak" |