Skip to content

Commit 715f6b6

Browse files
committed
Add a test for CI
1 parent 5709ff3 commit 715f6b6

6 files changed

Lines changed: 22 additions & 19 deletions

File tree

.github/workflows/web-image-export-function-demo.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: web-image-export-java-function
22
on:
33
push:
44
paths:
5-
- 'native-image/web-image/export-java-function/**'
5+
- 'web-image/export-java-function/**'
66
- '.github/workflows/web-image-export-function-demo.yml'
77
pull_request:
88
paths:
9-
- 'native-image/web-image/export-java-function/**'
9+
- 'web-image/export-java-function/**'
1010
- '.github/workflows/web-image-export-java-function.yml'
1111
schedule:
1212
- cron: "0 0 1 * *" # run every month
@@ -36,11 +36,7 @@ jobs:
3636
echo "$(pwd)/binaryen-version_122/bin" >> "$GITHUB_PATH"
3737
- name: Run 'native-image/wasm-javac'
3838
run: |
39-
cd native-image/web-image/export-java-function
39+
cd web-image/export-java-function
4040
javac Adder.java
4141
native-image --tool:svm-wasm -H:-AutoRunVM Adder
42-
jwebserver -p 8000 &
43-
SERVER_PID=$!
44-
sleep 5
45-
curl -i http://127.0.0.1:8000
46-
kill $SERVER_PID
42+
node --experimental-wasm-exnref log.js

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ micronaut-webapp/docker-compose.yml
238238
/hello-graal/Hello
239239
/hello-graal/Hello.build_artifacts.txt
240240
/native-heapdump-examples/helloworld
241-
native-list-dir/listdir
242-
native-list-dir/listdir.build_artifacts.txt
243241
shared
244242
micronaut-hello-rest-gradle/hello/
245243
micronaut-webapp/loadTests/results-*
@@ -262,7 +260,6 @@ fastR-examples/*.*
262260
venv/
263261
espresso-jshell/espresso-jshell
264262
espresso-jshell/espresso-jshell.build_artifacts.txt
265-
native-list-dir/extlistdir
266-
native-list-dir/extlistdir.build_artifacts.txt
267263
*.pyc
268264
*.iprof
265+
web-image/export-java-function/*.js
File renamed without changes.

native-image/web-image/export-java-function/README.md renamed to web-image/export-java-function/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Web Image: Export Java Method Example
22

3-
This demo illustrates the use of **Web Image** - an experimental backend for [GraalVM Native Image](https://www.graalvm.org/latest/reference-manual/native-image/) that compiles a Java application ahead-of-time and produces a WebAssembly (WASM) module with a JavaScript wrapper.
3+
This demo illustrates the use of **Web Image** - an experimental backend for [GraalVM Native Image](https://www.graalvm.org/latest/reference-manual/native-image/) that compiles a Java application ahead-of-time and produces a WebAssembly (Wasm) module with a JavaScript wrapper.
44
Then it can be run in browsers or with Node.js.
55

66
The key idea is to show how you can currently **call Java methods directly from JavaScript** without relying on the `main()` method.
7-
This demo exposes a simple Java `add(int a, int b)` method to the global JavaScript scope using the `@JS` annotation from the [Annotation Interface](https://www.graalvm.org/sdk/javadoc/org/graalvm/webimage/api/JS.html).
7+
This demo exposes a simple Java method to the global JavaScript scope using the `@JS` annotation from the [Annotation Interface](https://www.graalvm.org/sdk/javadoc/org/graalvm/webimage/api/JS.html).
88

99
> Note: Web Image is an experimental technology and under active development. APIs, tooling, and capabilities may change.
1010
@@ -70,7 +70,7 @@ public class Adder {
7070
```
7171

7272
- `@JS` annotation is part of [GraalVM Web Image API](https://www.graalvm.org/sdk/javadoc/org/graalvm/webimage/api/JS.html). It allows you to bridge Java and JavaScript.
73-
- `args = {"adder"}` tells GraalVM that the BiFunction you pass in Java will be available as a JavaScript variable `adder`.
73+
- `args = {"adder"}` tells GraalVM that the BiFunction you pass in Java will be available as a JavaScript variable `adder` (not necessary if the Java source code is compiled with the `-parameters` option).
7474
- `value = "globalThis.adder = adder;"` is a raw JavaScript code executed when the export happens; it sets a variable called `adder` to be globally accessible in browsers.
7575

7676
Further down you see the `export` method:
@@ -87,7 +87,7 @@ This makes the lambda directly callable from JS as `globalThis.adder(...)`.
8787
The next part is calling from JavaScript in HTML, which happens in this part of _index.html_:
8888
```js
8989
<script>
90-
GraalVM.run([], {}).then(() => {
90+
GraalVM.run([]).then(() => {
9191
...
9292
addButton.addEventListener("click", () => {
9393
const a = parseInt(document.getElementById("num1").value);
@@ -103,10 +103,10 @@ GraalVM.run([], {}).then(() => {
103103
</script>
104104
```
105105

106-
- `GraalVM.run([], {})` initializes the WASM module and the Java runtime inside the browser.
106+
- `GraalVM.run([], {})` initializes the Wasm module and the Java runtime inside the browser.
107107
- `globalThis.adder(a, b)` calls the `add` function you exported via WebAssembly.
108108

109109
### Conclusion
110110

111111
The focus of this demo is to demonstrate direct interaction between Java and JavaScript in the browser via WebAssembly.
112-
Note that the [GraalVM Web Image API](https://www.graalvm.org/sdk/javadoc/org/graalvm/webimage/api/JS.html) is still under active development.
112+
Note that the [GraalVM Web Image API](https://www.graalvm.org/sdk/javadoc/org/graalvm/webimage/api/JS.html) is still under active development, there will be better ways to export Java methods to JavaScript.

native-image/web-image/export-java-function/index.html renamed to web-image/export-java-function/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h2>GraalVM Web Image</h2>
1616

1717
<script src="adder.js"></script>
1818
<script>
19-
GraalVM.run([], {}).then(() => {
19+
GraalVM.run([]).then(() => {
2020
const addButton = document.getElementById("addButton");
2121
const clearButton = document.getElementById("clearButton");
2222
const output = document.getElementById("output");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require("./adder.js");
2+
3+
GraalVM.run([]).then(() => {
4+
const a = 3;
5+
const b = 4;
6+
7+
const result = globalThis.adder(a, b);
8+
console.log(`Result: ${result}`);
9+
10+
});

0 commit comments

Comments
 (0)