TimeZoneAndCanonicalIterator.mjs (2481B)
1 // generated by diplomat-tool 2 import { TimeZoneAndCanonical } from "./TimeZoneAndCanonical.mjs" 3 import wasm from "./diplomat-wasm.mjs"; 4 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 5 6 7 /** 8 * See the [Rust documentation for `TimeZoneAndCanonicalIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalIter.html) for more information. 9 */ 10 const TimeZoneAndCanonicalIterator_box_destroy_registry = new FinalizationRegistry((ptr) => { 11 wasm.icu4x_TimeZoneAndCanonicalIterator_destroy_mv1(ptr); 12 }); 13 14 export class TimeZoneAndCanonicalIterator { 15 // Internal ptr reference: 16 #ptr = null; 17 18 // Lifetimes are only to keep dependencies alive. 19 // Since JS won't garbage collect until there are no incoming edges. 20 #selfEdge = []; 21 #aEdge = []; 22 23 #internalConstructor(symbol, ptr, selfEdge, aEdge) { 24 if (symbol !== diplomatRuntime.internalConstructor) { 25 console.error("TimeZoneAndCanonicalIterator is an Opaque type. You cannot call its constructor."); 26 return; 27 } 28 this.#aEdge = aEdge; 29 this.#ptr = ptr; 30 this.#selfEdge = selfEdge; 31 32 // Are we being borrowed? If not, we can register. 33 if (this.#selfEdge.length === 0) { 34 TimeZoneAndCanonicalIterator_box_destroy_registry.register(this, this.#ptr); 35 } 36 37 return this; 38 } 39 get ffiValue() { 40 return this.#ptr; 41 } 42 43 44 /** 45 * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalIter.html#method.next) for more information. 46 */ 47 #iteratorNext() { 48 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 13, 4, true); 49 50 // This lifetime edge depends on lifetimes 'a 51 let aEdges = [this]; 52 53 54 const result = wasm.icu4x_TimeZoneAndCanonicalIterator_next_mv1(diplomatReceive.buffer, this.ffiValue); 55 56 try { 57 if (!diplomatReceive.resultFlag) { 58 return null; 59 } 60 return TimeZoneAndCanonical._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer, aEdges); 61 } 62 63 finally { 64 diplomatReceive.free(); 65 } 66 } 67 68 next(){ 69 const out = this.#iteratorNext(); 70 71 return { 72 value: out, 73 done: out === null, 74 }; 75 } 76 77 constructor(symbol, ptr, selfEdge, aEdge) { 78 return this.#internalConstructor(...arguments) 79 } 80 }