tor-browser

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

DisplayNamesStyle.mjs (2521B)


      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 `Style`](https://docs.rs/icu/latest/icu/experimental/displaynames/options/enum.Style.html) for more information.
      8 */
      9 
     10 
     11 export class DisplayNamesStyle {
     12    #value = undefined;
     13 
     14    static #values = new Map([
     15        ["Narrow", 0],
     16        ["Short", 1],
     17        ["Long", 2],
     18        ["Menu", 3]
     19    ]);
     20 
     21    static getAllEntries() {
     22        return DisplayNamesStyle.#values.entries();
     23    }
     24 
     25    #internalConstructor(value) {
     26        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
     27            // We pass in two internalConstructor arguments to create *new*
     28            // instances of this type, otherwise the enums are treated as singletons.
     29            if (arguments[1] === diplomatRuntime.internalConstructor ) {
     30                this.#value = arguments[2];
     31                return this;
     32            }
     33            return DisplayNamesStyle.#objectValues[arguments[1]];
     34        }
     35 
     36        if (value instanceof DisplayNamesStyle) {
     37            return value;
     38        }
     39 
     40        let intVal = DisplayNamesStyle.#values.get(value);
     41 
     42        // Nullish check, checks for null or undefined
     43        if (intVal != null) {
     44            return DisplayNamesStyle.#objectValues[intVal];
     45        }
     46 
     47        throw TypeError(value + " is not a DisplayNamesStyle and does not correspond to any of its enumerator values.");
     48    }
     49 
     50    static fromValue(value) {
     51        return new DisplayNamesStyle(value);
     52    }
     53 
     54    get value(){
     55        return [...DisplayNamesStyle.#values.keys()][this.#value];
     56    }
     57 
     58    get ffiValue(){
     59        return this.#value;
     60    }
     61    static #objectValues = [
     62        new DisplayNamesStyle(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
     63        new DisplayNamesStyle(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
     64        new DisplayNamesStyle(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
     65        new DisplayNamesStyle(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
     66    ];
     67 
     68    static Narrow = DisplayNamesStyle.#objectValues[0];
     69    static Short = DisplayNamesStyle.#objectValues[1];
     70    static Long = DisplayNamesStyle.#objectValues[2];
     71    static Menu = DisplayNamesStyle.#objectValues[3];
     72 
     73 
     74    constructor(value) {
     75        return this.#internalConstructor(...arguments)
     76    }
     77 }