benchmarks/wasm/src/index.js
function loadWebAssembly(filename, imports) {
  // Fetch the file and compile it
  return fetch(filename)
    .then(response => response.arrayBuffer())
    .then(buffer => WebAssembly.compile(buffer))
    .then(module => {
      // create the imports for the module, including the
      // standard dynamic library imports
      imports = imports || {};
      imports.env = imports.env || {};
      imports.env.memoryBase = imports.env.memoryBase || 0;
      imports.env.tableBase = imports.env.tableBase || 0;

      // note: just take really memory for now...
      if (!imports.env.memory)
        imports.env.memory = new WebAssembly.Memory({ initial: 256 });

      if (!imports.env.table)
        imports.env.table = new WebAssembly.Table({ initial: 0, element: 'anyfunc' });

      // create the instance
      const instance = new WebAssembly.Instance(module, imports);
      return Promise.resolve({ instance, imports });
    });
}
function loadWebAssembly(filename, imports) {
  // Fetch the file and compile it
  return fetch(filename)
    .then(response => response.arrayBuffer())
    .then(buffer => WebAssembly.compile(buffer))
    .then(module => {
      // create the imports for the module, including the
      // standard dynamic library imports
      imports = imports || {};
      imports.env = imports.env || {};
      imports.env.memoryBase = imports.env.memoryBase || 0;
      imports.env.tableBase = imports.env.tableBase || 0;

      // note: just take really memory for now...
      if (!imports.env.memory)
        imports.env.memory = new WebAssembly.Memory({ initial: 256 });

      if (!imports.env.table)
        imports.env.table = new WebAssembly.Table({ initial: 0, element: 'anyfunc' });

      // create the instance
      const instance = new WebAssembly.Instance(module, imports);
      return Promise.resolve({ instance, imports });
    });
}
function loadWebAssembly ( filename , imports ) { // Fetch the file and compile it return fetch ( filename ) . then ( response => response . arrayBuffer ( ) ) . then ( buffer => WebAssembly . compile ( buffer ) ) . then ( module => { // create the imports for the module, including the // standard dynamic library imports imports = imports || { } ; imports . env = imports . env || { } ; imports . env . memoryBase = imports . env . memoryBase || 0 ; imports . env . tableBase = imports . env . tableBase || 0 ; // note: just take really memory for now... if ( ! imports . env . memory ) imports . env . memory = new WebAssembly . Memory ( { initial : 256 } ) ; if ( ! imports . env . table ) imports . env . table = new WebAssembly . Table ( { initial : 0 , element : 'anyfunc' } ) ; // create the instance const instance = new WebAssembly . Instance ( module , imports ) ; return Promise . resolve ( { instance , imports } ) ; } ) ; }
loads a WebAssembly dynamic library, returns a promise. imports is an optional imports object
loads a WebAssembly dynamic library returns a promise . imports is an optional imports object