use of org.graalvm.wasm.WasmTable in project graal by oracle.
the class WasmJsApiSuite method testTableEmbedderData.
@Test
public void testTableEmbedderData() throws IOException {
runTest(context -> {
WasmTable table = WebAssembly.tableAlloc(1, 1);
checkEmbedderData(table);
});
}
use of org.graalvm.wasm.WasmTable in project graal by oracle.
the class WasmJsApiSuite method testInstantiateWithExportTable.
@Test
public void testInstantiateWithExportTable() throws IOException {
runTest(context -> {
final WebAssembly wasm = new WebAssembly(context);
final WasmInstance instance = moduleInstantiate(wasm, binaryWithTableExport, null);
try {
final WasmTable table = (WasmTable) WebAssembly.instanceExport(instance, "defaultTable");
final Object result = InteropLibrary.getUncached().execute(WebAssembly.tableRead(table, 0), 9);
Assert.assertEquals("Must be 81.", 81, result);
} catch (UnsupportedTypeException | UnsupportedMessageException | ArityException e) {
throw new RuntimeException(e);
}
});
}
use of org.graalvm.wasm.WasmTable in project graal by oracle.
the class WasmJsApiSuite method testExportSameFunctionInAndOutsideTable.
@Test
public void testExportSameFunctionInAndOutsideTable() throws IOException, InterruptedException {
final byte[] sameFunctionInExportAndTable = compileWat("sameFunctionInExportAndTable", "(module (func $f (result i32) i32.const 1) (table 1 funcref) (elem (i32.const 0) $f) (export \"f\" (func $f)) (export \"t\" (table 0)))");
runTest(context -> {
final WebAssembly wasm = new WebAssembly(context);
final WasmInstance instance = moduleInstantiate(wasm, sameFunctionInExportAndTable, null);
final Object f = WebAssembly.instanceExport(instance, "f");
final WasmTable t = (WasmTable) WebAssembly.instanceExport(instance, "t");
final Object fInTable = WebAssembly.tableRead(t, 0);
Assert.assertTrue("Returned function instances must be reference equal", f == fInTable);
});
}
use of org.graalvm.wasm.WasmTable in project graal by oracle.
the class WasmJsApiSuite method testTableGrowLimit.
@Test
public void testTableGrowLimit() throws IOException {
runTest(context -> {
try {
WasmTable table = WebAssembly.tableAlloc(1, 1);
WebAssembly.tableGrow(table, 1);
Assert.fail("Should have failed - try to grow table beyond max size");
} catch (WasmJsApiException e) {
Assert.assertEquals("Range error expected", WasmJsApiException.Kind.RangeError, e.kind());
}
});
}
use of org.graalvm.wasm.WasmTable in project graal by oracle.
the class WasmJsApiSuite method testExportSameFunctionAtDifferentTableIndices.
@Test
public void testExportSameFunctionAtDifferentTableIndices() throws IOException, InterruptedException {
final byte[] sameFunctionInExportAndTable = compileWat("sameFunctionInExportAndTable", "(module (func $f (result i32) i32.const 1) (table 2 funcref) (elem (i32.const 0) $f) (elem (i32.const 1) $f) (export \"t\" (table 0)))");
runTest(context -> {
final WebAssembly wasm = new WebAssembly(context);
final WasmInstance instance = moduleInstantiate(wasm, sameFunctionInExportAndTable, null);
final WasmTable t = (WasmTable) WebAssembly.instanceExport(instance, "t");
final Object f1 = WebAssembly.tableRead(t, 0);
final Object f2 = WebAssembly.tableRead(t, 1);
Assert.assertTrue("Returned function instances must be reference equal", f1 == f2);
});
}
Aggregations