tor-browser

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

DecimalRoundingIncrement.mjs (2756B)


      1 // generated by diplomat-tool
      2 import wasm from "./diplomat-wasm.mjs";
      3 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      4 
      5 
      6 /**
      7 * Increment used in a rounding operation.
      8 *
      9 * See the [Rust documentation for `RoundingIncrement`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.RoundingIncrement.html) for more information.
     10 */
     11 
     12 
     13 export class DecimalRoundingIncrement {
     14    #value = undefined;
     15 
     16    static #values = new Map([
     17        ["MultiplesOf1", 0],
     18        ["MultiplesOf2", 1],
     19        ["MultiplesOf5", 2],
     20        ["MultiplesOf25", 3]
     21    ]);
     22 
     23    static getAllEntries() {
     24        return DecimalRoundingIncrement.#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 DecimalRoundingIncrement.#objectValues[arguments[1]];
     36        }
     37 
     38        if (value instanceof DecimalRoundingIncrement) {
     39            return value;
     40        }
     41 
     42        let intVal = DecimalRoundingIncrement.#values.get(value);
     43 
     44        // Nullish check, checks for null or undefined
     45        if (intVal != null) {
     46            return DecimalRoundingIncrement.#objectValues[intVal];
     47        }
     48 
     49        throw TypeError(value + " is not a DecimalRoundingIncrement and does not correspond to any of its enumerator values.");
     50    }
     51 
     52    static fromValue(value) {
     53        return new DecimalRoundingIncrement(value);
     54    }
     55 
     56    get value(){
     57        return [...DecimalRoundingIncrement.#values.keys()][this.#value];
     58    }
     59 
     60    get ffiValue(){
     61        return this.#value;
     62    }
     63    static #objectValues = [
     64        new DecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
     65        new DecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
     66        new DecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
     67        new DecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
     68    ];
     69 
     70    static MultiplesOf1 = DecimalRoundingIncrement.#objectValues[0];
     71    static MultiplesOf2 = DecimalRoundingIncrement.#objectValues[1];
     72    static MultiplesOf5 = DecimalRoundingIncrement.#objectValues[2];
     73    static MultiplesOf25 = DecimalRoundingIncrement.#objectValues[3];
     74 
     75 
     76    constructor(value) {
     77        return this.#internalConstructor(...arguments)
     78    }
     79 }