Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
408 changes: 408 additions & 0 deletions crates/wasi-common/js-polyfill/Cargo.lock

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions crates/wasi-common/js-polyfill/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "polyfill"
version = "0.1.0"
authors = ["The Wasmtime Project Developers"]
edition = "2018"

[dependencies]
wasi-common = { path = ".." }

# This crate is built with the wasm32-unknown-emscripten target, so it's separate
# from the main Wasmtime build, so use this directive to exclude it
# from the parent directory's workspace.
[workspace]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions crates/wasi-common/js-polyfill/assets/load-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
mergeInto(LibraryManager.library, {
loadFiles: function() {
const imports = { wasi_snapshot_preview1: WASIPolyfill };
let file = document.getElementById("input").files[0];
let file_with_mime_type = file.slice(0, file.size, "application/wasm");
let response = new Response(file_with_mime_type);
wasi_instantiateStreaming(response, imports)
.then(obj => {
setInstance(obj.instance);
try {
obj.instance.exports._start();
} catch (e) {
if (e instanceof WASIExit) {
handleWASIExit(e);
} else {
}
}
})
.catch(error => {
console.log("error! " + error);
});
}
});
88 changes: 88 additions & 0 deletions crates/wasi-common/js-polyfill/assets/shell.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!doctype html>
<!-- This file is derived from src/shell_minimal.html in Emscripten. -->
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WASI Web Polyfill</title>
<style>
.wasi { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
textarea.wasi { font-family: monospace; width: 80%; }
div.wasi { text-align: center; }
div.wasi_border { border: 1px solid black; }
</style>
</head>
<body>
<figure style="overflow:visible;" id="spinner"><div class="spinner"></div><center style="margin-top:0.5em"><strong>WASI</strong></center></figure>
<div class="wasi" id="status">Downloading...</div>
<div class="wasi">
<progress value="0" max="100" id="progress" hidden=1></progress>
</div>
<img class="wasi" src="WASI-small.png" width="200" height="200" border="0" alt="WASI logo">
<input class="wasi" type="file" id="input" onchange="_handleFiles(this.files)">
<hr>
<textarea class="wasi" id="output" rows="8"></textarea>
<script type='text/javascript'>
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
var spinnerElement = document.getElementById('spinner');

var Module = {
preRun: [],
postRun: [],
print: (function() {
var element = document.getElementById('output');
if (element) element.value = ''; // clear browser cache
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
if (element) {
element.value += text + "\n";
element.scrollTop = element.scrollHeight; // focus on bottom
}
};
})(),
printErr: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
},
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.last.text) return;
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
var now = Date.now();
if (m && now - Module.setStatus.last.time < 30) return; // if this is a progress update, skip it if too soon
Module.setStatus.last.time = now;
Module.setStatus.last.text = text;
if (m) {
text = m[1];
progressElement.value = parseInt(m[2])*100;
progressElement.max = parseInt(m[4])*100;
progressElement.hidden = false;
spinnerElement.hidden = false;
} else {
progressElement.value = null;
progressElement.max = null;
progressElement.hidden = true;
if (!text) spinnerElement.hidden = true;
}
statusElement.innerHTML = text;
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
}
};
Module.setStatus('Downloading...');
window.onerror = function() {
Module.setStatus('Exception thrown, see JavaScript console');
spinnerElement.style.display = 'none';
Module.setStatus = function(text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
};
</script>
{{{ SCRIPT }}}
</body>
</html>
Loading