tor-browser

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

IanaParserExtended.mjs (5818B)


      1 // generated by diplomat-tool
      2 import { DataError } from "./DataError.mjs"
      3 import { DataProvider } from "./DataProvider.mjs"
      4 import { TimeZoneAndCanonicalAndNormalized } from "./TimeZoneAndCanonicalAndNormalized.mjs"
      5 import { TimeZoneAndCanonicalAndNormalizedIterator } from "./TimeZoneAndCanonicalAndNormalizedIterator.mjs"
      6 import { TimeZoneAndCanonicalIterator } from "./TimeZoneAndCanonicalIterator.mjs"
      7 import wasm from "./diplomat-wasm.mjs";
      8 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      9 
     10 
     11 /**
     12 * A mapper between IANA time zone identifiers and BCP-47 time zone identifiers.
     13 *
     14 * This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47.
     15 * It also supports normalizing and canonicalizing the IANA strings.
     16 *
     17 * See the [Rust documentation for `IanaParserExtended`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtended.html) for more information.
     18 */
     19 const IanaParserExtended_box_destroy_registry = new FinalizationRegistry((ptr) => {
     20    wasm.icu4x_IanaParserExtended_destroy_mv1(ptr);
     21 });
     22 
     23 export class IanaParserExtended {
     24    // Internal ptr reference:
     25    #ptr = null;
     26 
     27    // Lifetimes are only to keep dependencies alive.
     28    // Since JS won't garbage collect until there are no incoming edges.
     29    #selfEdge = [];
     30 
     31    #internalConstructor(symbol, ptr, selfEdge) {
     32        if (symbol !== diplomatRuntime.internalConstructor) {
     33            console.error("IanaParserExtended is an Opaque type. You cannot call its constructor.");
     34            return;
     35        }
     36        this.#ptr = ptr;
     37        this.#selfEdge = selfEdge;
     38 
     39        // Are we being borrowed? If not, we can register.
     40        if (this.#selfEdge.length === 0) {
     41            IanaParserExtended_box_destroy_registry.register(this, this.#ptr);
     42        }
     43 
     44        return this;
     45    }
     46    get ffiValue() {
     47        return this.#ptr;
     48    }
     49 
     50 
     51    /**
     52     * Create a new [`IanaParserExtended`] using compiled data
     53     *
     54     * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtended.html#method.new) for more information.
     55     */
     56    #defaultConstructor() {
     57 
     58        const result = wasm.icu4x_IanaParserExtended_create_mv1();
     59 
     60        try {
     61            return new IanaParserExtended(diplomatRuntime.internalConstructor, result, []);
     62        }
     63 
     64        finally {
     65        }
     66    }
     67 
     68    /**
     69     * Create a new [`IanaParserExtended`] using a particular data source
     70     *
     71     * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtended.html#method.new) for more information.
     72     */
     73    static createWithProvider(provider) {
     74        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     75 
     76 
     77        const result = wasm.icu4x_IanaParserExtended_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
     78 
     79        try {
     80            if (!diplomatReceive.resultFlag) {
     81                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     82                throw new globalThis.Error('DataError: ' + cause.value, { cause });
     83            }
     84            return new IanaParserExtended(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     85        }
     86 
     87        finally {
     88            diplomatReceive.free();
     89        }
     90    }
     91 
     92    /**
     93     * See the [Rust documentation for `parse`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtendedBorrowed.html#method.parse) for more information.
     94     */
     95    parse(value) {
     96        let functionCleanupArena = new diplomatRuntime.CleanupArena();
     97 
     98        const valueSlice = diplomatRuntime.DiplomatBuf.str8(wasm, value);
     99        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 20, 4, false);
    100 
    101        // This lifetime edge depends on lifetimes 'a
    102        let aEdges = [this];
    103 
    104 
    105        const result = wasm.icu4x_IanaParserExtended_parse_mv1(diplomatReceive.buffer, this.ffiValue, ...valueSlice.splat());
    106 
    107        try {
    108            return TimeZoneAndCanonicalAndNormalized._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer, aEdges);
    109        }
    110 
    111        finally {
    112            functionCleanupArena.free();
    113 
    114            diplomatReceive.free();
    115        }
    116    }
    117 
    118    /**
    119     * See the [Rust documentation for `iter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtendedBorrowed.html#method.iter) for more information.
    120     */
    121    iter() {
    122        // This lifetime edge depends on lifetimes 'a
    123        let aEdges = [this];
    124 
    125 
    126        const result = wasm.icu4x_IanaParserExtended_iter_mv1(this.ffiValue);
    127 
    128        try {
    129            return new TimeZoneAndCanonicalIterator(diplomatRuntime.internalConstructor, result, [], aEdges);
    130        }
    131 
    132        finally {
    133        }
    134    }
    135 
    136    /**
    137     * See the [Rust documentation for `iter_all`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtendedBorrowed.html#method.iter_all) for more information.
    138     */
    139    iterAll() {
    140        // This lifetime edge depends on lifetimes 'a
    141        let aEdges = [this];
    142 
    143 
    144        const result = wasm.icu4x_IanaParserExtended_iter_all_mv1(this.ffiValue);
    145 
    146        try {
    147            return new TimeZoneAndCanonicalAndNormalizedIterator(diplomatRuntime.internalConstructor, result, [], aEdges);
    148        }
    149 
    150        finally {
    151        }
    152    }
    153 
    154    constructor() {
    155        if (arguments[0] === diplomatRuntime.exposeConstructor) {
    156            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
    157        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
    158            return this.#internalConstructor(...arguments);
    159        } else {
    160            return this.#defaultConstructor(...arguments);
    161        }
    162    }
    163 }