tor-browser

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

DecimalSignDisplay.mjs (2792B)


      1 // generated by diplomat-tool
      2 import wasm from "./diplomat-wasm.mjs";
      3 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      4 
      5 
      6 /**
      7 * ECMA-402 compatible sign display preference.
      8 *
      9 * See the [Rust documentation for `SignDisplay`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.SignDisplay.html) for more information.
     10 */
     11 
     12 
     13 export class DecimalSignDisplay {
     14    #value = undefined;
     15 
     16    static #values = new Map([
     17        ["Auto", 0],
     18        ["Never", 1],
     19        ["Always", 2],
     20        ["ExceptZero", 3],
     21        ["Negative", 4]
     22    ]);
     23 
     24    static getAllEntries() {
     25        return DecimalSignDisplay.#values.entries();
     26    }
     27 
     28    #internalConstructor(value) {
     29        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
     30            // We pass in two internalConstructor arguments to create *new*
     31            // instances of this type, otherwise the enums are treated as singletons.
     32            if (arguments[1] === diplomatRuntime.internalConstructor ) {
     33                this.#value = arguments[2];
     34                return this;
     35            }
     36            return DecimalSignDisplay.#objectValues[arguments[1]];
     37        }
     38 
     39        if (value instanceof DecimalSignDisplay) {
     40            return value;
     41        }
     42 
     43        let intVal = DecimalSignDisplay.#values.get(value);
     44 
     45        // Nullish check, checks for null or undefined
     46        if (intVal != null) {
     47            return DecimalSignDisplay.#objectValues[intVal];
     48        }
     49 
     50        throw TypeError(value + " is not a DecimalSignDisplay and does not correspond to any of its enumerator values.");
     51    }
     52 
     53    static fromValue(value) {
     54        return new DecimalSignDisplay(value);
     55    }
     56 
     57    get value(){
     58        return [...DecimalSignDisplay.#values.keys()][this.#value];
     59    }
     60 
     61    get ffiValue(){
     62        return this.#value;
     63    }
     64    static #objectValues = [
     65        new DecimalSignDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
     66        new DecimalSignDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
     67        new DecimalSignDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
     68        new DecimalSignDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
     69        new DecimalSignDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
     70    ];
     71 
     72    static Auto = DecimalSignDisplay.#objectValues[0];
     73    static Never = DecimalSignDisplay.#objectValues[1];
     74    static Always = DecimalSignDisplay.#objectValues[2];
     75    static ExceptZero = DecimalSignDisplay.#objectValues[3];
     76    static Negative = DecimalSignDisplay.#objectValues[4];
     77 
     78 
     79    constructor(value) {
     80        return this.#internalConstructor(...arguments)
     81    }
     82 }