Skip to content

Commit

Permalink
refactor(loader): only create the buffer and extract response if ok. …
Browse files Browse the repository at this point in the history
…Cleanup
  • Loading branch information
TillaTheHun0 committed Nov 8, 2023
1 parent 42f77a7 commit 8897b38
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions loader/src/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,17 @@ module.exports = async function (binary) {
const doHandle = instance.cwrap('handle', 'string', ['string', 'string'])

return (buffer, msg, env) => {
if (buffer) {
instance.HEAPU8.set(buffer)
}
if (buffer) instance.HEAPU8.set(buffer)

const { ok, response } = JSON.parse(doHandle(JSON.stringify(msg), JSON.stringify(env)))

if (ok) {
buffer = instance.HEAPU8.slice()
return {
buffer,
output: response.output,
messages: response.messages,
spawns: response.spawns
}
if (!ok) throw response

return {
buffer: instance.HEAPU8.slice(),
output: response.output,
messages: response.messages,
spawns: response.spawns
}
throw response
}
}

0 comments on commit 8897b38

Please sign in to comment.