2024-10-02 21:03:04 +02:00
|
|
|
if( typeof emulator != 'undefined' ){
|
|
|
|
// inside worker-thread
|
2024-09-16 13:28:28 +02:00
|
|
|
|
2024-10-02 21:03:04 +02:00
|
|
|
// unix to js device
|
2024-10-15 12:32:16 +02:00
|
|
|
this.emulator.readFromPipe( 'dev/browser/js', async (data) => {
|
|
|
|
const buf = await emulator.read_file("dev/browser/js")
|
2024-10-02 21:03:04 +02:00
|
|
|
const decoder = new TextDecoder('utf-8');
|
|
|
|
const js = decoder.decode(buf).replace(/^#!\/bin\/js/,'') // remove leftover shebangs if any
|
|
|
|
try{
|
|
|
|
this.postMessage({event:'runJavascript',data:[js]})
|
|
|
|
}catch(e){
|
|
|
|
console.error(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-09-16 13:28:28 +02:00
|
|
|
|
2024-10-02 21:03:04 +02:00
|
|
|
}else{
|
|
|
|
// inside browser-thread
|
2024-09-16 13:28:28 +02:00
|
|
|
|
2024-10-02 21:03:04 +02:00
|
|
|
ISOTerminal.prototype.runJavascript = function(js){
|
|
|
|
let $root = document.querySelector("script#root")
|
|
|
|
if( !$root ){
|
|
|
|
$root = document.createElement("script")
|
|
|
|
$root.id = "root"
|
|
|
|
document.body.appendChild($root)
|
|
|
|
}
|
|
|
|
$root.innerHTML = js
|
|
|
|
}
|
2024-09-16 13:28:28 +02:00
|
|
|
|
2024-09-23 16:58:48 +02:00
|
|
|
}
|