tor-browser

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

PluralOperands.mjs (3299B)


      1 // generated by diplomat-tool
      2 import { Decimal } from "./Decimal.mjs"
      3 import { DecimalParseError } from "./DecimalParseError.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 `PluralOperands`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html) for more information.
     10 */
     11 const PluralOperands_box_destroy_registry = new FinalizationRegistry((ptr) => {
     12    wasm.icu4x_PluralOperands_destroy_mv1(ptr);
     13 });
     14 
     15 export class PluralOperands {
     16    // Internal ptr reference:
     17    #ptr = null;
     18 
     19    // Lifetimes are only to keep dependencies alive.
     20    // Since JS won't garbage collect until there are no incoming edges.
     21    #selfEdge = [];
     22 
     23    #internalConstructor(symbol, ptr, selfEdge) {
     24        if (symbol !== diplomatRuntime.internalConstructor) {
     25            console.error("PluralOperands is an Opaque type. You cannot call its constructor.");
     26            return;
     27        }
     28        this.#ptr = ptr;
     29        this.#selfEdge = selfEdge;
     30 
     31        // Are we being borrowed? If not, we can register.
     32        if (this.#selfEdge.length === 0) {
     33            PluralOperands_box_destroy_registry.register(this, this.#ptr);
     34        }
     35 
     36        return this;
     37    }
     38    get ffiValue() {
     39        return this.#ptr;
     40    }
     41 
     42 
     43    /**
     44     * Construct for a given string representing a number
     45     *
     46     * See the [Rust documentation for `from_str`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html#method.from_str) for more information.
     47     */
     48    static fromString(s) {
     49        let functionCleanupArena = new diplomatRuntime.CleanupArena();
     50 
     51        const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s);
     52        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     53 
     54 
     55        const result = wasm.icu4x_PluralOperands_from_string_mv1(diplomatReceive.buffer, ...sSlice.splat());
     56 
     57        try {
     58            if (!diplomatReceive.resultFlag) {
     59                const cause = new DecimalParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
     60                throw new globalThis.Error('DecimalParseError: ' + cause.value, { cause });
     61            }
     62            return new PluralOperands(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
     63        }
     64 
     65        finally {
     66            functionCleanupArena.free();
     67 
     68            diplomatReceive.free();
     69        }
     70    }
     71 
     72    /**
     73     * Construct for a given integer
     74     */
     75    static fromBigInt(i) {
     76 
     77        const result = wasm.icu4x_PluralOperands_from_int64_mv1(i);
     78 
     79        try {
     80            return new PluralOperands(diplomatRuntime.internalConstructor, result, []);
     81        }
     82 
     83        finally {
     84        }
     85    }
     86 
     87    /**
     88     * Construct from a FixedDecimal
     89     *
     90     * Retains at most 18 digits each from the integer and fraction parts.
     91     */
     92    static fromFixedDecimal(x) {
     93 
     94        const result = wasm.icu4x_PluralOperands_from_fixed_decimal_mv1(x.ffiValue);
     95 
     96        try {
     97            return new PluralOperands(diplomatRuntime.internalConstructor, result, []);
     98        }
     99 
    100        finally {
    101        }
    102    }
    103 
    104    constructor(symbol, ptr, selfEdge) {
    105        return this.#internalConstructor(...arguments)
    106    }
    107 }