tor-browser

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

DecimalSign.mjs (2295B)


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