prelude.js (928B)
1 // The prelude defines basic functionality 2 // that is expected by the Taler wallet core JavaScript, 3 // but not provided by quickjs or the "tart" module directly. 4 5 import * as os from "os"; 6 import * as tart from "tart"; 7 8 class TextEncoder { 9 encode(str) { 10 return new Uint8Array(tart.encodeUtf8(str)); 11 } 12 } 13 14 class TextDecoder { 15 decode(bytes) { 16 return tart.decodeUtf8(bytes); 17 } 18 } 19 20 globalThis.TextEncoder = TextEncoder; 21 globalThis.TextDecoder = TextDecoder; 22 globalThis.setTimeout = (f, t) => os.setTimeout(f, t); 23 globalThis.clearTimeout = (h) => os.clearTimeout(h); 24 globalThis.setImmediate = (f) => os.setTimeout(f, 0); 25 26 // FIXME: log to the right streams! 27 console.info = (...args) => { console.log(...args); }; 28 console.warn = (...args) => { console.log(...args); }; 29 console.error = (...args) => { console.log(...args); }; 30 console.assert = (b) => { if (!b) throw Error("assertion failed") }; 31 32 globalThis._tart = tart;