Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XUnitsConverterFactory.mjs

raw
1 import wasm from "./diplomat-wasm.mjs"
2 import * as diplomatRuntime from "./diplomat-runtime.mjs"
3 import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs"
4 import { ICU4XMeasureUnitParser } from "./ICU4XMeasureUnitParser.mjs"
5 import { ICU4XUnitsConverter } from "./ICU4XUnitsConverter.mjs"
6
7 const ICU4XUnitsConverterFactory_box_destroy_registry = new FinalizationRegistry(underlying => {
8 wasm.ICU4XUnitsConverterFactory_destroy(underlying);
9 });
10
11 export class ICU4XUnitsConverterFactory {
12 #lifetimeEdges = [];
13 constructor(underlying, owned, edges) {
14 this.underlying = underlying;
15 this.#lifetimeEdges.push(...edges);
16 if (owned) {
17 ICU4XUnitsConverterFactory_box_destroy_registry.register(this, underlying);
18 }
19 }
20
21 static create(arg_provider) {
22 return (() => {
23 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
24 wasm.ICU4XUnitsConverterFactory_create(diplomat_receive_buffer, arg_provider.underlying);
25 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
26 if (is_ok) {
27 const ok_value = new ICU4XUnitsConverterFactory(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []);
28 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
29 return ok_value;
30 } else {
31 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
32 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
33 throw new diplomatRuntime.FFIError(throw_value);
34 }
35 })();
36 }
37
38 converter(arg_from, arg_to) {
39 return (() => {
40 const option_ptr = wasm.ICU4XUnitsConverterFactory_converter(this.underlying, arg_from.underlying, arg_to.underlying);
41 return (option_ptr == 0) ? undefined : new ICU4XUnitsConverter(option_ptr, true, []);
42 })();
43 }
44
45 parser() {
46 return new ICU4XMeasureUnitParser(wasm.ICU4XUnitsConverterFactory_parser(this.underlying), true, [this]);
47 }
48 }