tor-browser

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

EastAsianWidth.mjs (6175B)


      1 // generated by diplomat-tool
      2 import wasm from "./diplomat-wasm.mjs";
      3 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      4 
      5 
      6 /**
      7 * See the [Rust documentation for `EastAsianWidth`](https://docs.rs/icu/latest/icu/properties/props/struct.EastAsianWidth.html) for more information.
      8 */
      9 
     10 
     11 export class EastAsianWidth {
     12    #value = undefined;
     13 
     14    static #values = new Map([
     15        ["Neutral", 0],
     16        ["Ambiguous", 1],
     17        ["Halfwidth", 2],
     18        ["Fullwidth", 3],
     19        ["Narrow", 4],
     20        ["Wide", 5]
     21    ]);
     22 
     23    static getAllEntries() {
     24        return EastAsianWidth.#values.entries();
     25    }
     26 
     27    #internalConstructor(value) {
     28        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
     29            // We pass in two internalConstructor arguments to create *new*
     30            // instances of this type, otherwise the enums are treated as singletons.
     31            if (arguments[1] === diplomatRuntime.internalConstructor ) {
     32                this.#value = arguments[2];
     33                return this;
     34            }
     35            return EastAsianWidth.#objectValues[arguments[1]];
     36        }
     37 
     38        if (value instanceof EastAsianWidth) {
     39            return value;
     40        }
     41 
     42        let intVal = EastAsianWidth.#values.get(value);
     43 
     44        // Nullish check, checks for null or undefined
     45        if (intVal != null) {
     46            return EastAsianWidth.#objectValues[intVal];
     47        }
     48 
     49        throw TypeError(value + " is not a EastAsianWidth and does not correspond to any of its enumerator values.");
     50    }
     51 
     52    static fromValue(value) {
     53        return new EastAsianWidth(value);
     54    }
     55 
     56    get value(){
     57        return [...EastAsianWidth.#values.keys()][this.#value];
     58    }
     59 
     60    get ffiValue(){
     61        return this.#value;
     62    }
     63    static #objectValues = [
     64        new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
     65        new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
     66        new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
     67        new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
     68        new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
     69        new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
     70    ];
     71 
     72    static Neutral = EastAsianWidth.#objectValues[0];
     73    static Ambiguous = EastAsianWidth.#objectValues[1];
     74    static Halfwidth = EastAsianWidth.#objectValues[2];
     75    static Fullwidth = EastAsianWidth.#objectValues[3];
     76    static Narrow = EastAsianWidth.#objectValues[4];
     77    static Wide = EastAsianWidth.#objectValues[5];
     78 
     79 
     80    /**
     81     * See the [Rust documentation for `for_char`](https://docs.rs/icu/latest/icu/properties/props/trait.EnumeratedProperty.html#tymethod.for_char) for more information.
     82     */
     83    static forChar(ch) {
     84 
     85        const result = wasm.icu4x_EastAsianWidth_for_char_mv1(ch);
     86 
     87        try {
     88            return new EastAsianWidth(diplomatRuntime.internalConstructor, result);
     89        }
     90 
     91        finally {
     92        }
     93    }
     94 
     95    /**
     96     * Get the "long" name of this property value (returns empty if property value is unknown)
     97     *
     98     * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/properties/struct.PropertyNamesLongBorrowed.html#method.get) for more information.
     99     */
    100    longName() {
    101        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
    102 
    103 
    104        const result = wasm.icu4x_EastAsianWidth_long_name_mv1(diplomatReceive.buffer, this.ffiValue);
    105 
    106        try {
    107            if (!diplomatReceive.resultFlag) {
    108                return null;
    109            }
    110            return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer,  "string8", []).getValue();
    111        }
    112 
    113        finally {
    114            diplomatReceive.free();
    115        }
    116    }
    117 
    118    /**
    119     * Get the "short" name of this property value (returns empty if property value is unknown)
    120     *
    121     * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/properties/struct.PropertyNamesShortBorrowed.html#method.get) for more information.
    122     */
    123    shortName() {
    124        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
    125 
    126 
    127        const result = wasm.icu4x_EastAsianWidth_short_name_mv1(diplomatReceive.buffer, this.ffiValue);
    128 
    129        try {
    130            if (!diplomatReceive.resultFlag) {
    131                return null;
    132            }
    133            return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer,  "string8", []).getValue();
    134        }
    135 
    136        finally {
    137            diplomatReceive.free();
    138        }
    139    }
    140 
    141    /**
    142     * Convert to an integer value usable with ICU4C and CodePointMapData
    143     *
    144     * See the [Rust documentation for `to_icu4c_value`](https://docs.rs/icu/latest/icu/properties/props/struct.EastAsianWidth.html#method.to_icu4c_value) for more information.
    145     */
    146    toIntegerValue() {
    147 
    148        const result = wasm.icu4x_EastAsianWidth_to_integer_value_mv1(this.ffiValue);
    149 
    150        try {
    151            return result;
    152        }
    153 
    154        finally {
    155        }
    156    }
    157 
    158    /**
    159     * Convert from an integer value from ICU4C or CodePointMapData
    160     *
    161     * See the [Rust documentation for `from_icu4c_value`](https://docs.rs/icu/latest/icu/properties/props/struct.EastAsianWidth.html#method.from_icu4c_value) for more information.
    162     */
    163    static fromIntegerValue(other) {
    164        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    165 
    166 
    167        const result = wasm.icu4x_EastAsianWidth_from_integer_value_mv1(diplomatReceive.buffer, other);
    168 
    169        try {
    170            if (!diplomatReceive.resultFlag) {
    171                return null;
    172            }
    173            return new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    174        }
    175 
    176        finally {
    177            diplomatReceive.free();
    178        }
    179    }
    180 
    181    constructor(value) {
    182        return this.#internalConstructor(...arguments)
    183    }
    184 }