1// generated by diplomat-tool 2import { DataError } from "./DataError.mjs" 3import { DataProvider } from "./DataProvider.mjs" 4import wasm from "./diplomat-wasm.mjs"; 5import * as diplomatRuntime from "./diplomat-runtime.mjs"; 6 7 8/** The raw canonical composition operation. 9* 10*Callers should generally use ComposingNormalizer unless they specifically need raw composition operations 11* 12*See the [Rust documentation for `CanonicalComposition`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalComposition.html) for more information. 13*/ 14const CanonicalComposition_box_destroy_registry = new FinalizationRegistry((ptr) => { 15 wasm.icu4x_CanonicalComposition_destroy_mv1(ptr); 16}); 17 18export class CanonicalComposition { 19 20 // Internal ptr reference: 21 #ptr = null; 22 23 // Lifetimes are only to keep dependencies alive. 24 // Since JS won't garbage collect until there are no incoming edges. 25 #selfEdge = []; 26 27 #internalConstructor(symbol, ptr, selfEdge) { 28 if (symbol !== diplomatRuntime.internalConstructor) { 29 console.error("CanonicalComposition is an Opaque type. You cannot call its constructor."); 30 return; 31 } 32 33 this.#ptr = ptr; 34 this.#selfEdge = selfEdge; 35 36 // Are we being borrowed? If not, we can register. 37 if (this.#selfEdge.length === 0) { 38 CanonicalComposition_box_destroy_registry.register(this, this.#ptr); 39 } 40 41 return this; 42 } 43 get ffiValue() { 44 return this.#ptr; 45 } 46 47 #defaultConstructor() { 48 const result = wasm.icu4x_CanonicalComposition_create_mv1(); 49 50 try { 51 return new CanonicalComposition(diplomatRuntime.internalConstructor, result, []); 52 } 53 54 finally {} 55 } 56 57 static createWithProvider(provider) { 58 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 59 60 const result = wasm.icu4x_CanonicalComposition_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); 61 62 try { 63 if (!diplomatReceive.resultFlag) { 64 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 65 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 66 } 67 return new CanonicalComposition(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 68 } 69 70 finally { 71 diplomatReceive.free(); 72 } 73 } 74 75 compose(starter, second) { 76 const result = wasm.icu4x_CanonicalComposition_compose_mv1(this.ffiValue, starter, second); 77 78 try { 79 return result; 80 } 81 82 finally {} 83 } 84 85 constructor() { 86 if (arguments[0] === diplomatRuntime.exposeConstructor) { 87 return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1)); 88 } else if (arguments[0] === diplomatRuntime.internalConstructor) { 89 return this.#internalConstructor(...arguments); 90 } else { 91 return this.#defaultConstructor(...arguments); 92 } 93 } 94}