-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ Cargo.lock | |
/hash.txt | ||
node_modules | ||
yarn.lock | ||
/web/dist | ||
web.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Play with QuickJS</title> | ||
</head> | ||
|
||
<body> | ||
<div class="result" id="result"> | ||
<textarea id="input-code" style="width: 500px; height: 200px;"> | ||
async function main() { | ||
const url = "https://httpbin.org/get"; | ||
console.log("Getting: ", url); | ||
const response = await fetch(url); | ||
console.log("Response: ", response.status); | ||
const body = await response.text(); | ||
Sidevm.inspect("Body: ", body); | ||
return body; | ||
} | ||
main() | ||
.then(result => scriptOutput = result) | ||
.catch(err => scriptOutput = err) | ||
.finally(() => Sidevm.exit()); | ||
</textarea> | ||
<br> | ||
<button id="btn-run" disabled="true">Run</button> | ||
<p>Output: <span id="output"></span></p> | ||
</div> | ||
</body> | ||
|
||
</html> | ||
<script type="module" src="main.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import init, { run } from "./dist/phatjs.js"; | ||
|
||
// Provide custom fetch implementation for phatjs | ||
window.phatjsFetch = (resource, options) => { | ||
console.log("Fetch: ", resource, options); | ||
return fetch(resource, options); | ||
} | ||
|
||
async function runScript() { | ||
const script = document.getElementById("input-code").value; | ||
document.getElementById("btn-run").disabled = true; | ||
const args = ["42"]; | ||
try { | ||
const output = await run(["phatjs", "-c", script, "--", ...args]); | ||
document.getElementById("output").innerText = output; | ||
} finally { | ||
document.getElementById("btn-run").disabled = false; | ||
} | ||
} | ||
|
||
async function main() { | ||
await init(); | ||
document.getElementById("btn-run").onclick = runScript; | ||
document.getElementById("btn-run").disabled = false; | ||
} | ||
|
||
main().catch(console.error) |