tor-browser

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

LocaleFallbackConfig.mjs (3184B)


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