• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { AnyCalendarKind } from "./AnyCalendarKind.mjs"
3import { DataError } from "./DataError.mjs"
4import { DataProvider } from "./DataProvider.mjs"
5import { Locale } from "./Locale.mjs"
6import wasm from "./diplomat-wasm.mjs";
7import * as diplomatRuntime from "./diplomat-runtime.mjs";
8
9
10/** See the [Rust documentation for `AnyCalendar`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html) for more information.
11*/
12const Calendar_box_destroy_registry = new FinalizationRegistry((ptr) => {
13    wasm.icu4x_Calendar_destroy_mv1(ptr);
14});
15
16export class Calendar {
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("Calendar 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            Calendar_box_destroy_registry.register(this, this.#ptr);
37        }
38
39        return this;
40    }
41    get ffiValue() {
42        return this.#ptr;
43    }
44
45    static createForLocale(locale) {
46        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
47
48        const result = wasm.icu4x_Calendar_create_for_locale_mv1(diplomatReceive.buffer, locale.ffiValue);
49
50        try {
51            if (!diplomatReceive.resultFlag) {
52                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
53                throw new globalThis.Error('DataError: ' + cause.value, { cause });
54            }
55            return new Calendar(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
56        }
57
58        finally {
59            diplomatReceive.free();
60        }
61    }
62
63    static createForKind(kind) {
64        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
65
66        const result = wasm.icu4x_Calendar_create_for_kind_mv1(diplomatReceive.buffer, kind.ffiValue);
67
68        try {
69            if (!diplomatReceive.resultFlag) {
70                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
71                throw new globalThis.Error('DataError: ' + cause.value, { cause });
72            }
73            return new Calendar(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
74        }
75
76        finally {
77            diplomatReceive.free();
78        }
79    }
80
81    static createForLocaleWithProvider(provider, locale) {
82        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
83
84        const result = wasm.icu4x_Calendar_create_for_locale_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
85
86        try {
87            if (!diplomatReceive.resultFlag) {
88                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
89                throw new globalThis.Error('DataError: ' + cause.value, { cause });
90            }
91            return new Calendar(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
92        }
93
94        finally {
95            diplomatReceive.free();
96        }
97    }
98
99    static createForKindWithProvider(provider, kind) {
100        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
101
102        const result = wasm.icu4x_Calendar_create_for_kind_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, kind.ffiValue);
103
104        try {
105            if (!diplomatReceive.resultFlag) {
106                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
107                throw new globalThis.Error('DataError: ' + cause.value, { cause });
108            }
109            return new Calendar(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
110        }
111
112        finally {
113            diplomatReceive.free();
114        }
115    }
116
117    get kind() {
118        const result = wasm.icu4x_Calendar_kind_mv1(this.ffiValue);
119
120        try {
121            return new AnyCalendarKind(diplomatRuntime.internalConstructor, result);
122        }
123
124        finally {}
125    }
126
127    constructor(symbol, ptr, selfEdge) {
128        return this.#internalConstructor(...arguments)
129    }
130}