tor-browser

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

IsoWeekOfYear.mjs (3845B)


      1 // generated by diplomat-tool
      2 import wasm from "./diplomat-wasm.mjs";
      3 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      4 
      5 
      6 
      7 export class IsoWeekOfYear {
      8    #weekNumber;
      9    get weekNumber() {
     10        return this.#weekNumber;
     11    }
     12    set weekNumber(value){
     13        this.#weekNumber = value;
     14    }
     15    #isoYear;
     16    get isoYear() {
     17        return this.#isoYear;
     18    }
     19    set isoYear(value){
     20        this.#isoYear = value;
     21    }
     22    /** Create `IsoWeekOfYear` from an object that contains all of `IsoWeekOfYear`s fields.
     23    * Optional fields do not need to be included in the provided object.
     24    */
     25    static fromFields(structObj) {
     26        return new IsoWeekOfYear(structObj);
     27    }
     28 
     29    #internalConstructor(structObj) {
     30        if (typeof structObj !== "object") {
     31            throw new Error("IsoWeekOfYear's constructor takes an object of IsoWeekOfYear's fields.");
     32        }
     33 
     34        if ("weekNumber" in structObj) {
     35            this.#weekNumber = structObj.weekNumber;
     36        } else {
     37            throw new Error("Missing required field weekNumber.");
     38        }
     39 
     40        if ("isoYear" in structObj) {
     41            this.#isoYear = structObj.isoYear;
     42        } else {
     43            throw new Error("Missing required field isoYear.");
     44        }
     45 
     46        return this;
     47    }
     48 
     49    // Return this struct in FFI function friendly format.
     50    // Returns an array that can be expanded with spread syntax (...)
     51    // JS structs need to be generated with or without padding depending on whether they are being passed as aggregates or splatted out into fields.
     52    // Most of the time this is known beforehand: large structs (>2 scalar fields) always get padding, and structs passed directly in parameters omit padding
     53    // if they are small. However small structs within large structs also get padding, and we signal that by setting forcePadding.
     54    _intoFFI(
     55        functionCleanupArena,
     56        appendArrayMap,
     57        forcePadding
     58    ) {
     59        return [this.#weekNumber, ...diplomatRuntime.maybePaddingFields(forcePadding, 3 /* x i8 */), this.#isoYear]
     60    }
     61 
     62    static _fromSuppliedValue(internalConstructor, obj) {
     63        if (internalConstructor !== diplomatRuntime.internalConstructor) {
     64            throw new Error("_fromSuppliedValue cannot be called externally.");
     65        }
     66 
     67        if (obj instanceof IsoWeekOfYear) {
     68            return obj;
     69        }
     70 
     71        return IsoWeekOfYear.fromFields(obj);
     72    }
     73 
     74    _writeToArrayBuffer(
     75        arrayBuffer,
     76        offset,
     77        functionCleanupArena,
     78        appendArrayMap,
     79        forcePadding
     80    ) {
     81        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#weekNumber, Uint8Array);
     82        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#isoYear, Int32Array);
     83    }
     84 
     85    // This struct contains borrowed fields, so this takes in a list of
     86    // "edges" corresponding to where each lifetime's data may have been borrowed from
     87    // and passes it down to individual fields containing the borrow.
     88    // This method does not attempt to handle any dependencies between lifetimes, the caller
     89    // should handle this when constructing edge arrays.
     90    static _fromFFI(internalConstructor, ptr) {
     91        if (internalConstructor !== diplomatRuntime.internalConstructor) {
     92            throw new Error("IsoWeekOfYear._fromFFI is not meant to be called externally. Please use the default constructor.");
     93        }
     94        let structObj = {};
     95        const weekNumberDeref = (new Uint8Array(wasm.memory.buffer, ptr, 1))[0];
     96        structObj.weekNumber = weekNumberDeref;
     97        const isoYearDeref = (new Int32Array(wasm.memory.buffer, ptr + 4, 1))[0];
     98        structObj.isoYear = isoYearDeref;
     99 
    100        return new IsoWeekOfYear(structObj);
    101    }
    102 
    103 
    104    constructor(structObj) {
    105        return this.#internalConstructor(...arguments)
    106    }
    107 }