From 9462fbd32d7c53d19008ce5f1de7216da36950e1 Mon Sep 17 00:00:00 2001 From: Doehyun Baek Date: Fri, 16 Feb 2024 09:37:23 +0900 Subject: [PATCH] fix bug of download binary when instrumentation fails --- src/runtime.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/runtime.js b/src/runtime.js index d0880422..2444938d 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -65,6 +65,20 @@ function setup() { // const p_instrumenting = performanceEvent(`instrumentation of wasm binary ${this_i}`) try { const { instrumented, js } = instrument_wasm(new Uint8Array(buffer)); + // self.performanceList.push(p_instrumenting.stop()) + wasabis.push(eval(js + '\nWasabi')) + buffer = new Uint8Array(instrumented) + importObject = importObjectWithHooks(importObject, this_i) + self.analysis.push(setupAnalysis(wasabis[this_i])) + let result + result = original_instantiate(buffer, importObject) + result.then(({ module, instance }) => { + wireInstanceExports(instance, this_i) + self.analysis[this_i].init() + + }) + // self.performanceList.push(p_instantiationTime.stop()) + return result } catch (e) { console.error('Instrumentation failed. Downloading the original data') let blob = new Blob([buffer.bytes]); @@ -78,20 +92,6 @@ function setup() { window.URL.revokeObjectURL(url); document.body.removeChild(a); } - // self.performanceList.push(p_instrumenting.stop()) - wasabis.push(eval(js + '\nWasabi')) - buffer = new Uint8Array(instrumented) - importObject = importObjectWithHooks(importObject, this_i) - self.analysis.push(setupAnalysis(wasabis[this_i])) - let result - result = original_instantiate(buffer, importObject) - result.then(({ module, instance }) => { - wireInstanceExports(instance, this_i) - self.analysis[this_i].init() - - }) - // self.performanceList.push(p_instantiationTime.stop()) - return result }; // replace instantiateStreaming WebAssembly.instantiateStreaming = async function (source, obj) {