• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { Locale } from "./Locale.mjs"
3import { LocaleFallbackIterator } from "./LocaleFallbackIterator.mjs"
4import wasm from "./diplomat-wasm.mjs";
5import * as diplomatRuntime from "./diplomat-runtime.mjs";
6
7
8/** An object that runs the ICU4X locale fallback algorithm with specific configurations.
9*
10*See the [Rust documentation for `LocaleFallbacker`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html) for more information.
11*
12*See the [Rust documentation for `LocaleFallbackerWithConfig`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackerWithConfig.html) for more information.
13*/
14const LocaleFallbackerWithConfig_box_destroy_registry = new FinalizationRegistry((ptr) => {
15    wasm.icu4x_LocaleFallbackerWithConfig_destroy_mv1(ptr);
16});
17
18export class LocaleFallbackerWithConfig {
19
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
34
35        this.#aEdge = aEdge;
36
37        this.#ptr = ptr;
38        this.#selfEdge = selfEdge;
39
40        // Are we being borrowed? If not, we can register.
41        if (this.#selfEdge.length === 0) {
42            LocaleFallbackerWithConfig_box_destroy_registry.register(this, this.#ptr);
43        }
44
45        return this;
46    }
47    get ffiValue() {
48        return this.#ptr;
49    }
50
51    fallbackForLocale(locale) {
52        // This lifetime edge depends on lifetimes 'a, 'b
53        let aEdges = [this];
54
55        const result = wasm.icu4x_LocaleFallbackerWithConfig_fallback_for_locale_mv1(this.ffiValue, locale.ffiValue);
56
57        try {
58            return new LocaleFallbackIterator(diplomatRuntime.internalConstructor, result, [], aEdges);
59        }
60
61        finally {}
62    }
63
64    constructor(symbol, ptr, selfEdge, aEdge) {
65        return this.#internalConstructor(...arguments)
66    }
67}