tor-browser

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

LocaleExpander.mjs (6302B)


      1 // generated by diplomat-tool
      2 import { DataError } from "./DataError.mjs"
      3 import { DataProvider } from "./DataProvider.mjs"
      4 import { Locale } from "./Locale.mjs"
      5 import { TransformResult } from "./TransformResult.mjs"
      6 import wasm from "./diplomat-wasm.mjs";
      7 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      8 
      9 
     10 /**
     11 * A locale expander.
     12 *
     13 * See the [Rust documentation for `LocaleExpander`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html) for more information.
     14 */
     15 const LocaleExpander_box_destroy_registry = new FinalizationRegistry((ptr) => {
     16    wasm.icu4x_LocaleExpander_destroy_mv1(ptr);
     17 });
     18 
     19 export class LocaleExpander {
     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 
     27    #internalConstructor(symbol, ptr, selfEdge) {
     28        if (symbol !== diplomatRuntime.internalConstructor) {
     29            console.error("LocaleExpander is an Opaque type. You cannot call its constructor.");
     30            return;
     31        }
     32        this.#ptr = ptr;
     33        this.#selfEdge = selfEdge;
     34 
     35        // Are we being borrowed? If not, we can register.
     36        if (this.#selfEdge.length === 0) {
     37            LocaleExpander_box_destroy_registry.register(this, this.#ptr);
     38        }
     39 
     40        return this;
     41    }
     42    get ffiValue() {
     43        return this.#ptr;
     44    }
     45 
     46 
     47    /**
     48     * Create a new [`LocaleExpander`] using compiled data.
     49     *
     50     * See the [Rust documentation for `new_common`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.new_common) for more information.
     51     */
     52    #defaultConstructor() {
     53 
     54        const result = wasm.icu4x_LocaleExpander_create_common_mv1();
     55 
     56        try {
     57            return new LocaleExpander(diplomatRuntime.internalConstructor, result, []);
     58        }
     59 
     60        finally {
     61        }
     62    }
     63 
     64    /**
     65     * Create a new [`LocaleExpander`] using a new_common data source.
     66     *
     67     * See the [Rust documentation for `new_common`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.new_common) for more information.
     68     */
     69    static createCommonWithProvider(provider) {
     70        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     71 
     72 
     73        const result = wasm.icu4x_LocaleExpander_create_common_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
     74 
     75        try {
     76            if (!diplomatReceive.resultFlag) {
     77                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     78                throw new globalThis.Error('DataError: ' + cause.value, { cause });
     79            }
     80            return new LocaleExpander(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     81        }
     82 
     83        finally {
     84            diplomatReceive.free();
     85        }
     86    }
     87 
     88    /**
     89     * Create a new [`LocaleExpander`] with extended data using compiled data.
     90     *
     91     * See the [Rust documentation for `new_extended`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.new_extended) for more information.
     92     */
     93    static createExtended() {
     94 
     95        const result = wasm.icu4x_LocaleExpander_create_extended_mv1();
     96 
     97        try {
     98            return new LocaleExpander(diplomatRuntime.internalConstructor, result, []);
     99        }
    100 
    101        finally {
    102        }
    103    }
    104 
    105    /**
    106     * Create a new [`LocaleExpander`] with extended data using a particular data source.
    107     *
    108     * See the [Rust documentation for `new_extended`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.new_extended) for more information.
    109     */
    110    static createExtendedWithProvider(provider) {
    111        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    112 
    113 
    114        const result = wasm.icu4x_LocaleExpander_create_extended_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
    115 
    116        try {
    117            if (!diplomatReceive.resultFlag) {
    118                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    119                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    120            }
    121            return new LocaleExpander(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    122        }
    123 
    124        finally {
    125            diplomatReceive.free();
    126        }
    127    }
    128 
    129    /**
    130     * See the [Rust documentation for `maximize`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.maximize) for more information.
    131     */
    132    maximize(locale) {
    133 
    134        const result = wasm.icu4x_LocaleExpander_maximize_mv1(this.ffiValue, locale.ffiValue);
    135 
    136        try {
    137            return new TransformResult(diplomatRuntime.internalConstructor, result);
    138        }
    139 
    140        finally {
    141        }
    142    }
    143 
    144    /**
    145     * See the [Rust documentation for `minimize`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.minimize) for more information.
    146     */
    147    minimize(locale) {
    148 
    149        const result = wasm.icu4x_LocaleExpander_minimize_mv1(this.ffiValue, locale.ffiValue);
    150 
    151        try {
    152            return new TransformResult(diplomatRuntime.internalConstructor, result);
    153        }
    154 
    155        finally {
    156        }
    157    }
    158 
    159    /**
    160     * See the [Rust documentation for `minimize_favor_script`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.minimize_favor_script) for more information.
    161     */
    162    minimizeFavorScript(locale) {
    163 
    164        const result = wasm.icu4x_LocaleExpander_minimize_favor_script_mv1(this.ffiValue, locale.ffiValue);
    165 
    166        try {
    167            return new TransformResult(diplomatRuntime.internalConstructor, result);
    168        }
    169 
    170        finally {
    171        }
    172    }
    173 
    174    constructor() {
    175        if (arguments[0] === diplomatRuntime.exposeConstructor) {
    176            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
    177        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
    178            return this.#internalConstructor(...arguments);
    179        } else {
    180            return this.#defaultConstructor(...arguments);
    181        }
    182    }
    183 }