tor-browser

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

GeneralCategoryNameToGroupMapper.mjs (5404B)


      1 // generated by diplomat-tool
      2 import { DataError } from "./DataError.mjs"
      3 import { DataProvider } from "./DataProvider.mjs"
      4 import { GeneralCategoryGroup } from "./GeneralCategoryGroup.mjs"
      5 import wasm from "./diplomat-wasm.mjs";
      6 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      7 
      8 
      9 /**
     10 * A type capable of looking up General Category Group values from a string name.
     11 *
     12 * See the [Rust documentation for `PropertyParser`](https://docs.rs/icu/latest/icu/properties/struct.PropertyParser.html) for more information.
     13 *
     14 * See the [Rust documentation for `GeneralCategory`](https://docs.rs/icu/latest/icu/properties/props/enum.GeneralCategory.html) for more information.
     15 */
     16 const GeneralCategoryNameToGroupMapper_box_destroy_registry = new FinalizationRegistry((ptr) => {
     17    wasm.icu4x_GeneralCategoryNameToGroupMapper_destroy_mv1(ptr);
     18 });
     19 
     20 export class GeneralCategoryNameToGroupMapper {
     21    // Internal ptr reference:
     22    #ptr = null;
     23 
     24    // Lifetimes are only to keep dependencies alive.
     25    // Since JS won't garbage collect until there are no incoming edges.
     26    #selfEdge = [];
     27 
     28    #internalConstructor(symbol, ptr, selfEdge) {
     29        if (symbol !== diplomatRuntime.internalConstructor) {
     30            console.error("GeneralCategoryNameToGroupMapper is an Opaque type. You cannot call its constructor.");
     31            return;
     32        }
     33        this.#ptr = ptr;
     34        this.#selfEdge = selfEdge;
     35 
     36        // Are we being borrowed? If not, we can register.
     37        if (this.#selfEdge.length === 0) {
     38            GeneralCategoryNameToGroupMapper_box_destroy_registry.register(this, this.#ptr);
     39        }
     40 
     41        return this;
     42    }
     43    get ffiValue() {
     44        return this.#ptr;
     45    }
     46 
     47 
     48    /**
     49     * Get the mask value matching the given name, using strict matching
     50     *
     51     * Returns 0 if the name is unknown for this property
     52     *
     53     * See the [Rust documentation for `get_strict`](https://docs.rs/icu/latest/icu/properties/struct.PropertyParserBorrowed.html#method.get_strict) for more information.
     54     */
     55    getStrict(name) {
     56        let functionCleanupArena = new diplomatRuntime.CleanupArena();
     57 
     58        const nameSlice = diplomatRuntime.DiplomatBuf.str8(wasm, name);
     59 
     60        const result = wasm.icu4x_GeneralCategoryNameToGroupMapper_get_strict_mv1(this.ffiValue, ...nameSlice.splat());
     61 
     62        try {
     63            return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result);
     64        }
     65 
     66        finally {
     67            functionCleanupArena.free();
     68 
     69        }
     70    }
     71 
     72    /**
     73     * Get the mask value matching the given name, using loose matching
     74     *
     75     * Returns 0 if the name is unknown for this property
     76     *
     77     * See the [Rust documentation for `get_loose`](https://docs.rs/icu/latest/icu/properties/struct.PropertyParserBorrowed.html#method.get_loose) for more information.
     78     */
     79    getLoose(name) {
     80        let functionCleanupArena = new diplomatRuntime.CleanupArena();
     81 
     82        const nameSlice = diplomatRuntime.DiplomatBuf.str8(wasm, name);
     83 
     84        const result = wasm.icu4x_GeneralCategoryNameToGroupMapper_get_loose_mv1(this.ffiValue, ...nameSlice.splat());
     85 
     86        try {
     87            return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result);
     88        }
     89 
     90        finally {
     91            functionCleanupArena.free();
     92 
     93        }
     94    }
     95 
     96    /**
     97     * Create a name-to-mask mapper for the `General_Category` property, using compiled data.
     98     *
     99     * See the [Rust documentation for `GeneralCategoryGroup`](https://docs.rs/icu/latest/icu/properties/props/struct.GeneralCategoryGroup.html) for more information.
    100     */
    101    #defaultConstructor() {
    102 
    103        const result = wasm.icu4x_GeneralCategoryNameToGroupMapper_create_mv1();
    104 
    105        try {
    106            return new GeneralCategoryNameToGroupMapper(diplomatRuntime.internalConstructor, result, []);
    107        }
    108 
    109        finally {
    110        }
    111    }
    112 
    113    /**
    114     * Create a name-to-mask mapper for the `General_Category` property, using a particular data source.
    115     *
    116     * See the [Rust documentation for `GeneralCategoryGroup`](https://docs.rs/icu/latest/icu/properties/props/struct.GeneralCategoryGroup.html) for more information.
    117     */
    118    static createWithProvider(provider) {
    119        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    120 
    121 
    122        const result = wasm.icu4x_GeneralCategoryNameToGroupMapper_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
    123 
    124        try {
    125            if (!diplomatReceive.resultFlag) {
    126                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    127                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    128            }
    129            return new GeneralCategoryNameToGroupMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    130        }
    131 
    132        finally {
    133            diplomatReceive.free();
    134        }
    135    }
    136 
    137    constructor() {
    138        if (arguments[0] === diplomatRuntime.exposeConstructor) {
    139            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
    140        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
    141            return this.#internalConstructor(...arguments);
    142        } else {
    143            return this.#defaultConstructor(...arguments);
    144        }
    145    }
    146 }