tor-browser

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

DateTimeWriteError.mjs (2408B)


      1 // generated by diplomat-tool
      2 import wasm from "./diplomat-wasm.mjs";
      3 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      4 
      5 
      6 /**
      7 * An error when formatting a datetime.
      8 *
      9 * Currently the only reachable error here is a missing time zone variant. If you encounter
     10 * that error, you need to call `with_variant` or `infer_variant` on your `TimeZoneInfo`.
     11 *
     12 * Additional information: [1](https://docs.rs/icu/latest/icu/datetime/unchecked/enum.FormattedDateTimeUncheckedError.html)
     13 */
     14 
     15 
     16 export class DateTimeWriteError {
     17    #value = undefined;
     18 
     19    static #values = new Map([
     20        ["Unknown", 0],
     21        ["MissingTimeZoneVariant", 1]
     22    ]);
     23 
     24    static getAllEntries() {
     25        return DateTimeWriteError.#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 DateTimeWriteError.#objectValues[arguments[1]];
     37        }
     38 
     39        if (value instanceof DateTimeWriteError) {
     40            return value;
     41        }
     42 
     43        let intVal = DateTimeWriteError.#values.get(value);
     44 
     45        // Nullish check, checks for null or undefined
     46        if (intVal != null) {
     47            return DateTimeWriteError.#objectValues[intVal];
     48        }
     49 
     50        throw TypeError(value + " is not a DateTimeWriteError and does not correspond to any of its enumerator values.");
     51    }
     52 
     53    static fromValue(value) {
     54        return new DateTimeWriteError(value);
     55    }
     56 
     57    get value(){
     58        return [...DateTimeWriteError.#values.keys()][this.#value];
     59    }
     60 
     61    get ffiValue(){
     62        return this.#value;
     63    }
     64    static #objectValues = [
     65        new DateTimeWriteError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
     66        new DateTimeWriteError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
     67    ];
     68 
     69    static Unknown = DateTimeWriteError.#objectValues[0];
     70    static MissingTimeZoneVariant = DateTimeWriteError.#objectValues[1];
     71 
     72 
     73    constructor(value) {
     74        return this.#internalConstructor(...arguments)
     75    }
     76 }