tor-browser

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

VariantOffsets.mjs (3512B)


      1 // generated by diplomat-tool
      2 import { UtcOffset } from "./UtcOffset.mjs"
      3 import wasm from "./diplomat-wasm.mjs";
      4 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      5 
      6 
      7 /**
      8 * See the [Rust documentation for `VariantOffsets`](https://docs.rs/icu/latest/icu/time/zone/struct.VariantOffsets.html) for more information.
      9 */
     10 
     11 
     12 export class VariantOffsets {
     13    #standard;
     14    get standard() {
     15        return this.#standard;
     16    }
     17    #daylight;
     18    get daylight() {
     19        return this.#daylight;
     20    }
     21    #internalConstructor(structObj, internalConstructor) {
     22        if (typeof structObj !== "object") {
     23            throw new Error("VariantOffsets's constructor takes an object of VariantOffsets's fields.");
     24        }
     25 
     26        if (internalConstructor !== diplomatRuntime.internalConstructor) {
     27            throw new Error("VariantOffsets is an out struct and can only be created internally.");
     28        }
     29        if ("standard" in structObj) {
     30            this.#standard = structObj.standard;
     31        } else {
     32            throw new Error("Missing required field standard.");
     33        }
     34 
     35        if ("daylight" in structObj) {
     36            this.#daylight = structObj.daylight;
     37        } else {
     38            throw new Error("Missing required field daylight.");
     39        }
     40 
     41        return this;
     42    }
     43 
     44    // Return this struct in FFI function friendly format.
     45    // Returns an array that can be expanded with spread syntax (...)
     46    _intoFFI(
     47        functionCleanupArena,
     48        appendArrayMap
     49    ) {
     50        return [this.#standard.ffiValue, this.#daylight.ffiValue ?? 0]
     51    }
     52 
     53    static _fromSuppliedValue(internalConstructor, obj) {
     54        if (internalConstructor !== diplomatRuntime.internalConstructor) {
     55            throw new Error("_fromSuppliedValue cannot be called externally.");
     56        }
     57 
     58        if (obj instanceof VariantOffsets) {
     59            return obj;
     60        }
     61 
     62        return VariantOffsets.fromFields(obj);
     63    }
     64 
     65    _writeToArrayBuffer(
     66        arrayBuffer,
     67        offset,
     68        functionCleanupArena,
     69        appendArrayMap
     70    ) {
     71        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#standard.ffiValue, Uint32Array);
     72        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#daylight.ffiValue ?? 0, Uint32Array);
     73    }
     74 
     75    // This struct contains borrowed fields, so this takes in a list of
     76    // "edges" corresponding to where each lifetime's data may have been borrowed from
     77    // and passes it down to individual fields containing the borrow.
     78    // This method does not attempt to handle any dependencies between lifetimes, the caller
     79    // should handle this when constructing edge arrays.
     80    static _fromFFI(internalConstructor, ptr) {
     81        if (internalConstructor !== diplomatRuntime.internalConstructor) {
     82            throw new Error("VariantOffsets._fromFFI is not meant to be called externally. Please use the default constructor.");
     83        }
     84        let structObj = {};
     85        const standardDeref = diplomatRuntime.ptrRead(wasm, ptr);
     86        structObj.standard = new UtcOffset(diplomatRuntime.internalConstructor, standardDeref, []);
     87        const daylightDeref = diplomatRuntime.ptrRead(wasm, ptr + 4);
     88        structObj.daylight = daylightDeref === 0 ? null : new UtcOffset(diplomatRuntime.internalConstructor, daylightDeref, []);
     89 
     90        return new VariantOffsets(structObj, internalConstructor);
     91    }
     92 
     93 
     94    constructor(structObj, internalConstructor) {
     95        return this.#internalConstructor(...arguments)
     96    }
     97 }