tor-browser

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

PluralCategories.mjs (4868B)


      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 PluralCategories {
      8    #zero;
      9    get zero() {
     10        return this.#zero;
     11    }
     12    #one;
     13    get one() {
     14        return this.#one;
     15    }
     16    #two;
     17    get two() {
     18        return this.#two;
     19    }
     20    #few;
     21    get few() {
     22        return this.#few;
     23    }
     24    #many;
     25    get many() {
     26        return this.#many;
     27    }
     28    #other;
     29    get other() {
     30        return this.#other;
     31    }
     32    #internalConstructor(structObj, internalConstructor) {
     33        if (typeof structObj !== "object") {
     34            throw new Error("PluralCategories's constructor takes an object of PluralCategories's fields.");
     35        }
     36 
     37        if (internalConstructor !== diplomatRuntime.internalConstructor) {
     38            throw new Error("PluralCategories is an out struct and can only be created internally.");
     39        }
     40        if ("zero" in structObj) {
     41            this.#zero = structObj.zero;
     42        } else {
     43            throw new Error("Missing required field zero.");
     44        }
     45 
     46        if ("one" in structObj) {
     47            this.#one = structObj.one;
     48        } else {
     49            throw new Error("Missing required field one.");
     50        }
     51 
     52        if ("two" in structObj) {
     53            this.#two = structObj.two;
     54        } else {
     55            throw new Error("Missing required field two.");
     56        }
     57 
     58        if ("few" in structObj) {
     59            this.#few = structObj.few;
     60        } else {
     61            throw new Error("Missing required field few.");
     62        }
     63 
     64        if ("many" in structObj) {
     65            this.#many = structObj.many;
     66        } else {
     67            throw new Error("Missing required field many.");
     68        }
     69 
     70        if ("other" in structObj) {
     71            this.#other = structObj.other;
     72        } else {
     73            throw new Error("Missing required field other.");
     74        }
     75 
     76        return this;
     77    }
     78 
     79    // Return this struct in FFI function friendly format.
     80    // Returns an array that can be expanded with spread syntax (...)
     81    _intoFFI(
     82        functionCleanupArena,
     83        appendArrayMap
     84    ) {
     85        return [this.#zero, this.#one, this.#two, this.#few, this.#many, this.#other]
     86    }
     87 
     88    static _fromSuppliedValue(internalConstructor, obj) {
     89        if (internalConstructor !== diplomatRuntime.internalConstructor) {
     90            throw new Error("_fromSuppliedValue cannot be called externally.");
     91        }
     92 
     93        if (obj instanceof PluralCategories) {
     94            return obj;
     95        }
     96 
     97        return PluralCategories.fromFields(obj);
     98    }
     99 
    100    _writeToArrayBuffer(
    101        arrayBuffer,
    102        offset,
    103        functionCleanupArena,
    104        appendArrayMap
    105    ) {
    106        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#zero, Uint8Array);
    107        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 1, this.#one, Uint8Array);
    108        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 2, this.#two, Uint8Array);
    109        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 3, this.#few, Uint8Array);
    110        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#many, Uint8Array);
    111        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 5, this.#other, Uint8Array);
    112    }
    113 
    114    // This struct contains borrowed fields, so this takes in a list of
    115    // "edges" corresponding to where each lifetime's data may have been borrowed from
    116    // and passes it down to individual fields containing the borrow.
    117    // This method does not attempt to handle any dependencies between lifetimes, the caller
    118    // should handle this when constructing edge arrays.
    119    static _fromFFI(internalConstructor, ptr) {
    120        if (internalConstructor !== diplomatRuntime.internalConstructor) {
    121            throw new Error("PluralCategories._fromFFI is not meant to be called externally. Please use the default constructor.");
    122        }
    123        let structObj = {};
    124        const zeroDeref = (new Uint8Array(wasm.memory.buffer, ptr, 1))[0] === 1;
    125        structObj.zero = zeroDeref;
    126        const oneDeref = (new Uint8Array(wasm.memory.buffer, ptr + 1, 1))[0] === 1;
    127        structObj.one = oneDeref;
    128        const twoDeref = (new Uint8Array(wasm.memory.buffer, ptr + 2, 1))[0] === 1;
    129        structObj.two = twoDeref;
    130        const fewDeref = (new Uint8Array(wasm.memory.buffer, ptr + 3, 1))[0] === 1;
    131        structObj.few = fewDeref;
    132        const manyDeref = (new Uint8Array(wasm.memory.buffer, ptr + 4, 1))[0] === 1;
    133        structObj.many = manyDeref;
    134        const otherDeref = (new Uint8Array(wasm.memory.buffer, ptr + 5, 1))[0] === 1;
    135        structObj.other = otherDeref;
    136 
    137        return new PluralCategories(structObj, internalConstructor);
    138    }
    139 
    140 
    141    constructor(structObj, internalConstructor) {
    142        return this.#internalConstructor(...arguments)
    143    }
    144 }