Skip to content

Commit

Permalink
fix(): TextEncoder and TextDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
dorin131 committed Dec 15, 2019
1 parent 425b033 commit 7b026b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
const wabt = require('wabt')();
const util = require('util');
let Decoder = TextDecoder;
let Encoder = TextEncoder;
if (!Decoder || !Encoder) {
Decoder = util.TextDecoder;
Encoder = util.TextEncoder;

getDecoderEncoder = () => {
let Decoder, Encoder;
try {
Decoder = TextDecoder;
Encoder = TextEncoder;
} catch (e) {
Decoder = util.TextDecoder;
Encoder = util.TextEncoder;
}
return { Decoder, Encoder };
}

module.exports = async (input, importObject) => {
const { Decoder, Encoder } = getDecoderEncoder();
const wasmModule = wabt.parseWat('inline', new Encoder('utf-8').encode(input));
const { buffer } = wasmModule.toBinary({});
const module = await WebAssembly.compile(buffer);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inline-webassembly",
"version": "1.0.5",
"version": "1.0.6",
"description": "Inline WebAssembly (text format) into JS",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down

0 comments on commit 7b026b6

Please sign in to comment.