tor-browser

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

ScriptWithExtensions.mjs (5989B)


      1 // generated by diplomat-tool
      2 import { CodePointRangeIterator } from "./CodePointRangeIterator.mjs"
      3 import { DataError } from "./DataError.mjs"
      4 import { DataProvider } from "./DataProvider.mjs"
      5 import { ScriptWithExtensionsBorrowed } from "./ScriptWithExtensionsBorrowed.mjs"
      6 import wasm from "./diplomat-wasm.mjs";
      7 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      8 
      9 
     10 /**
     11 * An ICU4X ScriptWithExtensions map object, capable of holding a map of codepoints to scriptextensions values
     12 *
     13 * See the [Rust documentation for `ScriptWithExtensions`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html) for more information.
     14 */
     15 const ScriptWithExtensions_box_destroy_registry = new FinalizationRegistry((ptr) => {
     16    wasm.icu4x_ScriptWithExtensions_destroy_mv1(ptr);
     17 });
     18 
     19 export class ScriptWithExtensions {
     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("ScriptWithExtensions 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            ScriptWithExtensions_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 map for the `Script`/`Script_Extensions` properties, using compiled data.
     49     *
     50     * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html#method.new) for more information.
     51     */
     52    #defaultConstructor() {
     53 
     54        const result = wasm.icu4x_ScriptWithExtensions_create_mv1();
     55 
     56        try {
     57            return new ScriptWithExtensions(diplomatRuntime.internalConstructor, result, []);
     58        }
     59 
     60        finally {
     61        }
     62    }
     63 
     64    /**
     65     * Create a map for the `Script`/`Script_Extensions` properties, using compiled data.
     66     *
     67     * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html#method.new) for more information.
     68     */
     69    static createWithProvider(provider) {
     70        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     71 
     72 
     73        const result = wasm.icu4x_ScriptWithExtensions_create_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 ScriptWithExtensions(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     81        }
     82 
     83        finally {
     84            diplomatReceive.free();
     85        }
     86    }
     87 
     88    /**
     89     * Get the Script property value for a code point
     90     *
     91     * See the [Rust documentation for `get_script_val`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_val) for more information.
     92     */
     93    getScriptVal(ch) {
     94 
     95        const result = wasm.icu4x_ScriptWithExtensions_get_script_val_mv1(this.ffiValue, ch);
     96 
     97        try {
     98            return result;
     99        }
    100 
    101        finally {
    102        }
    103    }
    104 
    105    /**
    106     * Check if the Script_Extensions property of the given code point covers the given script
    107     *
    108     * See the [Rust documentation for `has_script`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.has_script) for more information.
    109     */
    110    hasScript(ch, script) {
    111 
    112        const result = wasm.icu4x_ScriptWithExtensions_has_script_mv1(this.ffiValue, ch, script);
    113 
    114        try {
    115            return result;
    116        }
    117 
    118        finally {
    119        }
    120    }
    121 
    122    /**
    123     * Borrow this object for a slightly faster variant with more operations
    124     *
    125     * See the [Rust documentation for `as_borrowed`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html#method.as_borrowed) for more information.
    126     */
    127    get asBorrowed() {
    128        // This lifetime edge depends on lifetimes 'a
    129        let aEdges = [this];
    130 
    131 
    132        const result = wasm.icu4x_ScriptWithExtensions_as_borrowed_mv1(this.ffiValue);
    133 
    134        try {
    135            return new ScriptWithExtensionsBorrowed(diplomatRuntime.internalConstructor, result, [], aEdges);
    136        }
    137 
    138        finally {
    139        }
    140    }
    141 
    142    /**
    143     * Get a list of ranges of code points that contain this script in their Script_Extensions values
    144     *
    145     * See the [Rust documentation for `get_script_extensions_ranges`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_extensions_ranges) for more information.
    146     */
    147    iterRangesForScript(script) {
    148        // This lifetime edge depends on lifetimes 'a
    149        let aEdges = [this];
    150 
    151 
    152        const result = wasm.icu4x_ScriptWithExtensions_iter_ranges_for_script_mv1(this.ffiValue, script);
    153 
    154        try {
    155            return new CodePointRangeIterator(diplomatRuntime.internalConstructor, result, [], aEdges);
    156        }
    157 
    158        finally {
    159        }
    160    }
    161 
    162    constructor() {
    163        if (arguments[0] === diplomatRuntime.exposeConstructor) {
    164            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
    165        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
    166            return this.#internalConstructor(...arguments);
    167        } else {
    168            return this.#defaultConstructor(...arguments);
    169        }
    170    }
    171 }