LocaleFallbackIterator.mjs (1940B)
1 // generated by diplomat-tool 2 import { Locale } from "./Locale.mjs" 3 import wasm from "./diplomat-wasm.mjs"; 4 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 5 6 7 /** 8 * An iterator over the locale under fallback. 9 * 10 * See the [Rust documentation for `LocaleFallbackIterator`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackIterator.html) for more information. 11 */ 12 const LocaleFallbackIterator_box_destroy_registry = new FinalizationRegistry((ptr) => { 13 wasm.icu4x_LocaleFallbackIterator_destroy_mv1(ptr); 14 }); 15 16 export class LocaleFallbackIterator { 17 // Internal ptr reference: 18 #ptr = null; 19 20 // Lifetimes are only to keep dependencies alive. 21 // Since JS won't garbage collect until there are no incoming edges. 22 #selfEdge = []; 23 #aEdge = []; 24 25 #internalConstructor(symbol, ptr, selfEdge, aEdge) { 26 if (symbol !== diplomatRuntime.internalConstructor) { 27 console.error("LocaleFallbackIterator is an Opaque type. You cannot call its constructor."); 28 return; 29 } 30 this.#aEdge = aEdge; 31 this.#ptr = ptr; 32 this.#selfEdge = selfEdge; 33 34 // Are we being borrowed? If not, we can register. 35 if (this.#selfEdge.length === 0) { 36 LocaleFallbackIterator_box_destroy_registry.register(this, this.#ptr); 37 } 38 39 return this; 40 } 41 get ffiValue() { 42 return this.#ptr; 43 } 44 45 46 #iteratorNext() { 47 48 const result = wasm.icu4x_LocaleFallbackIterator_next_mv1(this.ffiValue); 49 50 try { 51 return result === 0 ? null : new Locale(diplomatRuntime.internalConstructor, result, []); 52 } 53 54 finally { 55 } 56 } 57 58 next(){ 59 const out = this.#iteratorNext(); 60 61 return { 62 value: out, 63 done: out === null, 64 }; 65 } 66 67 constructor(symbol, ptr, selfEdge, aEdge) { 68 return this.#internalConstructor(...arguments) 69 } 70 }