tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WeekdaySetIterator.mjs (2326B)


      1 // generated by diplomat-tool
      2 import { Weekday } from "./Weekday.mjs"
      3 import wasm from "./diplomat-wasm.mjs";
      4 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      5 
      6 
      7 /**
      8 * Documents which days of the week are considered to be a part of the weekend
      9 *
     10 * See the [Rust documentation for `WeekdaySetIterator`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekdaySetIterator.html) for more information.
     11 */
     12 const WeekdaySetIterator_box_destroy_registry = new FinalizationRegistry((ptr) => {
     13    wasm.icu4x_WeekdaySetIterator_destroy_mv1(ptr);
     14 });
     15 
     16 export class WeekdaySetIterator {
     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 
     24    #internalConstructor(symbol, ptr, selfEdge) {
     25        if (symbol !== diplomatRuntime.internalConstructor) {
     26            console.error("WeekdaySetIterator is an Opaque type. You cannot call its constructor.");
     27            return;
     28        }
     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            WeekdaySetIterator_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/calendar/week/struct.WeekdaySetIterator.html#method.next) for more information.
     46     */
     47    #iteratorNext() {
     48        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     49 
     50 
     51        const result = wasm.icu4x_WeekdaySetIterator_next_mv1(diplomatReceive.buffer, this.ffiValue);
     52 
     53        try {
     54            if (!diplomatReceive.resultFlag) {
     55                return null;
     56            }
     57            return new Weekday(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     58        }
     59 
     60        finally {
     61            diplomatReceive.free();
     62        }
     63    }
     64 
     65    next(){
     66        const out = this.#iteratorNext();
     67 
     68        return {
     69            value: out,
     70            done: out === null,
     71        };
     72    }
     73 
     74    constructor(symbol, ptr, selfEdge) {
     75        return this.#internalConstructor(...arguments)
     76    }
     77 }