mirror of
https://github.com/remko/waforth
synced 2024-11-17 07:48:06 +01:00
simplify base64 handling
This commit is contained in:
parent
806ebd742c
commit
533de49cd5
1 changed files with 10 additions and 7 deletions
|
@ -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 },
|
||||
|
|
Loading…
Reference in a new issue