Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XDateTimeFormatter.mjs

raw
1 import wasm from "./diplomat-wasm.mjs"
2 import * as diplomatRuntime from "./diplomat-runtime.mjs"
3 import { ICU4XDateLength_js_to_rust, ICU4XDateLength_rust_to_js } from "./ICU4XDateLength.mjs"
4 import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs"
5 import { ICU4XTimeLength_js_to_rust, ICU4XTimeLength_rust_to_js } from "./ICU4XTimeLength.mjs"
6
7 const ICU4XDateTimeFormatter_box_destroy_registry = new FinalizationRegistry(underlying => {
8 wasm.ICU4XDateTimeFormatter_destroy(underlying);
9 });
10
11 export class ICU4XDateTimeFormatter {
12 #lifetimeEdges = [];
13 constructor(underlying, owned, edges) {
14 this.underlying = underlying;
15 this.#lifetimeEdges.push(...edges);
16 if (owned) {
17 ICU4XDateTimeFormatter_box_destroy_registry.register(this, underlying);
18 }
19 }
20
21 static create_with_lengths(arg_provider, arg_locale, arg_date_length, arg_time_length) {
22 return (() => {
23 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
24 wasm.ICU4XDateTimeFormatter_create_with_lengths(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ICU4XDateLength_js_to_rust[arg_date_length], ICU4XTimeLength_js_to_rust[arg_time_length]);
25 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
26 if (is_ok) {
27 const ok_value = new ICU4XDateTimeFormatter(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 format_datetime(arg_value) {
39 return diplomatRuntime.withWriteable(wasm, (writeable) => {
40 return (() => {
41 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
42 wasm.ICU4XDateTimeFormatter_format_datetime(diplomat_receive_buffer, this.underlying, arg_value.underlying, writeable);
43 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
44 if (is_ok) {
45 const ok_value = {};
46 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
47 return ok_value;
48 } else {
49 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
50 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
51 throw new diplomatRuntime.FFIError(throw_value);
52 }
53 })();
54 });
55 }
56
57 format_iso_datetime(arg_value) {
58 return diplomatRuntime.withWriteable(wasm, (writeable) => {
59 return (() => {
60 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
61 wasm.ICU4XDateTimeFormatter_format_iso_datetime(diplomat_receive_buffer, this.underlying, arg_value.underlying, writeable);
62 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
63 if (is_ok) {
64 const ok_value = {};
65 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
66 return ok_value;
67 } else {
68 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
69 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
70 throw new diplomatRuntime.FFIError(throw_value);
71 }
72 })();
73 });
74 }
75 }