Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XMeasureUnitParser.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 { ICU4XMeasureUnit } from "./ICU4XMeasureUnit.mjs"
5
6 const ICU4XMeasureUnitParser_box_destroy_registry = new FinalizationRegistry(underlying => {
7 wasm.ICU4XMeasureUnitParser_destroy(underlying);
8 });
9
10 export class ICU4XMeasureUnitParser {
11 #lifetimeEdges = [];
12 constructor(underlying, owned, edges) {
13 this.underlying = underlying;
14 this.#lifetimeEdges.push(...edges);
15 if (owned) {
16 ICU4XMeasureUnitParser_box_destroy_registry.register(this, underlying);
17 }
18 }
19
20 parse(arg_unit_id) {
21 const buf_arg_unit_id = diplomatRuntime.DiplomatBuf.str8(wasm, arg_unit_id);
22 const diplomat_out = (() => {
23 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
24 wasm.ICU4XMeasureUnitParser_parse(diplomat_receive_buffer, this.underlying, buf_arg_unit_id.ptr, buf_arg_unit_id.size);
25 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
26 if (is_ok) {
27 const ok_value = new ICU4XMeasureUnit(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 buf_arg_unit_id.free();
37 return diplomat_out;
38 }
39 }