• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { CodePointSetBuilder } from "./CodePointSetBuilder.mjs"
3import { DataError } from "./DataError.mjs"
4import { DataProvider } from "./DataProvider.mjs"
5import wasm from "./diplomat-wasm.mjs";
6import * as diplomatRuntime from "./diplomat-runtime.mjs";
7
8
9/** See the [Rust documentation for `CaseMapCloser`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html) for more information.
10*/
11const CaseMapCloser_box_destroy_registry = new FinalizationRegistry((ptr) => {
12    wasm.icu4x_CaseMapCloser_destroy_mv1(ptr);
13});
14
15export class CaseMapCloser {
16
17    // Internal ptr reference:
18    #ptr = null;
19
20    // Lifetimes are only to keep dependencies alive.
21    // Since JS won't garbage collect until there are no incoming edges.
22    #selfEdge = [];
23
24    #internalConstructor(symbol, ptr, selfEdge) {
25        if (symbol !== diplomatRuntime.internalConstructor) {
26            console.error("CaseMapCloser is an Opaque type. You cannot call its constructor.");
27            return;
28        }
29
30        this.#ptr = ptr;
31        this.#selfEdge = selfEdge;
32
33        // Are we being borrowed? If not, we can register.
34        if (this.#selfEdge.length === 0) {
35            CaseMapCloser_box_destroy_registry.register(this, this.#ptr);
36        }
37
38        return this;
39    }
40    get ffiValue() {
41        return this.#ptr;
42    }
43
44    #defaultConstructor() {
45        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
46
47        const result = wasm.icu4x_CaseMapCloser_create_mv1(diplomatReceive.buffer);
48
49        try {
50            if (!diplomatReceive.resultFlag) {
51                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
52                throw new globalThis.Error('DataError: ' + cause.value, { cause });
53            }
54            return new CaseMapCloser(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
55        }
56
57        finally {
58            diplomatReceive.free();
59        }
60    }
61
62    static createWithProvider(provider) {
63        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
64
65        const result = wasm.icu4x_CaseMapCloser_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
66
67        try {
68            if (!diplomatReceive.resultFlag) {
69                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
70                throw new globalThis.Error('DataError: ' + cause.value, { cause });
71            }
72            return new CaseMapCloser(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
73        }
74
75        finally {
76            diplomatReceive.free();
77        }
78    }
79
80    addCaseClosureTo(c, builder) {wasm.icu4x_CaseMapCloser_add_case_closure_to_mv1(this.ffiValue, c, builder.ffiValue);
81
82        try {}
83
84        finally {}
85    }
86
87    addStringCaseClosureTo(s, builder) {
88        let functionCleanupArena = new diplomatRuntime.CleanupArena();
89
90        const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s));
91
92        const result = wasm.icu4x_CaseMapCloser_add_string_case_closure_to_mv1(this.ffiValue, ...sSlice.splat(), builder.ffiValue);
93
94        try {
95            return result;
96        }
97
98        finally {
99            functionCleanupArena.free();
100        }
101    }
102
103    constructor() {
104        if (arguments[0] === diplomatRuntime.exposeConstructor) {
105            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
106        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
107            return this.#internalConstructor(...arguments);
108        } else {
109            return this.#defaultConstructor(...arguments);
110        }
111    }
112}