Search in sources :

Example 16 with WasmJsApiException

use of org.graalvm.wasm.exception.WasmJsApiException in project graal by oracle.

the class WebAssembly method memSetGrowCallback.

private static Object memSetGrowCallback(Object[] args) {
    InteropLibrary lib = InteropLibrary.getUncached();
    if (!(args[0] instanceof WasmMemory)) {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm memory");
    }
    if (!lib.isExecutable(args[1])) {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "Second argument must be executable");
    }
    WasmMemory memory = (WasmMemory) args[0];
    return memSetGrowCallback(memory, args[1]);
}
Also used : WasmJsApiException(org.graalvm.wasm.exception.WasmJsApiException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) UnsafeWasmMemory(org.graalvm.wasm.memory.UnsafeWasmMemory) WasmMemory(org.graalvm.wasm.memory.WasmMemory) ByteArrayWasmMemory(org.graalvm.wasm.memory.ByteArrayWasmMemory)

Example 17 with WasmJsApiException

use of org.graalvm.wasm.exception.WasmJsApiException in project graal by oracle.

the class WebAssembly method memGrow.

private static Object memGrow(Object[] args) {
    checkArgumentCount(args, 2);
    if (!(args[0] instanceof WasmMemory)) {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm memory");
    }
    if (!(args[1] instanceof Integer)) {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "Second argument must be integer");
    }
    WasmMemory memory = (WasmMemory) args[0];
    int delta = (Integer) args[1];
    return memGrow(memory, delta);
}
Also used : WasmJsApiException(org.graalvm.wasm.exception.WasmJsApiException) UnsafeWasmMemory(org.graalvm.wasm.memory.UnsafeWasmMemory) WasmMemory(org.graalvm.wasm.memory.WasmMemory) ByteArrayWasmMemory(org.graalvm.wasm.memory.ByteArrayWasmMemory)

Example 18 with WasmJsApiException

use of org.graalvm.wasm.exception.WasmJsApiException in project graal by oracle.

the class WebAssembly method instanceExport.

private static Object instanceExport(Object[] args) {
    checkArgumentCount(args, 2);
    if (!(args[0] instanceof WasmInstance)) {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm instance");
    }
    if (!(args[1] instanceof String)) {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "Second argument must be string");
    }
    WasmInstance instance = (WasmInstance) args[0];
    String name = (String) args[1];
    return instanceExport(instance, name);
}
Also used : WasmInstance(org.graalvm.wasm.WasmInstance) WasmJsApiException(org.graalvm.wasm.exception.WasmJsApiException)

Example 19 with WasmJsApiException

use of org.graalvm.wasm.exception.WasmJsApiException in project graal by oracle.

the class WebAssembly method tableRead.

private static Object tableRead(Object[] args) {
    checkArgumentCount(args, 2);
    if (!(args[0] instanceof WasmTable)) {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm table");
    }
    if (!(args[1] instanceof Integer)) {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "Second argument must be integer");
    }
    WasmTable table = (WasmTable) args[0];
    int index = (Integer) args[1];
    return tableRead(table, index);
}
Also used : WasmJsApiException(org.graalvm.wasm.exception.WasmJsApiException) WasmTable(org.graalvm.wasm.WasmTable)

Example 20 with WasmJsApiException

use of org.graalvm.wasm.exception.WasmJsApiException in project graal by oracle.

the class WebAssembly method tableGrow.

private static Object tableGrow(Object[] args) {
    checkArgumentCount(args, 2);
    if (!(args[0] instanceof WasmTable)) {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "First argument must be wasm table");
    }
    if (!(args[1] instanceof Integer)) {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, "Second argument must be integer");
    }
    WasmTable table = (WasmTable) args[0];
    int delta = (Integer) args[1];
    return tableGrow(table, delta);
}
Also used : WasmJsApiException(org.graalvm.wasm.exception.WasmJsApiException) WasmTable(org.graalvm.wasm.WasmTable)

Aggregations

WasmJsApiException (org.graalvm.wasm.exception.WasmJsApiException)20 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)6 WasmTable (org.graalvm.wasm.WasmTable)6 Test (org.junit.Test)6 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)4 WasmInstance (org.graalvm.wasm.WasmInstance)4 ExportedWasmGlobal (org.graalvm.wasm.globals.ExportedWasmGlobal)4 WasmMemory (org.graalvm.wasm.memory.WasmMemory)4 ArityException (com.oracle.truffle.api.interop.ArityException)3 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)3 WebAssembly (org.graalvm.wasm.api.WebAssembly)3 DefaultWasmGlobal (org.graalvm.wasm.globals.DefaultWasmGlobal)3 WasmGlobal (org.graalvm.wasm.globals.WasmGlobal)3 ByteArrayWasmMemory (org.graalvm.wasm.memory.ByteArrayWasmMemory)3 UnsafeWasmMemory (org.graalvm.wasm.memory.UnsafeWasmMemory)3 WasmFunction (org.graalvm.wasm.WasmFunction)2 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)1