summaryrefslogtreecommitdiff
path: root/src/js/post.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/post.js')
-rw-r--r--src/js/post.js26
1 files changed, 19 insertions, 7 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.