Skip to content

Commit

Permalink
chore(loader): introducing new formats for metering
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterFarber authored and TillaTheHun0 committed Oct 16, 2024
1 parent 82658f4 commit ac404af
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions loader/src/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const originalCompileStreaming = WebAssembly.compileStreaming
const originalCompile = WebAssembly.compile

const shouldApplyMetering = (importObject = {}) => {
return importObject.applyMetering && ['wasm32-unknown-emscripten4', 'wasm64-unknown-emscripten-draft_2024_02_15'].includes(importObject.format);
return ['wasm32-unknown-emscripten-metering', 'wasm64-unknown-emscripten-draft_2024_10_16-metering'].includes(importObject.format);
}

const applyMetering = (arrayBuffer, importObject) => {
Expand All @@ -128,15 +128,15 @@ const applyMetering = (arrayBuffer, importObject) => {
}

// Override WebAssembly.compileStreaming to apply metering
WebAssembly.compileStreaming = async function (source, importObject = { applyMetering: false }) {
WebAssembly.compileStreaming = async function (source, importObject = { }) {
if (!shouldApplyMetering(importObject)) return originalCompileStreaming(source)

const arrayBuffer = await source.arrayBuffer()
return applyMetering(arrayBuffer, importObject)
}

// Override WebAssembly.compile to apply metering
WebAssembly.compile = async function (source, importObject = { applyMetering: false }) {
WebAssembly.compile = async function (source, importObject = { }) {
if (!shouldApplyMetering(importObject)) return originalCompile(source)

return applyMetering(source, importObject)
Expand Down Expand Up @@ -167,9 +167,9 @@ module.exports = async function (binary, options) {
options.wasmBinary = binary
}

if (options.format === "wasm64-unknown-emscripten-draft_2024_02_15") {
if (options.format === "wasm64-unknown-emscripten-draft_2024_02_15" || options.format === "wasm64-unknown-emscripten-draft_2024_10_16-metering") {
instance = await Wasm64(options)
} else if (options.format === "wasm32-unknown-emscripten4") {
} else if (options.format === "wasm32-unknown-emscripten4" || options.format === "wasm32-unknown-emscripten-metering") {
instance = await Emscripten4(options)
}

Expand Down

0 comments on commit ac404af

Please sign in to comment.