Search in sources :

Example 1 with ModuleImportDescriptor

use of org.graalvm.wasm.api.ModuleImportDescriptor in project graal by oracle.

the class WasmJsApiSuite method testImportOrder.

@Test
public void testImportOrder() throws IOException {
    runTest(context -> {
        final WebAssembly wasm = new WebAssembly(context);
        final WasmModule module = wasm.moduleDecode(binaryWithMixedImports);
        final Sequence<ModuleImportDescriptor> moduleImports = WebAssembly.moduleImports(module);
        String[] expected = new String[] { "f1", "g1", "t", "m", "g2", "f2" };
        try {
            Assert.assertEquals("Must import all members.", 6L, moduleImports.getArraySize());
            for (int i = 0; i < moduleImports.getArraySize(); i++) {
                Assert.assertEquals("Module member " + i + " should correspond to the expected import.", expected[i], ((ModuleImportDescriptor) moduleImports.readArrayElement(i)).name());
            }
        } catch (InvalidArrayIndexException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : ModuleImportDescriptor(org.graalvm.wasm.api.ModuleImportDescriptor) WasmModule(org.graalvm.wasm.WasmModule) InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) WebAssembly(org.graalvm.wasm.api.WebAssembly) Test(org.junit.Test)

Aggregations

InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)1 WasmModule (org.graalvm.wasm.WasmModule)1 ModuleImportDescriptor (org.graalvm.wasm.api.ModuleImportDescriptor)1 WebAssembly (org.graalvm.wasm.api.WebAssembly)1 Test (org.junit.Test)1