simplify base64 handling

This commit is contained in:
Remko Tronçon 2022-04-14 21:46:06 +02:00
parent 806ebd742c
commit 533de49cd5

View file

@ -4,19 +4,22 @@ const isSafari =
typeof navigator != "undefined" &&
/^((?!chrome|android).)*safari/i.test(navigator.userAgent);
class WAForth {
constructor(arrayToBase64) {
this.arrayToBase64 =
arrayToBase64 ||
function arrayToBase64(bytes) {
const arrayToBase64 =
typeof "Buffer" === "undefined"
? function arrayToBase64(bytes) {
var binary = "";
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
: function arrayToBase64(bytes) {
return Buffer.from(s).toString("base64");
};
}
class WAForth {
constructor() {}
start() {
let table;
@ -82,7 +85,7 @@ class WAForth {
if (index >= table.length) {
table.grow(table.length); // Double size
}
// console.log("Load", index, this.arrayToBase64(data));
// console.log("Load", index, arrayToBase64(data));
var module = new WebAssembly.Module(data);
new WebAssembly.Instance(module, {
env: { table, memory, tos: -1 },