• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { TimeZone } from "./TimeZone.mjs"
3import wasm from "./diplomat-wasm.mjs";
4import * as diplomatRuntime from "./diplomat-runtime.mjs";
5
6
7/** See the [Rust documentation for `TimeZoneIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneIter.html) for more information.
8*/
9const TimeZoneIterator_box_destroy_registry = new FinalizationRegistry((ptr) => {
10    wasm.icu4x_TimeZoneIterator_destroy_mv1(ptr);
11});
12
13export class TimeZoneIterator {
14
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("TimeZoneIterator is an Opaque type. You cannot call its constructor.");
26            return;
27        }
28
29
30        this.#aEdge = aEdge;
31
32        this.#ptr = ptr;
33        this.#selfEdge = selfEdge;
34
35        // Are we being borrowed? If not, we can register.
36        if (this.#selfEdge.length === 0) {
37            TimeZoneIterator_box_destroy_registry.register(this, this.#ptr);
38        }
39
40        return this;
41    }
42    get ffiValue() {
43        return this.#ptr;
44    }
45
46    #iteratorNext() {
47        const result = wasm.icu4x_TimeZoneIterator_next_mv1(this.ffiValue);
48
49        try {
50            return result === 0 ? null : new TimeZone(diplomatRuntime.internalConstructor, result, []);
51        }
52
53        finally {}
54    }
55
56    next() {
57        const out = this.#iteratorNext();
58
59        return {
60            value: out,
61            done: out === null,
62        };
63    }
64
65    constructor(symbol, ptr, selfEdge, aEdge) {
66        return this.#internalConstructor(...arguments)
67    }
68}