Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XLocaleDisplayNamesFormatter.mjs

raw
1 import wasm from "./diplomat-wasm.mjs"
2 import * as diplomatRuntime from "./diplomat-runtime.mjs"
3 import { ICU4XDisplayNamesFallback_js_to_rust, ICU4XDisplayNamesFallback_rust_to_js } from "./ICU4XDisplayNamesFallback.mjs"
4 import { ICU4XDisplayNamesStyle_js_to_rust, ICU4XDisplayNamesStyle_rust_to_js } from "./ICU4XDisplayNamesStyle.mjs"
5 import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs"
6 import { ICU4XLanguageDisplay_js_to_rust, ICU4XLanguageDisplay_rust_to_js } from "./ICU4XLanguageDisplay.mjs"
7
8 const ICU4XLocaleDisplayNamesFormatter_box_destroy_registry = new FinalizationRegistry(underlying => {
9 wasm.ICU4XLocaleDisplayNamesFormatter_destroy(underlying);
10 });
11
12 export class ICU4XLocaleDisplayNamesFormatter {
13 #lifetimeEdges = [];
14 constructor(underlying, owned, edges) {
15 this.underlying = underlying;
16 this.#lifetimeEdges.push(...edges);
17 if (owned) {
18 ICU4XLocaleDisplayNamesFormatter_box_destroy_registry.register(this, underlying);
19 }
20 }
21
22 static create(arg_provider, arg_locale, arg_options) {
23 const field_style_arg_options = arg_options["style"];
24 const field_fallback_arg_options = arg_options["fallback"];
25 const field_language_display_arg_options = arg_options["language_display"];
26 return (() => {
27 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
28 wasm.ICU4XLocaleDisplayNamesFormatter_create(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ICU4XDisplayNamesStyle_js_to_rust[field_style_arg_options], ICU4XDisplayNamesFallback_js_to_rust[field_fallback_arg_options], ICU4XLanguageDisplay_js_to_rust[field_language_display_arg_options]);
29 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
30 if (is_ok) {
31 const ok_value = new ICU4XLocaleDisplayNamesFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []);
32 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
33 return ok_value;
34 } else {
35 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
36 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
37 throw new diplomatRuntime.FFIError(throw_value);
38 }
39 })();
40 }
41
42 of(arg_locale) {
43 return diplomatRuntime.withWriteable(wasm, (writeable) => {
44 return (() => {
45 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
46 wasm.ICU4XLocaleDisplayNamesFormatter_of(diplomat_receive_buffer, this.underlying, arg_locale.underlying, writeable);
47 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
48 if (is_ok) {
49 const ok_value = {};
50 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
51 return ok_value;
52 } else {
53 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
54 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
55 throw new diplomatRuntime.FFIError(throw_value);
56 }
57 })();
58 });
59 }
60 }