Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XPluralRules.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 { ICU4XPluralCategories } from "./ICU4XPluralCategories.mjs"
5 import { ICU4XPluralCategory_js_to_rust, ICU4XPluralCategory_rust_to_js } from "./ICU4XPluralCategory.mjs"
6
7 const ICU4XPluralRules_box_destroy_registry = new FinalizationRegistry(underlying => {
8 wasm.ICU4XPluralRules_destroy(underlying);
9 });
10
11 export class ICU4XPluralRules {
12 #lifetimeEdges = [];
13 constructor(underlying, owned, edges) {
14 this.underlying = underlying;
15 this.#lifetimeEdges.push(...edges);
16 if (owned) {
17 ICU4XPluralRules_box_destroy_registry.register(this, underlying);
18 }
19 }
20
21 static create_cardinal(arg_provider, arg_locale) {
22 return (() => {
23 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
24 wasm.ICU4XPluralRules_create_cardinal(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying);
25 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
26 if (is_ok) {
27 const ok_value = new ICU4XPluralRules(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 static create_ordinal(arg_provider, arg_locale) {
39 return (() => {
40 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
41 wasm.ICU4XPluralRules_create_ordinal(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying);
42 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
43 if (is_ok) {
44 const ok_value = new ICU4XPluralRules(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []);
45 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
46 return ok_value;
47 } else {
48 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
49 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
50 throw new diplomatRuntime.FFIError(throw_value);
51 }
52 })();
53 }
54
55 category_for(arg_op) {
56 return ICU4XPluralCategory_rust_to_js[wasm.ICU4XPluralRules_category_for(this.underlying, arg_op.underlying)];
57 }
58
59 categories() {
60 return (() => {
61 const diplomat_receive_buffer = wasm.diplomat_alloc(6, 1);
62 wasm.ICU4XPluralRules_categories(diplomat_receive_buffer, this.underlying);
63 const out = new ICU4XPluralCategories(diplomat_receive_buffer);
64 wasm.diplomat_free(diplomat_receive_buffer, 6, 1);
65 return out;
66 })();
67 }
68 }