summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-10-31 16:09:10 -0700
committerAlon Zakai <alonzakai@gmail.com>2015-10-31 16:09:10 -0700
commitd726a11c7ee90b0bd2dfd3be1774fe3367da0432 (patch)
tree329637e3dbcd0a7b9b7997359af7957838f670f2 /src
parenta8963f481e5db2c212a7e7fa83d3599c65d7ef5f (diff)
downloadbinaryen-d726a11c7ee90b0bd2dfd3be1774fe3367da0432.tar.gz
binaryen-d726a11c7ee90b0bd2dfd3be1774fe3367da0432.tar.bz2
binaryen-d726a11c7ee90b0bd2dfd3be1774fe3367da0432.zip
polyfill fixes
Diffstat (limited to 'src')
-rw-r--r--src/js/post.js26
-rw-r--r--src/wasm-js.cpp4
2 files changed, 21 insertions, 9 deletions
diff --git a/src/js/post.js b/src/js/post.js
index 571fca101..2ee7b20b1 100644
--- a/src/js/post.js
+++ b/src/js/post.js
@@ -1,19 +1,31 @@
(function() {
- // XXX don't be confused. Module here is in the outside program. WasmJS is the inner wasm-js.cpp.
+ var wasmJS = WasmJS({}); // do not use the normal Module in the current scope
+
+ // XXX don't be confused. Module here is in the outside program. wasmJS is the inner wasm-js.cpp.
// Generate a module instance of the asm.js converted into wasm.
- var code = read(Module['asmjsCodeFile']);
- var temp = WasmJS._malloc(code.length + 1);
- WasmJS.writeAsciiToMemory(code, temp);
- var instance = WasmJS.load_asm(temp);
- WasmJS._free(temp);
+ var code;
+ if (typeof read === 'function') {
+ // spidermonkey or v8 shells
+ code = read(Module['asmjsCodeFile']);
+ } else if (typeof process === 'object' && typeof require === 'function') {
+ // node.js
+ code = require('fs')['readFileSync'](Module['asmjsCodeFile']).toString();
+ } else {
+ throw 'TODO: loading in other platforms';
+ }
+
+ var temp = wasmJS._malloc(code.length + 1);
+ wasmJS.writeAsciiToMemory(code, temp);
+ var instance = wasmJS._load_asm(temp);
+ wasmJS._free(temp);
// Generate memory XXX TODO get the right size
var theBuffer = Module['buffer'] = new ArrayBuffer(16*1024*1024);
// Information for the instance of the module.
- var instance = WasmJS['instance'] = {
+ var instance = wasmJS['instance'] = {
global: null,
env: null,
parent: Module // Module inside wasm-js.cpp refers to wasm-js.cpp; this allows access to the outside program.
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp
index 8305cb4a9..0fc844946 100644
--- a/src/wasm-js.cpp
+++ b/src/wasm-js.cpp
@@ -61,9 +61,9 @@ extern "C" ModuleInstance* EMSCRIPTEN_KEEPALIVE load_asm(char *input) {
});
for (auto& argument : arguments) {
if (argument.type == i32) {
- EM_ASM({ Module['tempArguments'].push($0) }, argument.geti32());
+ EM_ASM_({ Module['tempArguments'].push($0) }, argument.geti32());
} else if (argument.type == f64) {
- EM_ASM({ Module['tempArguments'].push($0) }, argument.getf64());
+ EM_ASM_({ Module['tempArguments'].push($0) }, argument.getf64());
} else {
abort();
}