tor-browser

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

CaseMapCloser.mjs (5112B)


      1 // generated by diplomat-tool
      2 import { CodePointSetBuilder } from "./CodePointSetBuilder.mjs"
      3 import { DataError } from "./DataError.mjs"
      4 import { DataProvider } from "./DataProvider.mjs"
      5 import wasm from "./diplomat-wasm.mjs";
      6 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      7 
      8 
      9 /**
     10 * See the [Rust documentation for `CaseMapCloser`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html) for more information.
     11 */
     12 const CaseMapCloser_box_destroy_registry = new FinalizationRegistry((ptr) => {
     13    wasm.icu4x_CaseMapCloser_destroy_mv1(ptr);
     14 });
     15 
     16 export class CaseMapCloser {
     17    // Internal ptr reference:
     18    #ptr = null;
     19 
     20    // Lifetimes are only to keep dependencies alive.
     21    // Since JS won't garbage collect until there are no incoming edges.
     22    #selfEdge = [];
     23 
     24    #internalConstructor(symbol, ptr, selfEdge) {
     25        if (symbol !== diplomatRuntime.internalConstructor) {
     26            console.error("CaseMapCloser is an Opaque type. You cannot call its constructor.");
     27            return;
     28        }
     29        this.#ptr = ptr;
     30        this.#selfEdge = selfEdge;
     31 
     32        // Are we being borrowed? If not, we can register.
     33        if (this.#selfEdge.length === 0) {
     34            CaseMapCloser_box_destroy_registry.register(this, this.#ptr);
     35        }
     36 
     37        return this;
     38    }
     39    get ffiValue() {
     40        return this.#ptr;
     41    }
     42 
     43 
     44    /**
     45     * Construct a new CaseMapCloser instance using compiled data.
     46     *
     47     * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html#method.new) for more information.
     48     */
     49    #defaultConstructor() {
     50        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     51 
     52 
     53        const result = wasm.icu4x_CaseMapCloser_create_mv1(diplomatReceive.buffer);
     54 
     55        try {
     56            if (!diplomatReceive.resultFlag) {
     57                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     58                throw new globalThis.Error('DataError: ' + cause.value, { cause });
     59            }
     60            return new CaseMapCloser(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     61        }
     62 
     63        finally {
     64            diplomatReceive.free();
     65        }
     66    }
     67 
     68    /**
     69     * Construct a new CaseMapCloser instance using a particular data source.
     70     *
     71     * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html#method.new) for more information.
     72     */
     73    static createWithProvider(provider) {
     74        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     75 
     76 
     77        const result = wasm.icu4x_CaseMapCloser_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
     78 
     79        try {
     80            if (!diplomatReceive.resultFlag) {
     81                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     82                throw new globalThis.Error('DataError: ' + cause.value, { cause });
     83            }
     84            return new CaseMapCloser(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     85        }
     86 
     87        finally {
     88            diplomatReceive.free();
     89        }
     90    }
     91 
     92    /**
     93     * Adds all simple case mappings and the full case folding for `c` to `builder`.
     94     * Also adds special case closure mappings.
     95     *
     96     * See the [Rust documentation for `add_case_closure_to`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloserBorrowed.html#method.add_case_closure_to) for more information.
     97     */
     98    addCaseClosureTo(c, builder) {
     99    wasm.icu4x_CaseMapCloser_add_case_closure_to_mv1(this.ffiValue, c, builder.ffiValue);
    100 
    101        try {}
    102 
    103        finally {
    104        }
    105    }
    106 
    107    /**
    108     * Finds all characters and strings which may casemap to `s` as their full case folding string
    109     * and adds them to the set.
    110     *
    111     * Returns true if the string was found
    112     *
    113     * See the [Rust documentation for `add_string_case_closure_to`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloserBorrowed.html#method.add_string_case_closure_to) for more information.
    114     */
    115    addStringCaseClosureTo(s, builder) {
    116        let functionCleanupArena = new diplomatRuntime.CleanupArena();
    117 
    118        const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s);
    119 
    120        const result = wasm.icu4x_CaseMapCloser_add_string_case_closure_to_mv1(this.ffiValue, ...sSlice.splat(), builder.ffiValue);
    121 
    122        try {
    123            return result;
    124        }
    125 
    126        finally {
    127            functionCleanupArena.free();
    128 
    129        }
    130    }
    131 
    132    constructor() {
    133        if (arguments[0] === diplomatRuntime.exposeConstructor) {
    134            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
    135        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
    136            return this.#internalConstructor(...arguments);
    137        } else {
    138            return this.#defaultConstructor(...arguments);
    139        }
    140    }
    141 }