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