// generated by diplomat-tool import { AnyCalendarKind } from "./AnyCalendarKind.mjs" import { DataError } from "./DataError.mjs" import { DataProvider } from "./DataProvider.mjs" import { Locale } from "./Locale.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; /** See the [Rust documentation for `AnyCalendar`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html) for more information. */ const Calendar_box_destroy_registry = new FinalizationRegistry((ptr) => { wasm.icu4x_Calendar_destroy_mv1(ptr); }); export class Calendar { // Internal ptr reference: #ptr = null; // Lifetimes are only to keep dependencies alive. // Since JS won't garbage collect until there are no incoming edges. #selfEdge = []; constructor(symbol, ptr, selfEdge) { if (symbol !== diplomatRuntime.internalConstructor) { console.error("Calendar is an Opaque type. You cannot call its constructor."); return; } this.#ptr = ptr; this.#selfEdge = selfEdge; // Are we being borrowed? If not, we can register. if (this.#selfEdge.length === 0) { Calendar_box_destroy_registry.register(this, this.#ptr); } } get ffiValue() { return this.#ptr; } static createForLocale(provider, locale) { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_Calendar_create_for_locale_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue); try { if (!diplomatReceive.resultFlag) { const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new Calendar(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } finally { diplomatReceive.free(); } } static createForKind(provider, kind) { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_Calendar_create_for_kind_mv1(diplomatReceive.buffer, provider.ffiValue, kind.ffiValue); try { if (!diplomatReceive.resultFlag) { const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new Calendar(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } finally { diplomatReceive.free(); } } get kind() { const result = wasm.icu4x_Calendar_kind_mv1(this.ffiValue); try { return new AnyCalendarKind(diplomatRuntime.internalConstructor, result); } finally {} } }