tor-browser

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

EmojiSetData.mjs (4549B)


      1 // generated by diplomat-tool
      2 import { DataError } from "./DataError.mjs"
      3 import { DataProvider } from "./DataProvider.mjs"
      4 import wasm from "./diplomat-wasm.mjs";
      5 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      6 
      7 
      8 /**
      9 * An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property.
     10 *
     11 * See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information.
     12 *
     13 * See the [Rust documentation for `EmojiSetData`](https://docs.rs/icu/latest/icu/properties/struct.EmojiSetData.html) for more information.
     14 *
     15 * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/properties/struct.EmojiSetData.html#method.new) for more information.
     16 *
     17 * See the [Rust documentation for `EmojiSetDataBorrowed`](https://docs.rs/icu/latest/icu/properties/struct.EmojiSetDataBorrowed.html) for more information.
     18 */
     19 const EmojiSetData_box_destroy_registry = new FinalizationRegistry((ptr) => {
     20    wasm.icu4x_EmojiSetData_destroy_mv1(ptr);
     21 });
     22 
     23 export class EmojiSetData {
     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("EmojiSetData 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            EmojiSetData_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     * Checks whether the string is in the set.
     53     *
     54     * See the [Rust documentation for `contains_str`](https://docs.rs/icu/latest/icu/properties/struct.EmojiSetDataBorrowed.html#method.contains_str) for more information.
     55     */
     56    containsStr(s) {
     57        let functionCleanupArena = new diplomatRuntime.CleanupArena();
     58 
     59        const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s);
     60 
     61        const result = wasm.icu4x_EmojiSetData_contains_str_mv1(this.ffiValue, ...sSlice.splat());
     62 
     63        try {
     64            return result;
     65        }
     66 
     67        finally {
     68            functionCleanupArena.free();
     69 
     70        }
     71    }
     72 
     73    /**
     74     * Checks whether the code point is in the set.
     75     *
     76     * See the [Rust documentation for `contains`](https://docs.rs/icu/latest/icu/properties/struct.EmojiSetDataBorrowed.html#method.contains) for more information.
     77     */
     78    contains(cp) {
     79 
     80        const result = wasm.icu4x_EmojiSetData_contains_mv1(this.ffiValue, cp);
     81 
     82        try {
     83            return result;
     84        }
     85 
     86        finally {
     87        }
     88    }
     89 
     90    /**
     91     * Create a map for the `Basic_Emoji` property, using compiled data.
     92     *
     93     * See the [Rust documentation for `BasicEmoji`](https://docs.rs/icu/latest/icu/properties/props/struct.BasicEmoji.html) for more information.
     94     */
     95    static createBasic() {
     96 
     97        const result = wasm.icu4x_EmojiSetData_create_basic_mv1();
     98 
     99        try {
    100            return new EmojiSetData(diplomatRuntime.internalConstructor, result, []);
    101        }
    102 
    103        finally {
    104        }
    105    }
    106 
    107    /**
    108     * Create a map for the `Basic_Emoji` property, using a particular data source.
    109     *
    110     * See the [Rust documentation for `BasicEmoji`](https://docs.rs/icu/latest/icu/properties/props/struct.BasicEmoji.html) for more information.
    111     */
    112    static createBasicWithProvider(provider) {
    113        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    114 
    115 
    116        const result = wasm.icu4x_EmojiSetData_create_basic_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
    117 
    118        try {
    119            if (!diplomatReceive.resultFlag) {
    120                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    121                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    122            }
    123            return new EmojiSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    124        }
    125 
    126        finally {
    127            diplomatReceive.free();
    128        }
    129    }
    130 
    131    constructor(symbol, ptr, selfEdge) {
    132        return this.#internalConstructor(...arguments)
    133    }
    134 }