Skip to content

Commit

Permalink
handle WebAssembly.Instance and Module
Browse files Browse the repository at this point in the history
  • Loading branch information
doehyunbaek committed Dec 6, 2023
1 parent e45cdaa commit 256b711
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function setup() {
initSync(buffer)
let original_instantiate = WebAssembly.instantiate
WebAssembly.instantiate = function (buffer, importObject) {
buffer = (buffer.byte) ? buffer.byte : buffer
// self.performanceList.push(p_timeToFirstInstantiate.stop())
const this_i = i
i += 1
Expand Down Expand Up @@ -85,5 +86,31 @@ function setup() {
let body = await response.arrayBuffer();
return WebAssembly.instantiate(body, obj);
}
const original_module = WebAssembly.Module
WebAssembly.Module = function (byte) {
console.log('WebAssembly.Module')
const module = new original_module(byte)
module.byte = byte
return module
}
const original_instance = WebAssembly.Instance
WebAssembly.Instance = function (module, importObject) {
console.log('WebAssembly.Instance')
let buffer = module.byte
const this_i = i
i += 1
printWelcome()
self.originalWasmBuffer.push(Array.from(new Uint8Array(buffer)))
const { instrumented, js } = instrument_wasm(new Uint8Array(buffer));
wasabis.push(eval(js + '\nWasabi'))
buffer = new Uint8Array(instrumented)
importObject = importObjectWithHooks(importObject, this_i)
self.analysis.push(setupAnalysis(wasabis[this_i]))
let result
module = new WebAssembly.Module(buffer)
const instance = new original_instance(module, importObject)
result = wireInstanceExports(instance, this_i)
return instance
}
}
setup()
2 changes: 1 addition & 1 deletion wasabi

0 comments on commit 256b711

Please sign in to comment.