Search in sources :

Example 6 with WasmTable

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);
    });
}
Also used : WasmTable(org.graalvm.wasm.WasmTable) Test(org.junit.Test)

Example 7 with WasmTable

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);
        }
    });
}
Also used : WasmInstance(org.graalvm.wasm.WasmInstance) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) WebAssembly(org.graalvm.wasm.api.WebAssembly) WasmTable(org.graalvm.wasm.WasmTable) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ArityException(com.oracle.truffle.api.interop.ArityException) Test(org.junit.Test)

Example 8 with WasmTable

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);
    });
}
Also used : WasmInstance(org.graalvm.wasm.WasmInstance) WebAssembly(org.graalvm.wasm.api.WebAssembly) WasmTable(org.graalvm.wasm.WasmTable) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 9 with WasmTable

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());
        }
    });
}
Also used : WasmJsApiException(org.graalvm.wasm.exception.WasmJsApiException) WasmTable(org.graalvm.wasm.WasmTable) Test(org.junit.Test)

Example 10 with WasmTable

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);
    });
}
Also used : WasmInstance(org.graalvm.wasm.WasmInstance) WebAssembly(org.graalvm.wasm.api.WebAssembly) WasmTable(org.graalvm.wasm.WasmTable) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Aggregations

WasmTable (org.graalvm.wasm.WasmTable)14 Test (org.junit.Test)7 WasmInstance (org.graalvm.wasm.WasmInstance)6 WasmJsApiException (org.graalvm.wasm.exception.WasmJsApiException)6 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)5 WebAssembly (org.graalvm.wasm.api.WebAssembly)5 WasmFunction (org.graalvm.wasm.WasmFunction)3 WasmFunctionInstance (org.graalvm.wasm.WasmFunctionInstance)3 WasmMemory (org.graalvm.wasm.memory.WasmMemory)3 InteropException (com.oracle.truffle.api.interop.InteropException)2 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)2 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)2 HashMap (java.util.HashMap)2 SymbolTable (org.graalvm.wasm.SymbolTable)2 WasmGlobal (org.graalvm.wasm.globals.WasmGlobal)2 CallTarget (com.oracle.truffle.api.CallTarget)1 BytecodeInterpreterSwitch (com.oracle.truffle.api.HostCompilerDirectives.BytecodeInterpreterSwitch)1 BytecodeInterpreterSwitchBoundary (com.oracle.truffle.api.HostCompilerDirectives.BytecodeInterpreterSwitchBoundary)1 TruffleContext (com.oracle.truffle.api.TruffleContext)1 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1