tor-browser

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

LineBreakOptions.mjs (4509B)


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