tor-browser

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

UnitsConverter.mjs (2669B)


      1 // generated by diplomat-tool
      2 import wasm from "./diplomat-wasm.mjs";
      3 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      4 
      5 
      6 /**
      7 * An ICU4X Units Converter object, capable of converting between two [`MeasureUnit`]s.
      8 *
      9 * You can create an instance of this object using [`UnitsConverterFactory`] by calling the `converter` method.
     10 *
     11 * See the [Rust documentation for `UnitsConverter`](https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html) for more information.
     12 */
     13 const UnitsConverter_box_destroy_registry = new FinalizationRegistry((ptr) => {
     14    wasm.icu4x_UnitsConverter_destroy_mv1(ptr);
     15 });
     16 
     17 export class UnitsConverter {
     18    // Internal ptr reference:
     19    #ptr = null;
     20 
     21    // Lifetimes are only to keep dependencies alive.
     22    // Since JS won't garbage collect until there are no incoming edges.
     23    #selfEdge = [];
     24 
     25    #internalConstructor(symbol, ptr, selfEdge) {
     26        if (symbol !== diplomatRuntime.internalConstructor) {
     27            console.error("UnitsConverter is an Opaque type. You cannot call its constructor.");
     28            return;
     29        }
     30        this.#ptr = ptr;
     31        this.#selfEdge = selfEdge;
     32 
     33        // Are we being borrowed? If not, we can register.
     34        if (this.#selfEdge.length === 0) {
     35            UnitsConverter_box_destroy_registry.register(this, this.#ptr);
     36        }
     37 
     38        return this;
     39    }
     40    get ffiValue() {
     41        return this.#ptr;
     42    }
     43 
     44 
     45    /**
     46     * Converts the input value from the input unit to the output unit (that have been used to create this converter).
     47     * NOTE:
     48     * The conversion using floating-point operations is not as accurate as the conversion using ratios.
     49     *
     50     * See the [Rust documentation for `convert`](https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html#method.convert) for more information.
     51     */
     52    convertNumber(value) {
     53 
     54        const result = wasm.icu4x_UnitsConverter_convert_double_mv1(this.ffiValue, value);
     55 
     56        try {
     57            return result;
     58        }
     59 
     60        finally {
     61        }
     62    }
     63 
     64    /**
     65     * Clones the current [`UnitsConverter`] object.
     66     *
     67     * See the [Rust documentation for `clone`](https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html#method.clone) for more information.
     68     */
     69    clone() {
     70 
     71        const result = wasm.icu4x_UnitsConverter_clone_mv1(this.ffiValue);
     72 
     73        try {
     74            return new UnitsConverter(diplomatRuntime.internalConstructor, result, []);
     75        }
     76 
     77        finally {
     78        }
     79    }
     80 
     81    constructor(symbol, ptr, selfEdge) {
     82        return this.#internalConstructor(...arguments)
     83    }
     84 }