blob: 4cd9cfcd22a970abffdedd601d25a45dca4724d2 [file] [log] [blame]
sbarati@apple.com25dea422016-12-23 01:32:30 +00001import Builder from '../Builder.js'
2import * as assert from '../assert.js'
3
4const builder = (new Builder())
5 .Type().End()
6 .Import()
7 .Function("import", "sideEffects", {params: [], ret: "void"})
8 .End()
9 .Function().End()
10 .Export()
11 .Function("foo")
12 .Function("bar")
13 .End()
14 .Code()
15 .Function("foo", {params: ["i64"], ret: "void"})
16 .Call(0)
17 .Return()
18 .End()
19 .Function("bar", {params: [], ret: "i64"})
20 .Call(0)
21 .I32Const(25)
22 .I64ExtendUI32()
23 .Return()
24 .End()
25 .End();
26
27const bin = builder.WebAssembly().get();
28const module = new WebAssembly.Module(bin);
29let called = false;
30const imp = {
31 import: {
32 sideEffects() { called = true; }
33 }
34};
35
36const instance = new WebAssembly.Instance(module, imp);
37assert.throws(() => instance.exports.foo(20), WebAssembly.RuntimeError, "WebAssembly function with an i64 argument can't be called from JavaScript");
38assert.throws(() => instance.exports.foo({valueOf() { throw new Error("Should not be called!"); }}), WebAssembly.RuntimeError, "WebAssembly function with an i64 argument can't be called from JavaScript");
39assert.throws(() => instance.exports.bar(), WebAssembly.RuntimeError, "WebAssembly function that returns i64 can't be called from JavaScript");
40assert.eq(called, false);