test262-automation e9a5a7f918 [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time) (#1620)
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
2018-07-03 15:59:58 -04:00

193 lines
5.1 KiB
JavaScript

import * as assert from '../assert.js';
import Builder from '../Builder.js';
assert.isFunction(WebAssembly.instantiate);
assert.isFunction(WebAssembly.__proto__.instantiate);
assert.eq(WebAssembly.instantiate.length, 1);
{
const builder = (new Builder())
.Type().End()
.Function().End()
.Export()
.Function("foo")
.End()
.Code()
.Function("foo", { params: [], ret: "i32" })
.I32Const(1)
.End()
.End();
const bin = builder.WebAssembly().get();
async function test() {
let {module, instance} = await WebAssembly.instantiate(bin);
assert.truthy(module instanceof WebAssembly.Module);
assert.truthy(instance instanceof WebAssembly.Instance);
assert.eq(instance.exports.foo(20), 1);
}
assert.asyncTest(test());
}
{
const builder = (new Builder())
.Type().End()
.Function().End()
.Export()
.Function("foo")
.End()
.Code()
.Function("foo", { params: [], ret: "i32" })
.I32Const(1)
.End()
.End();
const bin = builder.WebAssembly().get();
async function test() {
try {
let {module, instance} = await WebAssembly.instantiate(bin, null);
} catch(e) {
assert.eq(e.message, "second argument to WebAssembly.instantiate must be undefined or an Object (evaluating 'WebAssembly.instantiate(bin, null)')");
}
}
assert.asyncTest(test());
}
{
const builder = (new Builder())
.Type().End()
.Function().End()
.Export()
.Function("foo")
.End()
.Code()
.Function("foo", { params: [], ret: "i32" })
.F32Const(1)
.End()
.End();
const bin = builder.WebAssembly().get();
async function test() {
try {
let {module, instance} = await WebAssembly.instantiate(bin);
} catch(e) {
assert.truthy(e instanceof WebAssembly.CompileError);
assert.eq(e.message, "WebAssembly.Module doesn't validate: control flow returns with unexpected type, in function at index 0");
}
}
assert.asyncTest(test());
}
{
const builder = (new Builder())
.Type().End()
.Import().Memory("imp", "memory", {initial:100}).End()
.Function().End()
.Export()
.Function("foo")
.End()
.Code()
.Function("foo", { params: [], ret: "i32" })
.I32Const(1)
.End()
.End();
const bin = builder.WebAssembly().get();
async function test() {
try {
let {module, instance} = await WebAssembly.instantiate(bin, {imp: {memory: 20}});
} catch(e) {
assert.eq(e.message, "Memory import imp:memory is not an instance of WebAssembly.Memory");
}
}
assert.asyncTest(test());
}
{
const builder = (new Builder())
.Type().End()
.Import().Memory("imp", "memory", {initial:100}).End()
.Function().End()
.Export()
.Function("foo")
.End()
.Code()
.Function("foo", { params: [], ret: "i32" })
.I32Const(1)
.End()
.End();
const bin = builder.WebAssembly().get();
async function test() {
try {
const module = new WebAssembly.Module(bin);
let instance = await WebAssembly.instantiate(bin, {imp: {memory: 20}});
} catch(e) {
assert.eq(e.message, "Memory import imp:memory is not an instance of WebAssembly.Memory");
}
}
assert.asyncTest(test());
}
{
const builder = (new Builder())
.Type().End()
.Function().End()
.Export()
.Function("foo")
.End()
.Code()
.Function("foo", { params: [], ret: "i32" })
.I32Const(1)
.End()
.End();
const bin = builder.WebAssembly().get();
async function test() {
let module = new WebAssembly.Module(bin);
let instance = await WebAssembly.instantiate(module);
assert.truthy(instance instanceof WebAssembly.Instance);
assert.eq(instance.exports.foo(20), 1);
}
assert.asyncTest(test());
}
{
const builder = (new Builder())
.Type().End()
.Import().Memory("imp", "memory", {initial:100}).End()
.Function().End()
.Export()
.Function("foo")
.End()
.Code()
.Function("foo", { params: [], ret: "i32" })
.I32Const(1)
.End()
.End();
const bin = builder.WebAssembly().get();
async function test() {
try {
await WebAssembly.instantiate(25);
} catch(e) {
// FIXME: Better error message here.
assert.eq(e.message, "first argument must be an ArrayBufferView or an ArrayBuffer (evaluating 'WebAssembly.instantiate(25)')");
}
}
assert.asyncTest(test());
}