use of org.graalvm.wasm.exception.WasmJsApiException in project graal by oracle.
the class WasmJsApiSuite method testMemoryGrowLimit.
@Test
public void testMemoryGrowLimit() throws IOException {
runTest(context -> {
try {
WasmMemory memory = WebAssembly.memAlloc(1, 1);
WebAssembly.memGrow(memory, 1);
Assert.fail("Should have failed - try to grow memory beyond max size");
} catch (WasmJsApiException e) {
Assert.assertEquals("Range error expected", WasmJsApiException.Kind.RangeError, e.kind());
}
});
}
use of org.graalvm.wasm.exception.WasmJsApiException in project graal by oracle.
the class WasmJsApiSuite method testInvalidEmbedderData.
@Test
public void testInvalidEmbedderData() throws IOException {
runTest(context -> {
Object notEmbedderDataHolder = new Object();
try {
WebAssembly.embedderDataGet(new Object[] { notEmbedderDataHolder });
Assert.fail("embedderDataGet failed to throw");
} catch (WasmJsApiException ex) {
Assert.assertEquals("Type error expected", WasmJsApiException.Kind.TypeError, ex.kind());
}
try {
WebAssembly.embedderDataSet(new Object[] { notEmbedderDataHolder, 42 });
Assert.fail("embedderDataSet failed to throw");
} catch (WasmJsApiException ex) {
Assert.assertEquals("Type error expected", WasmJsApiException.Kind.TypeError, ex.kind());
}
});
}
use of org.graalvm.wasm.exception.WasmJsApiException in project graal by oracle.
the class WasmJsApiSuite method testTableInstanceGrowLimit.
@Test
public void testTableInstanceGrowLimit() throws IOException {
runTest(context -> {
final WebAssembly wasm = new WebAssembly(context);
final WasmInstance instance = moduleInstantiate(wasm, binaryWithMixedExports, null);
final InteropLibrary lib = InteropLibrary.getUncached();
// We should be able to grow the table to 10,000,000.
try {
final Object table = WebAssembly.instanceExport(instance, "t");
final Object grow = wasm.readMember("table_grow");
lib.execute(grow, table, 9999999);
} catch (UnsupportedMessageException | UnknownIdentifierException | UnsupportedTypeException | ArityException e) {
throw new RuntimeException(e);
}
// But growing to 10,000,001 should fail.
try {
final Object table = WebAssembly.instanceExport(instance, "t");
final Object grow = wasm.readMember("table_grow");
lib.execute(grow, table, 1);
Assert.fail("Should have failed - export count exceeds the limit");
} catch (UnsupportedMessageException | UnknownIdentifierException | UnsupportedTypeException | ArityException e) {
throw new RuntimeException(e);
} catch (WasmJsApiException e) {
Assert.assertEquals("Range error expected", WasmJsApiException.Kind.RangeError, e.kind());
}
});
}
use of org.graalvm.wasm.exception.WasmJsApiException in project graal by oracle.
the class WasmJsApiSuite method testTableInstanceOutOfBoundsGet.
@Test
public void testTableInstanceOutOfBoundsGet() throws IOException {
runTest(context -> {
final WebAssembly wasm = new WebAssembly(context);
final WasmInstance instance = moduleInstantiate(wasm, binaryWithMixedExports, null);
final InteropLibrary lib = InteropLibrary.getUncached();
// We should be able to get element 1.
try {
final Object table = WebAssembly.instanceExport(instance, "t");
final Object readTable = wasm.readMember("table_read");
lib.execute(readTable, table, 0);
} catch (UnsupportedMessageException | UnknownIdentifierException | UnsupportedTypeException | ArityException e) {
throw new RuntimeException(e);
}
// But not element 2.
try {
final Object table = WebAssembly.instanceExport(instance, "t");
final Object readTable = wasm.readMember("table_read");
lib.execute(readTable, table, 1);
Assert.fail("Should have failed - export count exceeds the limit");
} catch (UnsupportedMessageException | UnknownIdentifierException | UnsupportedTypeException | ArityException e) {
throw new RuntimeException(e);
} catch (WasmJsApiException e) {
Assert.assertEquals("Range error expected", WasmJsApiException.Kind.RangeError, e.kind());
}
});
}
use of org.graalvm.wasm.exception.WasmJsApiException 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());
}
});
}
Aggregations