tor-browser

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

LocaleFallbackerWithConfig.mjs (2493B)


      1 // generated by diplomat-tool
      2 import { Locale } from "./Locale.mjs"
      3 import { LocaleFallbackIterator } from "./LocaleFallbackIterator.mjs"
      4 import wasm from "./diplomat-wasm.mjs";
      5 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      6 
      7 
      8 /**
      9 * An object that runs the ICU4X locale fallback algorithm with specific configurations.
     10 *
     11 * See the [Rust documentation for `LocaleFallbacker`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html) for more information.
     12 *
     13 * See the [Rust documentation for `LocaleFallbackerWithConfig`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackerWithConfig.html) for more information.
     14 */
     15 const LocaleFallbackerWithConfig_box_destroy_registry = new FinalizationRegistry((ptr) => {
     16    wasm.icu4x_LocaleFallbackerWithConfig_destroy_mv1(ptr);
     17 });
     18 
     19 export class LocaleFallbackerWithConfig {
     20    // Internal ptr reference:
     21    #ptr = null;
     22 
     23    // Lifetimes are only to keep dependencies alive.
     24    // Since JS won't garbage collect until there are no incoming edges.
     25    #selfEdge = [];
     26    #aEdge = [];
     27 
     28    #internalConstructor(symbol, ptr, selfEdge, aEdge) {
     29        if (symbol !== diplomatRuntime.internalConstructor) {
     30            console.error("LocaleFallbackerWithConfig is an Opaque type. You cannot call its constructor.");
     31            return;
     32        }
     33        this.#aEdge = aEdge;
     34        this.#ptr = ptr;
     35        this.#selfEdge = selfEdge;
     36 
     37        // Are we being borrowed? If not, we can register.
     38        if (this.#selfEdge.length === 0) {
     39            LocaleFallbackerWithConfig_box_destroy_registry.register(this, this.#ptr);
     40        }
     41 
     42        return this;
     43    }
     44    get ffiValue() {
     45        return this.#ptr;
     46    }
     47 
     48 
     49    /**
     50     * Creates an iterator from a locale with each step of fallback.
     51     *
     52     * See the [Rust documentation for `fallback_for`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html#method.fallback_for) for more information.
     53     */
     54    fallbackForLocale(locale) {
     55        // This lifetime edge depends on lifetimes 'a, 'b
     56        let aEdges = [this];
     57 
     58 
     59        const result = wasm.icu4x_LocaleFallbackerWithConfig_fallback_for_locale_mv1(this.ffiValue, locale.ffiValue);
     60 
     61        try {
     62            return new LocaleFallbackIterator(diplomatRuntime.internalConstructor, result, [], aEdges);
     63        }
     64 
     65        finally {
     66        }
     67    }
     68 
     69    constructor(symbol, ptr, selfEdge, aEdge) {
     70        return this.#internalConstructor(...arguments)
     71    }
     72 }