tor-browser

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

WeekInformation.mjs (5563B)


      1 // generated by diplomat-tool
      2 import { DataError } from "./DataError.mjs"
      3 import { DataProvider } from "./DataProvider.mjs"
      4 import { Locale } from "./Locale.mjs"
      5 import { Weekday } from "./Weekday.mjs"
      6 import { WeekdaySetIterator } from "./WeekdaySetIterator.mjs"
      7 import wasm from "./diplomat-wasm.mjs";
      8 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      9 
     10 
     11 /**
     12 * A Week calculator, useful to be passed in to `week_of_year()` on Date and DateTime types
     13 *
     14 * See the [Rust documentation for `WeekInformation`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekInformation.html) for more information.
     15 */
     16 const WeekInformation_box_destroy_registry = new FinalizationRegistry((ptr) => {
     17    wasm.icu4x_WeekInformation_destroy_mv1(ptr);
     18 });
     19 
     20 export class WeekInformation {
     21    // Internal ptr reference:
     22    #ptr = null;
     23 
     24    // Lifetimes are only to keep dependencies alive.
     25    // Since JS won't garbage collect until there are no incoming edges.
     26    #selfEdge = [];
     27 
     28    #internalConstructor(symbol, ptr, selfEdge) {
     29        if (symbol !== diplomatRuntime.internalConstructor) {
     30            console.error("WeekInformation is an Opaque type. You cannot call its constructor.");
     31            return;
     32        }
     33        this.#ptr = ptr;
     34        this.#selfEdge = selfEdge;
     35 
     36        // Are we being borrowed? If not, we can register.
     37        if (this.#selfEdge.length === 0) {
     38            WeekInformation_box_destroy_registry.register(this, this.#ptr);
     39        }
     40 
     41        return this;
     42    }
     43    get ffiValue() {
     44        return this.#ptr;
     45    }
     46 
     47 
     48    /**
     49     * Creates a new [`WeekInformation`] from locale data using compiled data.
     50     *
     51     * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekInformation.html#method.try_new) for more information.
     52     */
     53    #defaultConstructor(locale) {
     54        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     55 
     56 
     57        const result = wasm.icu4x_WeekInformation_create_mv1(diplomatReceive.buffer, locale.ffiValue);
     58 
     59        try {
     60            if (!diplomatReceive.resultFlag) {
     61                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     62                throw new globalThis.Error('DataError: ' + cause.value, { cause });
     63            }
     64            return new WeekInformation(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     65        }
     66 
     67        finally {
     68            diplomatReceive.free();
     69        }
     70    }
     71 
     72    /**
     73     * Creates a new [`WeekInformation`] from locale data using a particular data source.
     74     *
     75     * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekInformation.html#method.try_new) for more information.
     76     */
     77    static createWithProvider(provider, locale) {
     78        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     79 
     80 
     81        const result = wasm.icu4x_WeekInformation_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
     82 
     83        try {
     84            if (!diplomatReceive.resultFlag) {
     85                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     86                throw new globalThis.Error('DataError: ' + cause.value, { cause });
     87            }
     88            return new WeekInformation(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     89        }
     90 
     91        finally {
     92            diplomatReceive.free();
     93        }
     94    }
     95 
     96    /**
     97     * Returns the weekday that starts the week for this object's locale
     98     *
     99     * See the [Rust documentation for `first_weekday`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekInformation.html#structfield.first_weekday) for more information.
    100     */
    101    get firstWeekday() {
    102 
    103        const result = wasm.icu4x_WeekInformation_first_weekday_mv1(this.ffiValue);
    104 
    105        try {
    106            return new Weekday(diplomatRuntime.internalConstructor, result);
    107        }
    108 
    109        finally {
    110        }
    111    }
    112 
    113    /**
    114     * See the [Rust documentation for `weekend`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekInformation.html#structfield.weekend) for more information.
    115     *
    116     * See the [Rust documentation for `contains`](https://docs.rs/icu/latest/icu/calendar/provider/struct.WeekdaySet.html#method.contains) for more information.
    117     */
    118    isWeekend(day) {
    119 
    120        const result = wasm.icu4x_WeekInformation_is_weekend_mv1(this.ffiValue, day.ffiValue);
    121 
    122        try {
    123            return result;
    124        }
    125 
    126        finally {
    127        }
    128    }
    129 
    130    /**
    131     * See the [Rust documentation for `weekend`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekInformation.html#method.weekend) for more information.
    132     */
    133    get weekend() {
    134 
    135        const result = wasm.icu4x_WeekInformation_weekend_mv1(this.ffiValue);
    136 
    137        try {
    138            return new WeekdaySetIterator(diplomatRuntime.internalConstructor, result, []);
    139        }
    140 
    141        finally {
    142        }
    143    }
    144 
    145    constructor(locale) {
    146        if (arguments[0] === diplomatRuntime.exposeConstructor) {
    147            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
    148        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
    149            return this.#internalConstructor(...arguments);
    150        } else {
    151            return this.#defaultConstructor(...arguments);
    152        }
    153    }
    154 }