Logger.mjs (1562B)
1 // generated by diplomat-tool 2 import wasm from "./diplomat-wasm.mjs"; 3 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 4 5 6 /** 7 * An object allowing control over the logging used 8 */ 9 const Logger_box_destroy_registry = new FinalizationRegistry((ptr) => { 10 wasm.icu4x_Logger_destroy_mv1(ptr); 11 }); 12 13 export class Logger { 14 // Internal ptr reference: 15 #ptr = null; 16 17 // Lifetimes are only to keep dependencies alive. 18 // Since JS won't garbage collect until there are no incoming edges. 19 #selfEdge = []; 20 21 #internalConstructor(symbol, ptr, selfEdge) { 22 if (symbol !== diplomatRuntime.internalConstructor) { 23 console.error("Logger is an Opaque type. You cannot call its constructor."); 24 return; 25 } 26 this.#ptr = ptr; 27 this.#selfEdge = selfEdge; 28 29 // Are we being borrowed? If not, we can register. 30 if (this.#selfEdge.length === 0) { 31 Logger_box_destroy_registry.register(this, this.#ptr); 32 } 33 34 return this; 35 } 36 get ffiValue() { 37 return this.#ptr; 38 } 39 40 41 /** 42 * Initialize the logger using `simple_logger` 43 * 44 * Requires the `simple_logger` Cargo feature. 45 * 46 * Returns `false` if there was already a logger set. 47 */ 48 static initSimpleLogger() { 49 50 const result = wasm.icu4x_Logger_init_simple_logger_mv1(); 51 52 try { 53 return result; 54 } 55 56 finally { 57 } 58 } 59 60 constructor(symbol, ptr, selfEdge) { 61 return this.#internalConstructor(...arguments) 62 } 63 }