tor-browser

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

CodePointRangeIterator.mjs (2040B)


      1 // generated by diplomat-tool
      2 import { CodePointRangeIteratorResult } from "./CodePointRangeIteratorResult.mjs"
      3 import wasm from "./diplomat-wasm.mjs";
      4 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      5 
      6 
      7 /**
      8 * An iterator over code point ranges, produced by `CodePointSetData` or
      9 * one of the `CodePointMapData` types
     10 */
     11 const CodePointRangeIterator_box_destroy_registry = new FinalizationRegistry((ptr) => {
     12    wasm.icu4x_CodePointRangeIterator_destroy_mv1(ptr);
     13 });
     14 
     15 export class CodePointRangeIterator {
     16    // Internal ptr reference:
     17    #ptr = null;
     18 
     19    // Lifetimes are only to keep dependencies alive.
     20    // Since JS won't garbage collect until there are no incoming edges.
     21    #selfEdge = [];
     22    #aEdge = [];
     23 
     24    #internalConstructor(symbol, ptr, selfEdge, aEdge) {
     25        if (symbol !== diplomatRuntime.internalConstructor) {
     26            console.error("CodePointRangeIterator is an Opaque type. You cannot call its constructor.");
     27            return;
     28        }
     29        this.#aEdge = aEdge;
     30        this.#ptr = ptr;
     31        this.#selfEdge = selfEdge;
     32 
     33        // Are we being borrowed? If not, we can register.
     34        if (this.#selfEdge.length === 0) {
     35            CodePointRangeIterator_box_destroy_registry.register(this, this.#ptr);
     36        }
     37 
     38        return this;
     39    }
     40    get ffiValue() {
     41        return this.#ptr;
     42    }
     43 
     44 
     45    /**
     46     * Advance the iterator by one and return the next range.
     47     *
     48     * If the iterator is out of items, `done` will be true
     49     */
     50    next() {
     51        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 12, 4, false);
     52 
     53 
     54        const result = wasm.icu4x_CodePointRangeIterator_next_mv1(diplomatReceive.buffer, this.ffiValue);
     55 
     56        try {
     57            return CodePointRangeIteratorResult._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer);
     58        }
     59 
     60        finally {
     61            diplomatReceive.free();
     62        }
     63    }
     64 
     65    constructor(symbol, ptr, selfEdge, aEdge) {
     66        return this.#internalConstructor(...arguments)
     67    }
     68 }