sbarati@apple.com | 25dea42 | 2016-12-23 01:32:30 +0000 | [diff] [blame] | 1 | import Builder from '../Builder.js' |
| 2 | import * as assert from '../assert.js' |
| 3 | |
| 4 | const 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 | |
| 27 | const bin = builder.WebAssembly().get(); |
| 28 | const module = new WebAssembly.Module(bin); |
| 29 | let called = false; |
| 30 | const imp = { |
| 31 | import: { |
| 32 | sideEffects() { called = true; } |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | const instance = new WebAssembly.Instance(module, imp); |
| 37 | assert.throws(() => instance.exports.foo(20), WebAssembly.RuntimeError, "WebAssembly function with an i64 argument can't be called from JavaScript"); |
| 38 | assert.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"); |
| 39 | assert.throws(() => instance.exports.bar(), WebAssembly.RuntimeError, "WebAssembly function that returns i64 can't be called from JavaScript"); |
| 40 | assert.eq(called, false); |