graaljs
This commit is contained in:
parent
b8269a2871
commit
7a22a32383
@ -37,7 +37,7 @@
|
||||
</Style>
|
||||
</Styles>
|
||||
<Worksheet ss:Name="Engines">
|
||||
<Table ss:ExpandedColumnCount="8" ss:ExpandedRowCount="14" x:FullColumns="1"
|
||||
<Table ss:ExpandedColumnCount="8" ss:ExpandedRowCount="15" x:FullColumns="1"
|
||||
x:FullRows="1" ss:DefaultColumnWidth="65" ss:DefaultRowHeight="16">
|
||||
<Column ss:Index="3" ss:Width="24"/>
|
||||
<Column ss:Width="31"/>
|
||||
@ -181,6 +181,16 @@
|
||||
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
|
||||
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
|
||||
</Row>
|
||||
<Row>
|
||||
<Cell><Data ss:Type="String">GraalJS</Data></Cell>
|
||||
<Cell><Data ss:Type="String">Java</Data></Cell>
|
||||
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
|
||||
<Cell ss:StyleID="s16"/>
|
||||
<Cell ss:StyleID="s16"/>
|
||||
<Cell ss:StyleID="s16"/>
|
||||
<Cell ss:StyleID="s16"/>
|
||||
<Cell ss:StyleID="s16"/>
|
||||
</Row>
|
||||
</Table>
|
||||
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
|
||||
<PageSetup>
|
||||
@ -208,7 +218,7 @@
|
||||
</WorksheetOptions>
|
||||
</Worksheet>
|
||||
<Worksheet ss:Name="Bindings">
|
||||
<Table ss:ExpandedColumnCount="8" ss:ExpandedRowCount="11" x:FullColumns="1"
|
||||
<Table ss:ExpandedColumnCount="8" ss:ExpandedRowCount="12" x:FullColumns="1"
|
||||
x:FullRows="1" ss:DefaultColumnWidth="65" ss:DefaultRowHeight="16">
|
||||
<Column ss:Index="3" ss:Width="24"/>
|
||||
<Column ss:Width="31"/>
|
||||
|
@ -42,7 +42,7 @@ Each browser demo was tested in the following environments:
|
||||
| Browser | TF.js version | Date |
|
||||
|:------------|:--------------|:-----------|
|
||||
| Chrome 119 | `4.14.0` | 2023-12-09 |
|
||||
| Safari 16.6 | `4.14.0` | 2023-12-09 |
|
||||
| Safari 17.4 | `4.14.0` | 2024-03-23 |
|
||||
|
||||
:::
|
||||
|
||||
|
@ -453,7 +453,7 @@ Some lesser-used browsers do not support File System Access API:
|
||||
|
||||
| Browser | Date |
|
||||
|:------------|:-----------|
|
||||
| Safari 17.0 | 2023-11-04 |
|
||||
| Safari 17.4 | 2024-03-23 |
|
||||
| Firefox 119 | 2023-11-04 |
|
||||
|
||||
:::
|
||||
|
@ -44,7 +44,7 @@ This demo was last tested in the following environments:
|
||||
| Browser | Date | `localForage` |
|
||||
|:------------|:-----------|:--------------|
|
||||
| Chrome 122 | 2024-03-21 | 1.10.0 |
|
||||
| Safari 17.0 | 2023-11-30 | 1.10.0 |
|
||||
| Safari 17.4 | 2024-03-23 | 1.10.0 |
|
||||
|
||||
:::
|
||||
|
||||
|
@ -105,23 +105,26 @@ This demo was tested in the following deployments:
|
||||
|
||||
| OpenJDK | Nashorn | Date |
|
||||
|:--------|:----------------|:-----------|
|
||||
| 21.0.1 | 15.4 standalone | 2023-12-01 |
|
||||
| 20.0.2 | 15.4 standalone | 2023-12-01 |
|
||||
| 19.0.2 | 15.4 standalone | 2023-12-01 |
|
||||
| 18.0.2 | 15.4 standalone | 2023-12-01 |
|
||||
| 17.0.9 | 15.4 standalone | 2023-12-01 |
|
||||
| 16.0.1 | 15.4 standalone | 2023-12-01 |
|
||||
| 15.0.10 | 15.4 standalone | 2023-12-01 |
|
||||
| 14.0.2 | Built-in | 2023-12-01 |
|
||||
| 13.0.14 | Built-in | 2023-12-01 |
|
||||
| 12.0.2 | Built-in | 2023-12-01 |
|
||||
| 11.0.20 | Built-in | 2024-02-13 |
|
||||
| 10.0.2 | Built-in | 2023-12-01 |
|
||||
| 9 | Built-in | 2023-12-01 |
|
||||
| 1.8.0 | Built-in | 2023-12-01 |
|
||||
| 22 | 15.4 standalone | 2024-03-23 |
|
||||
| 21.0.2 | 15.4 standalone | 2024-03-23 |
|
||||
| 20.0.2 | 15.4 standalone | 2024-03-23 |
|
||||
| 19.0.2 | 15.4 standalone | 2024-03-23 |
|
||||
| 18.0.2 | 15.4 standalone | 2024-03-23 |
|
||||
| 17.0.10 | 15.4 standalone | 2024-03-23 |
|
||||
| 16.0.1 | 15.4 standalone | 2024-03-23 |
|
||||
| 15.0.10 | 15.4 standalone | 2024-03-23 |
|
||||
| 14.0.2 | Built-in | 2024-03-23 |
|
||||
| 13.0.14 | Built-in | 2024-03-23 |
|
||||
| 12.0.2 | Built-in | 2024-03-23 |
|
||||
| 11.0.20 | Built-in | 2024-03-23 |
|
||||
| 10.0.2 | Built-in | 2024-03-23 |
|
||||
| 9 | Built-in | 2024-03-23 |
|
||||
| 1.8.0 | Built-in | 2024-03-23 |
|
||||
|
||||
:::
|
||||
|
||||
### Compilation
|
||||
|
||||
<Tabs groupId="java">
|
||||
<TabItem value="stdlib" label="Java 8 - 14">
|
||||
|
||||
@ -174,6 +177,8 @@ javac SheetJSNashorn.java
|
||||
This program tries to parse the file specified by the first argument and prints
|
||||
CSV rows from the first worksheet.
|
||||
|
||||
### Standalone Test
|
||||
|
||||
4) Run the command directly:
|
||||
|
||||
<Tabs groupId="java">
|
||||
@ -193,6 +198,9 @@ java -cp .:asm-9.5.jar:asm-tree-9.5.jar:asm-commons-9.5.jar:asm-analysis-9.5.jar
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
If successful, CSV rows from the first worksheet will be displayed.
|
||||
|
||||
### Java Archive Test
|
||||
|
||||
5) Assemble a Java Archive:
|
||||
|
||||
@ -200,9 +208,7 @@ java -cp .:asm-9.5.jar:asm-tree-9.5.jar:asm-commons-9.5.jar:asm-analysis-9.5.jar
|
||||
jar -cf SheetJSNashorn.jar SheetJSNashorn.class xlsx.full.min.js shim.min.js
|
||||
```
|
||||
|
||||
6) Verify the Java Archive.
|
||||
|
||||
Create new directory and copy the archives and test file:
|
||||
6) Create new directory and copy the archives and test file:
|
||||
|
||||
```bash
|
||||
mkdir -p sheethorn
|
||||
@ -210,7 +216,7 @@ cp *.jar pres.xlsx sheethorn
|
||||
cd sheethorn
|
||||
```
|
||||
|
||||
Invoke the command in the archive:
|
||||
7) Run the program using the Java Archive:
|
||||
|
||||
<Tabs groupId="java">
|
||||
<TabItem value="stdlib" label="Java 8 - 14">
|
||||
@ -229,4 +235,4 @@ java -cp .:asm-9.5.jar:asm-tree-9.5.jar:asm-commons-9.5.jar:asm-analysis-9.5.jar
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
This should print the same CSV rows from Step 3.
|
||||
This should print the same CSV rows from Step 4.
|
||||
|
140
docz/docs/03-demos/42-engines/24-graaljs.md
Normal file
140
docz/docs/03-demos/42-engines/24-graaljs.md
Normal file
@ -0,0 +1,140 @@
|
||||
---
|
||||
title: Data Processing with GraalJS
|
||||
sidebar_label: Java + GraalJS
|
||||
pagination_prev: demos/bigdata/index
|
||||
pagination_next: solutions/input
|
||||
---
|
||||
|
||||
import current from '/version.js';
|
||||
import CodeBlock from '@theme/CodeBlock';
|
||||
|
||||
[GraalJS](https://www.graalvm.org/latest/reference-manual/js/) is a JS engine
|
||||
for Java. The project offers a JSR-223 compliant OpenJDK-compatible build.
|
||||
|
||||
[SheetJS](https://sheetjs.com) is a JavaScript library for reading and writing
|
||||
data from spreadsheets.
|
||||
|
||||
The ["Complete Example"](#complete-example) section includes a complete Java
|
||||
command-line tool for reading data from spreadsheets and printing CSV rows.
|
||||
|
||||
:::info pass
|
||||
|
||||
The Java packages used in this demo are covered under open source licenses. The
|
||||
Universal Permissive License covers most of the packages, while `icu4j` uses
|
||||
a different, yet still permissive, license.
|
||||
|
||||
:::
|
||||
|
||||
## Integration Details
|
||||
|
||||
:::info pass
|
||||
|
||||
When this demo was last tested, raw byte arrays could not be passed to GraalJS.
|
||||
|
||||
**This is a limitation of the default GraalJS behavior.**
|
||||
|
||||
Instead, this demo uses Nashorn Compatibility Mode[^1] through a runtime flag:
|
||||
|
||||
```js
|
||||
java -Dpolyglot.js.nashorn-compat=true ...
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
The [Nashorn demo](/docs/demos/engines/nashorn) code and explanation applies to
|
||||
JSR-223 compatible `ScriptEngine` implementations, including GraalJS.
|
||||
|
||||
## Complete Example
|
||||
|
||||
:::note Tested Deployments
|
||||
|
||||
This demo was tested in the following deployments:
|
||||
|
||||
| OpenJDK | GraalJS | Date |
|
||||
|:--------|:--------|:-----------|
|
||||
| 22 | 24.0.0 | 2024-03-23 |
|
||||
| 21.0.2 | 24.0.0 | 2024-03-23 |
|
||||
|
||||
:::
|
||||
|
||||
### Compilation
|
||||
|
||||
0) Download GraalJS and its dependencies:
|
||||
|
||||
```bash
|
||||
curl -LO "https://repo1.maven.org/maven2/org/graalvm/js/js-scriptengine/24.0.0/js-scriptengine-24.0.0.jar"
|
||||
curl -LO "https://repo1.maven.org/maven2/org/graalvm/js/js-language/24.0.0/js-language-24.0.0.jar"
|
||||
curl -LO "https://repo1.maven.org/maven2/org/graalvm/polyglot/polyglot/24.0.0/polyglot-24.0.0.jar"
|
||||
curl -LO "https://repo1.maven.org/maven2/org/graalvm/sdk/collections/24.0.0/collections-24.0.0.jar"
|
||||
curl -LO "https://repo1.maven.org/maven2/org/graalvm/truffle/truffle-api/24.0.0/truffle-api-24.0.0.jar"
|
||||
curl -LO "https://repo1.maven.org/maven2/org/graalvm/sdk/nativeimage/24.0.0/nativeimage-24.0.0.jar"
|
||||
curl -LO "https://repo1.maven.org/maven2/org/graalvm/shadowed/icu4j/24.0.0/icu4j-24.0.0.jar"
|
||||
curl -LO "https://repo1.maven.org/maven2/org/graalvm/regex/regex/24.0.0/regex-24.0.0.jar"
|
||||
```
|
||||
|
||||
1) Download the SheetJS Standalone script, shim script and test file. Move all
|
||||
three files to the project directory:
|
||||
|
||||
<ul>
|
||||
<li><a href={`https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min.js`}>xlsx.full.min.js</a></li>
|
||||
<li><a href={`https://cdn.sheetjs.com/xlsx-${current}/package/dist/shim.min.js`}>shim.min.js</a></li>
|
||||
<li><a href="https://sheetjs.com/pres.xlsx">pres.xlsx</a></li>
|
||||
</ul>
|
||||
|
||||
<CodeBlock language="bash">{`\
|
||||
curl -LO https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min.js
|
||||
curl -LO https://cdn.sheetjs.com/xlsx-${current}/package/dist/shim.min.js
|
||||
curl -LO https://sheetjs.com/pres.xlsx`}
|
||||
</CodeBlock>
|
||||
|
||||
2) Download [`SheetJSNashorn.java`](pathname:///nashorn/SheetJSNashorn.java):
|
||||
|
||||
```bash
|
||||
curl -LO https://docs.sheetjs.com/nashorn/SheetJSNashorn.java
|
||||
```
|
||||
|
||||
3) Build the sample class:
|
||||
|
||||
```bash
|
||||
javac SheetJSNashorn.java
|
||||
```
|
||||
|
||||
This program tries to parse the file specified by the first argument and prints
|
||||
CSV rows from the first worksheet.
|
||||
|
||||
### Standalone Test
|
||||
|
||||
4) Run the command directly:
|
||||
|
||||
```bash
|
||||
java -cp .:js-scriptengine-24.0.0.jar:js-language-24.0.0.jar:polyglot-24.0.0.jar:collections-24.0.0.jar:truffle-api-24.0.0.jar:nativeimage-24.0.0.jar:icu4j-24.0.0.jar:regex-24.0.0.jar -Dpolyglot.js.nashorn-compat=true SheetJSNashorn pres.xlsx
|
||||
```
|
||||
|
||||
If successful, CSV rows from the first worksheet will be displayed.
|
||||
|
||||
### Java Archive Test
|
||||
|
||||
5) Assemble a Java Archive:
|
||||
|
||||
```bash
|
||||
jar -cf SheetJSNashorn.jar SheetJSNashorn.class xlsx.full.min.js shim.min.js
|
||||
```
|
||||
|
||||
6) Create new directory and copy the archives and test file:
|
||||
|
||||
```bash
|
||||
mkdir -p sheethorn
|
||||
cp *.jar pres.xlsx sheethorn
|
||||
cd sheethorn
|
||||
```
|
||||
|
||||
7) Run the program using the Java Archive:
|
||||
|
||||
```bash
|
||||
java -cp .:js-scriptengine-24.0.0.jar:js-language-24.0.0.jar:polyglot-24.0.0.jar:collections-24.0.0.jar:truffle-api-24.0.0.jar:nativeimage-24.0.0.jar:icu4j-24.0.0.jar:regex-24.0.0.jar:SheetJSNashorn.jar -Dpolyglot.js.nashorn-compat=true SheetJSNashorn pres.xlsx
|
||||
```
|
||||
|
||||
|
||||
This should print the same CSV rows from Step 4.
|
||||
|
||||
[^1]: See ["Nashorn Compatibility Mode"](https://www.graalvm.org/latest/reference-manual/js/NashornMigrationGuide/#nashorn-compatibility-mode) in the GraalJS documentation.
|
48
tests/nashorntest.sh
Executable file
48
tests/nashorntest.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd /tmp
|
||||
mkdir -p nashorn
|
||||
cd nashorn
|
||||
|
||||
curl -LO https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js
|
||||
curl -LO https://cdn.sheetjs.com/xlsx-latest/package/dist/shim.min.js
|
||||
curl -LO https://sheetjs.com/pres.xlsx
|
||||
curl -LO https://docs.sheetjs.com/nashorn/SheetJSNashorn.java
|
||||
|
||||
curl -L -o nashorn-core-15.4.jar "https://search.maven.org/remotecontent?filepath=org/openjdk/nashorn/nashorn-core/15.4/nashorn-core-15.4.jar"
|
||||
curl -L -o asm-9.5.jar "https://search.maven.org/remotecontent?filepath=org/ow2/asm/asm/9.5/asm-9.5.jar"
|
||||
curl -L -o asm-tree-9.5.jar "https://search.maven.org/remotecontent?filepath=org/ow2/asm/asm-tree/9.5/asm-tree-9.5.jar"
|
||||
curl -L -o asm-commons-9.5.jar "https://search.maven.org/remotecontent?filepath=org/ow2/asm/asm-commons/9.5/asm-commons-9.5.jar"
|
||||
curl -L -o asm-analysis-9.5.jar "https://search.maven.org/remotecontent?filepath=org/ow2/asm/asm-analysis/9.5/asm-analysis-9.5.jar"
|
||||
curl -L -o asm-util-9.5.jar "https://search.maven.org/remotecontent?filepath=org/ow2/asm/asm-util/9.5/asm-util-9.5.jar"
|
||||
|
||||
# Standalone Nashorn
|
||||
for n in {15..22}; do
|
||||
export JAVA_HOME=`/usr/libexec/java_home -v $n`
|
||||
java -version
|
||||
rm -fr SheetJSNashorn.class SheetJSNashorn.jar sheethorn
|
||||
javac SheetJSNashorn.java
|
||||
java -cp .:asm-9.5.jar:asm-tree-9.5.jar:asm-commons-9.5.jar:asm-analysis-9.5.jar:asm-util-9.5.jar:nashorn-core-15.4.jar SheetJSNashorn pres.xlsx
|
||||
jar -cf SheetJSNashorn.jar SheetJSNashorn.class xlsx.full.min.js shim.min.js
|
||||
mkdir -p sheethorn
|
||||
cp *.jar pres.xlsx sheethorn
|
||||
cd sheethorn
|
||||
java -cp .:asm-9.5.jar:asm-tree-9.5.jar:asm-commons-9.5.jar:asm-analysis-9.5.jar:asm-util-9.5.jar:nashorn-core-15.4.jar:SheetJSNashorn.jar SheetJSNashorn pres.xlsx
|
||||
cd -
|
||||
done
|
||||
|
||||
# Built-in Nashorn
|
||||
for n in 1.8 {9..14}; do
|
||||
export JAVA_HOME=`/usr/libexec/java_home -v $n`
|
||||
java -version
|
||||
rm -fr SheetJSNashorn.class SheetJSNashorn.jar sheethorn
|
||||
javac SheetJSNashorn.java
|
||||
java SheetJSNashorn pres.xlsx
|
||||
jar -cf SheetJSNashorn.jar SheetJSNashorn.class xlsx.full.min.js shim.min.js
|
||||
mkdir -p sheethorn
|
||||
cp *.jar pres.xlsx sheethorn
|
||||
cd sheethorn
|
||||
java -cp .:SheetJSNashorn.jar SheetJSNashorn pres.xlsx
|
||||
cd -
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user