Index: test/mjsunit/wasm/asm-wasm.js |
diff --git a/test/mjsunit/wasm/asm-wasm.js b/test/mjsunit/wasm/asm-wasm.js |
index 603ca0124188924ee26bca0866acded3cc7609a8..d1e631094c7fe2df2a5ce1bf83e87a21ea59e92c 100644 |
--- a/test/mjsunit/wasm/asm-wasm.js |
+++ b/test/mjsunit/wasm/asm-wasm.js |
@@ -1080,3 +1080,46 @@ function TestForeignFunctionMultipleUse() { |
} |
TestForeignFunctionMultipleUse(); |
+ |
+ |
+function TestForeignVariables() { |
aseemgarg
2016/02/09 02:38:56
Might want to also write test that uses same forei
bradnelson
2016/02/09 04:55:23
Done.
|
+ function AsmModule(stdlib, foreign, buffer) { |
+ "use asm"; |
+ |
+ var i1 = foreign.foo | 0; |
+ var f1 = +foreign.bar; |
+ |
+ function geti() { |
+ return i1|0; |
+ } |
+ |
+ function getf() { |
+ return +f1; |
+ } |
+ |
+ return {geti:geti, getf:getf}; |
+ } |
+ |
+ // Check normal operation. |
+ var module = _WASMEXP_.instantiateModuleFromAsm( |
+ AsmModule.toString(), {foo: 123, bar: 234}, null); |
+ module.__init__(); |
+ assertEquals(123, module.geti()); |
+ assertEquals(234, module.getf()); |
+ |
+ // Check that undefined values are converted to zero. |
aseemgarg
2016/02/09 02:38:56
As discussed, doubles should flow as NaNs. Please
bradnelson
2016/02/09 04:55:23
Done.
|
+ var module = _WASMEXP_.instantiateModuleFromAsm( |
+ AsmModule.toString(), {baz: 678}, null); |
+ module.__init__(); |
+ assertEquals(0, module.geti()); |
+ assertEquals(0, module.getf()); |
+ |
+ // Check that a missing ffi object is safe. |
+ var module = _WASMEXP_.instantiateModuleFromAsm( |
+ AsmModule.toString()); |
+ module.__init__(); |
+ assertEquals(0, module.geti()); |
+ assertEquals(0, module.getf()); |
+} |
+ |
+TestForeignVariables(); |