index.js
function resume (instance, state) {
  if (instance.__hibernated) {
    instance.__hibernated = false
  } else {
    // initialize memory
    const mem = instance.exports[`${state.symbol}memory`]
    if (mem) {
      (new Uint32Array(mem.buffer)).set(state.memory, 0)
    }

    // initialize table
    if (instance.exports._table) {
      for (const index in state.table) {
        const funcIndex = state.table[index]
        instance.exports._table.set(index, instance.exports[`${state.symbol}func_${funcIndex}`])
      }
    }

    // initialize globals
    for (const index in state.globals) {
      const val = state.globals[index]
      if (val !== undefined) {
        if (Array.isArray(val)) {
          instance.exports[`${state.symbol}global_setter_i64_${index}`](val[1], val[0])
        } else {
          instance.exports[`${state.symbol}global_setter_i32_${index}`](val)
        }
      }
    }
  }
  return instance
}
function resume (instance, state) {
  if (instance.__hibernated) {
    instance.__hibernated = false
  } else {
    // initialize memory
    const mem = instance.exports[`${state.symbol}memory`]
    if (mem) {
      (new Uint32Array(mem.buffer)).set(state.memory, 0)
    }

    // initialize table
    if (instance.exports._table) {
      for (const index in state.table) {
        const funcIndex = state.table[index]
        instance.exports._table.set(index, instance.exports[`${state.symbol}func_${funcIndex}`])
      }
    }

    // initialize globals
    for (const index in state.globals) {
      const val = state.globals[index]
      if (val !== undefined) {
        if (Array.isArray(val)) {
          instance.exports[`${state.symbol}global_setter_i64_${index}`](val[1], val[0])
        } else {
          instance.exports[`${state.symbol}global_setter_i32_${index}`](val)
        }
      }
    }
  }
  return instance
}
function resume ( instance , state ) { if ( instance . __hibernated ) { instance . __hibernated = false } else { // initialize memory const mem = instance . exports [ ` ${ state . symbol } ` ] if ( mem ) { ( new Uint32Array ( mem . buffer ) ) . set ( state . memory , 0 ) } // initialize table if ( instance . exports . _table ) { for ( const index in state . table ) { const funcIndex = state . table [ index ] instance . exports . _table . set ( index , instance . exports [ ` ${ state . symbol } ${ funcIndex } ` ] ) } } // initialize globals for ( const index in state . globals ) { const val = state . globals [ index ] if ( val !== undefined ) { if ( Array . isArray ( val ) ) { instance . exports [ ` ${ state . symbol } ${ index } ` ] ( val [ 1 ] , val [ 0 ] ) } else { instance . exports [ ` ${ state . symbol } ${ index } ` ] ( val ) } } } } return instance }
Resumes a previously hibernated Webassembly instance
@param {WebAssembly.Instance} instance
@param {Object} state - the previous state of the wasm instance
@return {WebAssembly.Instance}
Resumes a previously hibernated Webassembly instance