tor-browser

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

TimeZoneAndCanonicalAndNormalized.mjs (5070B)


      1 // generated by diplomat-tool
      2 import { TimeZone } from "./TimeZone.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 `TimeZoneAndCanonicalAndNormalized`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalAndNormalized.html) for more information.
      9 */
     10 
     11 
     12 export class TimeZoneAndCanonicalAndNormalized {
     13    #timeZone;
     14    get timeZone() {
     15        return this.#timeZone;
     16    }
     17    #canonical;
     18    get canonical() {
     19        return this.#canonical;
     20    }
     21    #normalized;
     22    get normalized() {
     23        return this.#normalized;
     24    }
     25    #internalConstructor(structObj, internalConstructor) {
     26        if (typeof structObj !== "object") {
     27            throw new Error("TimeZoneAndCanonicalAndNormalized's constructor takes an object of TimeZoneAndCanonicalAndNormalized's fields.");
     28        }
     29 
     30        if (internalConstructor !== diplomatRuntime.internalConstructor) {
     31            throw new Error("TimeZoneAndCanonicalAndNormalized is an out struct and can only be created internally.");
     32        }
     33        if ("timeZone" in structObj) {
     34            this.#timeZone = structObj.timeZone;
     35        } else {
     36            throw new Error("Missing required field timeZone.");
     37        }
     38 
     39        if ("canonical" in structObj) {
     40            this.#canonical = structObj.canonical;
     41        } else {
     42            throw new Error("Missing required field canonical.");
     43        }
     44 
     45        if ("normalized" in structObj) {
     46            this.#normalized = structObj.normalized;
     47        } else {
     48            throw new Error("Missing required field normalized.");
     49        }
     50 
     51        return this;
     52    }
     53 
     54    // Return this struct in FFI function friendly format.
     55    // Returns an array that can be expanded with spread syntax (...)// If this struct contains any slices, their lifetime-edge-relevant information will be
     56    // set up here, and can be appended to any relevant lifetime arrays here. <lifetime>AppendArray accepts a list
     57    // of arrays for each lifetime to do so. It accepts multiple lists per lifetime in case the caller needs to tie a lifetime to multiple
     58    // output arrays. Null is equivalent to an empty list: this lifetime is not being borrowed from.
     59    _intoFFI(
     60        functionCleanupArena,
     61        appendArrayMap
     62    ) {
     63        return [this.#timeZone.ffiValue, ...diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical).splat(), ...diplomatRuntime.DiplomatBuf.str8(wasm, this.#normalized).splat()]
     64    }
     65 
     66    static _fromSuppliedValue(internalConstructor, obj) {
     67        if (internalConstructor !== diplomatRuntime.internalConstructor) {
     68            throw new Error("_fromSuppliedValue cannot be called externally.");
     69        }
     70 
     71        if (obj instanceof TimeZoneAndCanonicalAndNormalized) {
     72            return obj;
     73        }
     74 
     75        return TimeZoneAndCanonicalAndNormalized.fromFields(obj);
     76    }
     77 
     78    _writeToArrayBuffer(
     79        arrayBuffer,
     80        offset,
     81        functionCleanupArena,
     82        appendArrayMap
     83    ) {
     84        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#timeZone.ffiValue, Uint32Array);
     85        diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical)).writePtrLenToArrayBuffer(arrayBuffer, offset + 4);
     86        diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#normalized)).writePtrLenToArrayBuffer(arrayBuffer, offset + 12);
     87    }
     88 
     89    static _fromFFI(internalConstructor, ptr, aEdges) {
     90        if (internalConstructor !== diplomatRuntime.internalConstructor) {
     91            throw new Error("TimeZoneAndCanonicalAndNormalized._fromFFI is not meant to be called externally. Please use the default constructor.");
     92        }
     93        let structObj = {};
     94        const timeZoneDeref = diplomatRuntime.ptrRead(wasm, ptr);
     95        structObj.timeZone = new TimeZone(diplomatRuntime.internalConstructor, timeZoneDeref, []);
     96        const canonicalDeref = ptr + 4;
     97        structObj.canonical = new diplomatRuntime.DiplomatSliceStr(wasm, canonicalDeref,  "string8", aEdges).getValue();
     98        const normalizedDeref = ptr + 12;
     99        structObj.normalized = new diplomatRuntime.DiplomatSliceStr(wasm, normalizedDeref,  "string8", aEdges).getValue();
    100 
    101        return new TimeZoneAndCanonicalAndNormalized(structObj, internalConstructor);
    102    }
    103 
    104    // Return all fields corresponding to lifetime `'a`
    105    // without handling lifetime dependencies (this is the job of the caller)
    106    // This is all fields that may be borrowed from if borrowing `'a`,
    107    // assuming that there are no `'other: a`. bounds. In case of such bounds,
    108    // the caller should take care to also call _fieldsForLifetimeOther
    109    get _fieldsForLifetimeA() {
    110        return [this.#canonical, this.#normalized];
    111    };
    112 
    113 
    114    constructor(structObj, internalConstructor) {
    115        return this.#internalConstructor(...arguments)
    116    }
    117 }