Skip to content

Commit

Permalink
Fix order of WASM loading (nodejs#1204)
Browse files Browse the repository at this point in the history
* fix: loading simd should be first

* feat: inline require calls
  • Loading branch information
mcfedr authored and metcoder95 committed Dec 26, 2022
1 parent 571f9ce commit d1683e0
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const {
HTTPParserError
} = require('./core/errors')
const buildConnector = require('./core/connect')
const llhttpWasmData = require('./llhttp/llhttp.wasm.js')
const llhttpSimdWasmData = require('./llhttp/llhttp_simd.wasm.js')

const {
kUrl,
kReset,
Expand Down Expand Up @@ -413,15 +410,15 @@ const EMPTY_BUF = Buffer.alloc(0)
async function lazyllhttp () {
let mod
try {
mod = await WebAssembly.compile(Buffer.from(llhttpWasmData, 'base64'))
mod = await WebAssembly.compile(Buffer.from(require('./llhttp/llhttp_simd.wasm.js'), 'base64'))
} catch (e) {
/* istanbul ignore next */

// We could check if the error was caused by the simd option not
// being enabled, but the occurring of this other error
// * https://github.com/emscripten-core/emscripten/issues/11495
// got me to remove that check to avoid breaking Node 12.
mod = await WebAssembly.compile(Buffer.from(llhttpSimdWasmData, 'base64'))
mod = await WebAssembly.compile(Buffer.from(require('./llhttp/llhttp.wasm.js'), 'base64'))
}

return await WebAssembly.instantiate(mod, {
Expand Down

0 comments on commit d1683e0

Please sign in to comment.