
function integrateWasmJS(Module) {
  if (typeof WASM === 'object') {
    // Provide an "asm.js function" for the application, called to "link" the asm.js module. We instantiate
    // the wasm module at that time, and it receives imports and provides exports and so forth, the app
    // doesn't need to care that it is wasm and not asm.
    Module['asm'] = function(global, env, providedBuffer) {
      // Load the binary wasm module
      var filename = Module['wasmCodeFile'];
      var binary;
      if (typeof read === 'function') {
        // spidermonkey or v8 shells
        if (typeof readbuffer === 'function') {
          binary = new Uint8Array(readbuffer(filename));
        } else {
          binary = read(f, 'binary');
        }
      } else if (typeof process === 'object' && typeof require === 'function') {
        // node.js
        binary = require('fs')['readFileSync'](filename);
        if (!binary.buffer) { // handle older node.js not returning a proper typed array
          binary = new Uint8Array(ret);
        }
      } else {
        throw 'TODO: binary loading in other platforms';
      }
      assert(binary.buffer);
      // Create an instance of the module using native support in the JS engine.
      var instance = WASM.instantiateModule(binary, {
        "global.Math": global.Math,
        "env": env
      });
      // The wasm instance creates its memory. But static init code might have written to
      // buffer already, and we must copy it over.
      // TODO: avoid this copy, by avoiding such static init writes
      // TODO: in shorter term, just copy up to the last static init write
      var oldBuffer = Module['buffer'];
      var newBuffer = instance.memory;
      assert(newBuffer.byteLength >= oldBuffer.byteLength, 'we might fail if we allocated more than TOTAL_MEMORY');
      (new Int8Array(newBuffer)).set(new Int8Array(oldBuffer));
      updateGlobalBuffer(newBuffer);
      updateGlobalBufferViews();
      Module['reallocBuffer'] = function(size) {
        abort('no memory growth quite yet, but easy to add');
      };
      return instance;
    };
    return;
  }

  // Use wasm.js to polyfill and execute code in a wasm interpreter.
  var wasmJS = WasmJS({});

  // XXX don't be confused. Module here is in the outside program. wasmJS is the inner wasm-js.cpp.
  wasmJS['outside'] = Module; // Inside wasm-js.cpp, Module['outside'] reaches the outside module.

  // Information for the instance of the module.
  var info = wasmJS['info'] = {
    global: null,
    env: null,
    asm2wasm: { // special asm2wasm imports
      "f64-rem": function(x, y) {
        return x % y;
      },
      "f64-to-int": function(x) {
        return x | 0;
      },
      "debugger": function() {
        debugger;
      },
    },
    parent: Module // Module inside wasm-js.cpp refers to wasm-js.cpp; this allows access to the outside program.
  };

  wasmJS['lookupImport'] = function(mod, base) {
    var lookup = info;
    if (mod.indexOf('.') < 0) {
      lookup = (lookup || {})[mod];
    } else {
      var parts = mod.split('.');
      lookup = (lookup || {})[parts[0]];
      lookup = (lookup || {})[parts[1]];
    }
    lookup = (lookup || {})[base];
    if (lookup === undefined) {
      abort('bad lookupImport to (' + mod + ').' + base);
    }
    return lookup;
  }

  // The asm.js function, called to "link" the asm.js module. At that time, we are provided imports
  // and respond with exports, and so forth.
  Module['asm'] = function(global, env, providedBuffer) {
    assert(providedBuffer === Module['buffer']); // we should not even need to pass it as a 3rd arg for wasm, but that's the asm.js way.

    // Generate a module instance of the asm.js converted into wasm.
    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';
    }

    // wasm code would create its own buffer, at this time. But static init code might have
    // written to the buffer already, and we must copy it over. We could just avoid
    // this copy in wasm.js polyfilling, but to be as close as possible to real wasm,
    // we do what wasm would do.
    // TODO: avoid this copy, by avoiding such static init writes
    // TODO: in shorter term, just copy up to the last static init write
    var oldBuffer = Module['buffer'];
    var newBuffer = ArrayBuffer(oldBuffer.byteLength);
    (new Int8Array(newBuffer)).set(new Int8Array(oldBuffer));
    updateGlobalBuffer(newBuffer);
    updateGlobalBufferViews();
    wasmJS['providedTotalMemory'] = Module['buffer'].byteLength;

    Module['reallocBuffer'] = function(size) {
      var old = Module['buffer'];
      wasmJS['asmExports']['__growWasmMemory'](size); // tiny wasm method that just does grow_memory
      return Module['buffer'] !== old ? Module['buffer'] : null; // if it was reallocated, it changed
    };

    var temp = wasmJS['_malloc'](code.length + 1);
    wasmJS['writeAsciiToMemory'](code, temp);
    wasmJS['_load_asm'](temp);
    wasmJS['_free'](temp);

    // write the provided data to a location the wasm instance can get at it.
    info.global = global;
    info.env = env;
    wasmJS['_load_mapped_globals'](); // now that we have global and env, we can ready the provided imported globals, copying them to their mapped locations.
    return wasmJS['asmExports'];
  };
}


@@ -410,23 +410,16 @@
 oad the 
-binary 
 wasm mod
@@ -432,24 +432,22 @@
     var 
-filename
+binary
  = Modul
@@ -453,694 +453,46 @@
 le%5B'
-wasmCodeFile'%5D;%0A      var binary;%0A      if (typeof read === 'function') %7B%0A        // spidermonkey or v8 shells%0A        if (typeof readbuffer === 'function') %7B%0A          binary = new Uint8Array(readbuffer(filename));%0A        %7D else %7B%0A          binary = read(f, 'binary');%0A        %7D%0A      %7D else if (typeof process === 'object' && typeof require === 'function') %7B%0A        // node.js%0A        binary = require('fs')%5B'readFileSync'%5D(filename);%0A        if (!binary.buffer) %7B // handle older node.js not returning a proper typed array%0A          binary = new Uint8Array(ret);%0A        %7D%0A      %7D else %7B%0A        throw 'TODO: binary loading in other platforms';%0A      %7D%0A      assert(binary.buffer);
+readBinary'%5D(Module%5B'wasmCodeFile'%5D);%0A
 %0A   
@@ -688,16 +688,17 @@
     %7D);%0A
+%0A
       //
@@ -1418,24 +1418,25 @@
 );%0A      %7D;%0A
+%0A
       return
@@ -3096,369 +3096,51 @@
 code
-;%0A    if (typeof read === 'function') %7B%0A      // spidermonkey or v8 shells%0A      code = read(Module%5B'asmjsCodeFile'%5D);%0A    %7D else if (typeof process === 'object' && typeof require === 'function') %7B%0A      // node.js%0A      code = require('fs')%5B'readFileSync'%5D(Module%5B'asmjsCodeFile'%5D).toString();%0A    %7D else %7B%0A      throw 'TODO: loading in other platforms';%0A    %7D
+ = Module%5B'read'%5D(Module%5B'asmjsCodeFile'%5D);
 %0A%0A  

simplify wasm.js loading code, since we are now embedded where we can use the outside module's