diff --git a/buildroot-v86/board/v86/rootfs_overlay/bin/js b/buildroot-v86/board/v86/rootfs_overlay/bin/js index 3a41ff9..f66d252 100755 --- a/buildroot-v86/board/v86/rootfs_overlay/bin/js +++ b/buildroot-v86/board/v86/rootfs_overlay/bin/js @@ -19,13 +19,20 @@ test -f "$1" && { OUTPUT=/mnt/run/$PID # com/isoterminal/feat/javascript.js writes output here -touch $OUTPUT echo -n "PID=$PID; $javascript" > /dev/browser/js -# todo watch file -sleep 0.1 -cat $OUTPUT -rm $OUTPUT +# check for file output +check_ready(){ + test -f $OUTPUT && { + cat $OUTPUT | grep -vE '^undefined$'; + code="$(cat ${OUTPUT}.exit)" + rm $OUTPUT; + exit $code; + } +} + +check_ready +while sleep 0.3; do check_ready; done # should we use flock, an awesome way to make processes read/write the same file # while preventing 1001 concurrency issues? diff --git a/buildroot-v86/board/v86/rootfs_overlay/root/manual.md b/buildroot-v86/board/v86/rootfs_overlay/root/manual.md index 46341ef..df9d185 100644 --- a/buildroot-v86/board/v86/rootfs_overlay/root/manual.md +++ b/buildroot-v86/board/v86/rootfs_overlay/root/manual.md @@ -251,3 +251,16 @@ Various options: 3. Run `jsh alert hello` in the shell 4. Run `jsh` to start an interactive shell +This allow writing (a)synchronous cli-scripts which execute in the browser: + +``` +#!/bin/js +return "hello" +``` + +``` +#!/bin/js +return new Promise( (resolve,reject) => resolve("hello") ) +``` + +NOTE: For convenience the javascript-code is passed to browser-context (via the webworker). In the future a package like [quickjs](https://bellard.org/quickjs/) will isolate things further. diff --git a/dist/v86-linux.iso b/dist/v86-linux.iso index 5dd6c7b..d2dd643 100644 Binary files a/dist/v86-linux.iso and b/dist/v86-linux.iso differ