tor-browser

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

VariantOffsetsCalculator.mjs (4486B)


      1 // generated by diplomat-tool
      2 import { DataError } from "./DataError.mjs"
      3 import { DataProvider } from "./DataProvider.mjs"
      4 import { IsoDate } from "./IsoDate.mjs"
      5 import { Time } from "./Time.mjs"
      6 import { TimeZone } from "./TimeZone.mjs"
      7 import { VariantOffsets } from "./VariantOffsets.mjs"
      8 import wasm from "./diplomat-wasm.mjs";
      9 import * as diplomatRuntime from "./diplomat-runtime.mjs";
     10 
     11 
     12 /**
     13 * See the [Rust documentation for `VariantOffsetsCalculator`](https://docs.rs/icu/latest/icu/time/zone/struct.VariantOffsetsCalculator.html) for more information.
     14 */
     15 const VariantOffsetsCalculator_box_destroy_registry = new FinalizationRegistry((ptr) => {
     16    wasm.icu4x_VariantOffsetsCalculator_destroy_mv1(ptr);
     17 });
     18 
     19 export class VariantOffsetsCalculator {
     20    // Internal ptr reference:
     21    #ptr = null;
     22 
     23    // Lifetimes are only to keep dependencies alive.
     24    // Since JS won't garbage collect until there are no incoming edges.
     25    #selfEdge = [];
     26 
     27    #internalConstructor(symbol, ptr, selfEdge) {
     28        if (symbol !== diplomatRuntime.internalConstructor) {
     29            console.error("VariantOffsetsCalculator is an Opaque type. You cannot call its constructor.");
     30            return;
     31        }
     32        this.#ptr = ptr;
     33        this.#selfEdge = selfEdge;
     34 
     35        // Are we being borrowed? If not, we can register.
     36        if (this.#selfEdge.length === 0) {
     37            VariantOffsetsCalculator_box_destroy_registry.register(this, this.#ptr);
     38        }
     39 
     40        return this;
     41    }
     42    get ffiValue() {
     43        return this.#ptr;
     44    }
     45 
     46 
     47    /**
     48     * Construct a new [`VariantOffsetsCalculator`] instance using compiled data.
     49     *
     50     * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/time/zone/struct.VariantOffsetsCalculator.html#method.new) for more information.
     51     */
     52    #defaultConstructor() {
     53 
     54        const result = wasm.icu4x_VariantOffsetsCalculator_create_mv1();
     55 
     56        try {
     57            return new VariantOffsetsCalculator(diplomatRuntime.internalConstructor, result, []);
     58        }
     59 
     60        finally {
     61        }
     62    }
     63 
     64    /**
     65     * Construct a new [`VariantOffsetsCalculator`] instance using a particular data source.
     66     *
     67     * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/time/zone/struct.VariantOffsetsCalculator.html#method.new) for more information.
     68     */
     69    static createWithProvider(provider) {
     70        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     71 
     72 
     73        const result = wasm.icu4x_VariantOffsetsCalculator_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
     74 
     75        try {
     76            if (!diplomatReceive.resultFlag) {
     77                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     78                throw new globalThis.Error('DataError: ' + cause.value, { cause });
     79            }
     80            return new VariantOffsetsCalculator(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     81        }
     82 
     83        finally {
     84            diplomatReceive.free();
     85        }
     86    }
     87 
     88    /**
     89     * See the [Rust documentation for `compute_offsets_from_time_zone_and_name_timestamp`](https://docs.rs/icu/latest/icu/time/zone/struct.VariantOffsetsCalculatorBorrowed.html#method.compute_offsets_from_time_zone_and_name_timestamp) for more information.
     90     */
     91    computeOffsetsFromTimeZoneAndDateTime(timeZone, localDate, localTime) {
     92        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
     93 
     94 
     95        const result = wasm.icu4x_VariantOffsetsCalculator_compute_offsets_from_time_zone_and_date_time_mv1(diplomatReceive.buffer, this.ffiValue, timeZone.ffiValue, localDate.ffiValue, localTime.ffiValue);
     96 
     97        try {
     98            if (!diplomatReceive.resultFlag) {
     99                return null;
    100            }
    101            return VariantOffsets._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer);
    102        }
    103 
    104        finally {
    105            diplomatReceive.free();
    106        }
    107    }
    108 
    109    constructor() {
    110        if (arguments[0] === diplomatRuntime.exposeConstructor) {
    111            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
    112        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
    113            return this.#internalConstructor(...arguments);
    114        } else {
    115            return this.#defaultConstructor(...arguments);
    116        }
    117    }
    118 }