tor-browser

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

TimePrecision.mjs (5074B)


      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 `TimePrecision`](https://docs.rs/icu/latest/icu/datetime/options/enum.TimePrecision.html) for more information.
      8 *
      9 * See the [Rust documentation for `SubsecondDigits`](https://docs.rs/icu/latest/icu/datetime/options/enum.SubsecondDigits.html) for more information.
     10 */
     11 
     12 
     13 export class TimePrecision {
     14    #value = undefined;
     15 
     16    static #values = new Map([
     17        ["Hour", 0],
     18        ["Minute", 1],
     19        ["MinuteOptional", 2],
     20        ["Second", 3],
     21        ["Subsecond1", 4],
     22        ["Subsecond2", 5],
     23        ["Subsecond3", 6],
     24        ["Subsecond4", 7],
     25        ["Subsecond5", 8],
     26        ["Subsecond6", 9],
     27        ["Subsecond7", 10],
     28        ["Subsecond8", 11],
     29        ["Subsecond9", 12]
     30    ]);
     31 
     32    static getAllEntries() {
     33        return TimePrecision.#values.entries();
     34    }
     35 
     36    #internalConstructor(value) {
     37        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
     38            // We pass in two internalConstructor arguments to create *new*
     39            // instances of this type, otherwise the enums are treated as singletons.
     40            if (arguments[1] === diplomatRuntime.internalConstructor ) {
     41                this.#value = arguments[2];
     42                return this;
     43            }
     44            return TimePrecision.#objectValues[arguments[1]];
     45        }
     46 
     47        if (value instanceof TimePrecision) {
     48            return value;
     49        }
     50 
     51        let intVal = TimePrecision.#values.get(value);
     52 
     53        // Nullish check, checks for null or undefined
     54        if (intVal != null) {
     55            return TimePrecision.#objectValues[intVal];
     56        }
     57 
     58        throw TypeError(value + " is not a TimePrecision and does not correspond to any of its enumerator values.");
     59    }
     60 
     61    static fromValue(value) {
     62        return new TimePrecision(value);
     63    }
     64 
     65    get value(){
     66        return [...TimePrecision.#values.keys()][this.#value];
     67    }
     68 
     69    get ffiValue(){
     70        return this.#value;
     71    }
     72    static #objectValues = [
     73        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
     74        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
     75        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
     76        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
     77        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
     78        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
     79        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6),
     80        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7),
     81        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8),
     82        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 9),
     83        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 10),
     84        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 11),
     85        new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 12),
     86    ];
     87 
     88    static Hour = TimePrecision.#objectValues[0];
     89    static Minute = TimePrecision.#objectValues[1];
     90    static MinuteOptional = TimePrecision.#objectValues[2];
     91    static Second = TimePrecision.#objectValues[3];
     92    static Subsecond1 = TimePrecision.#objectValues[4];
     93    static Subsecond2 = TimePrecision.#objectValues[5];
     94    static Subsecond3 = TimePrecision.#objectValues[6];
     95    static Subsecond4 = TimePrecision.#objectValues[7];
     96    static Subsecond5 = TimePrecision.#objectValues[8];
     97    static Subsecond6 = TimePrecision.#objectValues[9];
     98    static Subsecond7 = TimePrecision.#objectValues[10];
     99    static Subsecond8 = TimePrecision.#objectValues[11];
    100    static Subsecond9 = TimePrecision.#objectValues[12];
    101 
    102 
    103    /**
    104     * See the [Rust documentation for `try_from_int`](https://docs.rs/icu/latest/icu/datetime/options/enum.SubsecondDigits.html#method.try_from_int) for more information.
    105     */
    106    static fromSubsecondDigits(digits) {
    107        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    108 
    109 
    110        const result = wasm.icu4x_TimePrecision_from_subsecond_digits_mv1(diplomatReceive.buffer, digits);
    111 
    112        try {
    113            if (!diplomatReceive.resultFlag) {
    114                return null;
    115            }
    116            return new TimePrecision(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    117        }
    118 
    119        finally {
    120            diplomatReceive.free();
    121        }
    122    }
    123 
    124    constructor(value) {
    125        return this.#internalConstructor(...arguments)
    126    }
    127 }