• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { DataError } from "./DataError.mjs"
3import { DataProvider } from "./DataProvider.mjs"
4import { Locale } from "./Locale.mjs"
5import { LocaleDirection } from "./LocaleDirection.mjs"
6import wasm from "./diplomat-wasm.mjs";
7import * as diplomatRuntime from "./diplomat-runtime.mjs";
8
9
10/** See the [Rust documentation for `LocaleDirectionality`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html) for more information.
11*/
12const LocaleDirectionality_box_destroy_registry = new FinalizationRegistry((ptr) => {
13    wasm.icu4x_LocaleDirectionality_destroy_mv1(ptr);
14});
15
16export class LocaleDirectionality {
17
18    // Internal ptr reference:
19    #ptr = null;
20
21    // Lifetimes are only to keep dependencies alive.
22    // Since JS won't garbage collect until there are no incoming edges.
23    #selfEdge = [];
24
25    #internalConstructor(symbol, ptr, selfEdge) {
26        if (symbol !== diplomatRuntime.internalConstructor) {
27            console.error("LocaleDirectionality is an Opaque type. You cannot call its constructor.");
28            return;
29        }
30
31        this.#ptr = ptr;
32        this.#selfEdge = selfEdge;
33
34        // Are we being borrowed? If not, we can register.
35        if (this.#selfEdge.length === 0) {
36            LocaleDirectionality_box_destroy_registry.register(this, this.#ptr);
37        }
38
39        return this;
40    }
41    get ffiValue() {
42        return this.#ptr;
43    }
44
45    #defaultConstructor() {
46        const result = wasm.icu4x_LocaleDirectionality_create_common_mv1();
47
48        try {
49            return new LocaleDirectionality(diplomatRuntime.internalConstructor, result, []);
50        }
51
52        finally {}
53    }
54
55    static createCommonWithProvider(provider) {
56        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
57
58        const result = wasm.icu4x_LocaleDirectionality_create_common_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
59
60        try {
61            if (!diplomatReceive.resultFlag) {
62                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
63                throw new globalThis.Error('DataError: ' + cause.value, { cause });
64            }
65            return new LocaleDirectionality(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
66        }
67
68        finally {
69            diplomatReceive.free();
70        }
71    }
72
73    static createExtended() {
74        const result = wasm.icu4x_LocaleDirectionality_create_extended_mv1();
75
76        try {
77            return new LocaleDirectionality(diplomatRuntime.internalConstructor, result, []);
78        }
79
80        finally {}
81    }
82
83    static createExtendedWithProvider(provider) {
84        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
85
86        const result = wasm.icu4x_LocaleDirectionality_create_extended_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
87
88        try {
89            if (!diplomatReceive.resultFlag) {
90                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
91                throw new globalThis.Error('DataError: ' + cause.value, { cause });
92            }
93            return new LocaleDirectionality(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
94        }
95
96        finally {
97            diplomatReceive.free();
98        }
99    }
100
101    get(locale) {
102        const result = wasm.icu4x_LocaleDirectionality_get_mv1(this.ffiValue, locale.ffiValue);
103
104        try {
105            return new LocaleDirection(diplomatRuntime.internalConstructor, result);
106        }
107
108        finally {}
109    }
110
111    isLeftToRight(locale) {
112        const result = wasm.icu4x_LocaleDirectionality_is_left_to_right_mv1(this.ffiValue, locale.ffiValue);
113
114        try {
115            return result;
116        }
117
118        finally {}
119    }
120
121    isRightToLeft(locale) {
122        const result = wasm.icu4x_LocaleDirectionality_is_right_to_left_mv1(this.ffiValue, locale.ffiValue);
123
124        try {
125            return result;
126        }
127
128        finally {}
129    }
130
131    constructor() {
132        if (arguments[0] === diplomatRuntime.exposeConstructor) {
133            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
134        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
135            return this.#internalConstructor(...arguments);
136        } else {
137            return this.#defaultConstructor(...arguments);
138        }
139    }
140}