Skip to content

Commit

Permalink
Fix export object retrieval in WebAssembly.instantiate()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Baker committed Apr 26, 2022
1 parent 2a4722f commit cd7e42f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions content/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,20 +825,26 @@ const webAssemblyInstantiateHook = function(inObject, importObject = {}) {

return new Promise(function(resolve, reject) {
oldWebAssemblyInstantiate(instrumentedObject, importObject).then(function(instanceObject) {
let instance = instanceObject;

if (typeof instanceObject.instance !== "undefined") {
instance = instanceObject.instance;
}

if (typeof memoryDescriptor !== "undefined" && memoryDescriptor.type === "export") {
memoryInstance = getMemoryFromObject(instanceObject.exports, memoryDescriptor);
let exportObject = instance.exports;

if (typeof exportObject !== "object") {
colorError("WebAssembly.instantiate() failed to retrieve export object for instantiated module");
}

memoryInstance = getMemoryFromObject(exportObject, memoryDescriptor);
}

if (!(memoryInstance instanceof WebAssembly.Memory)) {
colorError("WebAssembly.instantiate() failed to retrieve a WebAssembly.Memory object");
}

let instance = instanceObject;

if (typeof instanceObject.instance !== "undefined") {
instance = instanceObject.instance;
}

cetus = new Cetus({
memory: memoryInstance,
watchpointExports: [instance.exports.addWatch],
Expand Down

0 comments on commit cd7e42f

Please sign in to comment.