tor-browser

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

ListFormatter.mjs (8620B)


      1 // generated by diplomat-tool
      2 import { DataError } from "./DataError.mjs"
      3 import { DataProvider } from "./DataProvider.mjs"
      4 import { ListLength } from "./ListLength.mjs"
      5 import { Locale } from "./Locale.mjs"
      6 import wasm from "./diplomat-wasm.mjs";
      7 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      8 
      9 
     10 /**
     11 * See the [Rust documentation for `ListFormatter`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html) for more information.
     12 */
     13 const ListFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => {
     14    wasm.icu4x_ListFormatter_destroy_mv1(ptr);
     15 });
     16 
     17 export class ListFormatter {
     18    // Internal ptr reference:
     19    #ptr = null;
     20 
     21    // Lifetimes are only to keep dependencies alive.
     22    // Since JS won't garbage collect until there are no incoming edges.
     23    #selfEdge = [];
     24 
     25    #internalConstructor(symbol, ptr, selfEdge) {
     26        if (symbol !== diplomatRuntime.internalConstructor) {
     27            console.error("ListFormatter is an Opaque type. You cannot call its constructor.");
     28            return;
     29        }
     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            ListFormatter_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     * Construct a new ListFormatter instance for And patterns from compiled data.
     47     *
     48     * See the [Rust documentation for `try_new_and`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_and) for more information.
     49     */
     50    static createAndWithLength(locale, length) {
     51        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     52 
     53 
     54        const result = wasm.icu4x_ListFormatter_create_and_with_length_mv1(diplomatReceive.buffer, locale.ffiValue, length.ffiValue);
     55 
     56        try {
     57            if (!diplomatReceive.resultFlag) {
     58                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     59                throw new globalThis.Error('DataError: ' + cause.value, { cause });
     60            }
     61            return new ListFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     62        }
     63 
     64        finally {
     65            diplomatReceive.free();
     66        }
     67    }
     68 
     69    /**
     70     * Construct a new ListFormatter instance for And patterns
     71     *
     72     * See the [Rust documentation for `try_new_and`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_and) for more information.
     73     */
     74    static createAndWithLengthAndProvider(provider, locale, length) {
     75        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     76 
     77 
     78        const result = wasm.icu4x_ListFormatter_create_and_with_length_and_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue, length.ffiValue);
     79 
     80        try {
     81            if (!diplomatReceive.resultFlag) {
     82                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     83                throw new globalThis.Error('DataError: ' + cause.value, { cause });
     84            }
     85            return new ListFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     86        }
     87 
     88        finally {
     89            diplomatReceive.free();
     90        }
     91    }
     92 
     93    /**
     94     * Construct a new ListFormatter instance for And patterns from compiled data.
     95     *
     96     * See the [Rust documentation for `try_new_or`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_or) for more information.
     97     */
     98    static createOrWithLength(locale, length) {
     99        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    100 
    101 
    102        const result = wasm.icu4x_ListFormatter_create_or_with_length_mv1(diplomatReceive.buffer, locale.ffiValue, length.ffiValue);
    103 
    104        try {
    105            if (!diplomatReceive.resultFlag) {
    106                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    107                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    108            }
    109            return new ListFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    110        }
    111 
    112        finally {
    113            diplomatReceive.free();
    114        }
    115    }
    116 
    117    /**
    118     * Construct a new ListFormatter instance for And patterns
    119     *
    120     * See the [Rust documentation for `try_new_or`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_or) for more information.
    121     */
    122    static createOrWithLengthAndProvider(provider, locale, length) {
    123        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    124 
    125 
    126        const result = wasm.icu4x_ListFormatter_create_or_with_length_and_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue, length.ffiValue);
    127 
    128        try {
    129            if (!diplomatReceive.resultFlag) {
    130                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    131                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    132            }
    133            return new ListFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    134        }
    135 
    136        finally {
    137            diplomatReceive.free();
    138        }
    139    }
    140 
    141    /**
    142     * Construct a new ListFormatter instance for And patterns from compiled data.
    143     *
    144     * See the [Rust documentation for `try_new_unit`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_unit) for more information.
    145     */
    146    static createUnitWithLength(locale, length) {
    147        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    148 
    149 
    150        const result = wasm.icu4x_ListFormatter_create_unit_with_length_mv1(diplomatReceive.buffer, locale.ffiValue, length.ffiValue);
    151 
    152        try {
    153            if (!diplomatReceive.resultFlag) {
    154                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    155                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    156            }
    157            return new ListFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    158        }
    159 
    160        finally {
    161            diplomatReceive.free();
    162        }
    163    }
    164 
    165    /**
    166     * Construct a new ListFormatter instance for And patterns
    167     *
    168     * See the [Rust documentation for `try_new_unit`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_unit) for more information.
    169     */
    170    static createUnitWithLengthAndProvider(provider, locale, length) {
    171        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    172 
    173 
    174        const result = wasm.icu4x_ListFormatter_create_unit_with_length_and_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue, length.ffiValue);
    175 
    176        try {
    177            if (!diplomatReceive.resultFlag) {
    178                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    179                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    180            }
    181            return new ListFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    182        }
    183 
    184        finally {
    185            diplomatReceive.free();
    186        }
    187    }
    188 
    189    /**
    190     * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.format) for more information.
    191     */
    192    format(list) {
    193        let functionCleanupArena = new diplomatRuntime.CleanupArena();
    194 
    195        const listSlice = diplomatRuntime.DiplomatBuf.strs(wasm, list, "string16");
    196        const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
    197 
    198    wasm.icu4x_ListFormatter_format_utf16_mv1(this.ffiValue, ...listSlice.splat(), write.buffer);
    199 
    200        try {
    201            return write.readString8();
    202        }
    203 
    204        finally {
    205            functionCleanupArena.free();
    206 
    207            write.free();
    208        }
    209    }
    210 
    211    constructor(symbol, ptr, selfEdge) {
    212        return this.#internalConstructor(...arguments)
    213    }
    214 }