Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XCalendar.mjs

raw
1 import wasm from "./diplomat-wasm.mjs"
2 import * as diplomatRuntime from "./diplomat-runtime.mjs"
3 import { ICU4XAnyCalendarKind_js_to_rust, ICU4XAnyCalendarKind_rust_to_js } from "./ICU4XAnyCalendarKind.mjs"
4 import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs"
5
6 const ICU4XCalendar_box_destroy_registry = new FinalizationRegistry(underlying => {
7 wasm.ICU4XCalendar_destroy(underlying);
8 });
9
10 export class ICU4XCalendar {
11 #lifetimeEdges = [];
12 constructor(underlying, owned, edges) {
13 this.underlying = underlying;
14 this.#lifetimeEdges.push(...edges);
15 if (owned) {
16 ICU4XCalendar_box_destroy_registry.register(this, underlying);
17 }
18 }
19
20 static create_for_locale(arg_provider, arg_locale) {
21 return (() => {
22 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
23 wasm.ICU4XCalendar_create_for_locale(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying);
24 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
25 if (is_ok) {
26 const ok_value = new ICU4XCalendar(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []);
27 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
28 return ok_value;
29 } else {
30 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
31 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
32 throw new diplomatRuntime.FFIError(throw_value);
33 }
34 })();
35 }
36
37 static create_for_kind(arg_provider, arg_kind) {
38 return (() => {
39 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
40 wasm.ICU4XCalendar_create_for_kind(diplomat_receive_buffer, arg_provider.underlying, ICU4XAnyCalendarKind_js_to_rust[arg_kind]);
41 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
42 if (is_ok) {
43 const ok_value = new ICU4XCalendar(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []);
44 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
45 return ok_value;
46 } else {
47 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
48 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
49 throw new diplomatRuntime.FFIError(throw_value);
50 }
51 })();
52 }
53
54 kind() {
55 return ICU4XAnyCalendarKind_rust_to_js[wasm.ICU4XCalendar_kind(this.underlying)];
56 }
57 }