CanonicalCombiningClassMap.mjs (4027B)
1 // generated by diplomat-tool 2 import { DataError } from "./DataError.mjs" 3 import { DataProvider } from "./DataProvider.mjs" 4 import wasm from "./diplomat-wasm.mjs"; 5 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 6 7 8 /** 9 * Lookup of the Canonical_Combining_Class Unicode property 10 * 11 * See the [Rust documentation for `CanonicalCombiningClassMap`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html) for more information. 12 */ 13 const CanonicalCombiningClassMap_box_destroy_registry = new FinalizationRegistry((ptr) => { 14 wasm.icu4x_CanonicalCombiningClassMap_destroy_mv1(ptr); 15 }); 16 17 export class CanonicalCombiningClassMap { 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("CanonicalCombiningClassMap is an Opaque type. You cannot call its constructor."); 28 return; 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 CanonicalCombiningClassMap_box_destroy_registry.register(this, this.#ptr); 36 } 37 38 return this; 39 } 40 get ffiValue() { 41 return this.#ptr; 42 } 43 44 45 /** 46 * Construct a new CanonicalCombiningClassMap instance for NFC using compiled data. 47 * 48 * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html#method.new) for more information. 49 */ 50 #defaultConstructor() { 51 52 const result = wasm.icu4x_CanonicalCombiningClassMap_create_mv1(); 53 54 try { 55 return new CanonicalCombiningClassMap(diplomatRuntime.internalConstructor, result, []); 56 } 57 58 finally { 59 } 60 } 61 62 /** 63 * Construct a new CanonicalCombiningClassMap instance for NFC using a particular data source. 64 * 65 * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html#method.new) for more information. 66 */ 67 static createWithProvider(provider) { 68 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 69 70 71 const result = wasm.icu4x_CanonicalCombiningClassMap_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); 72 73 try { 74 if (!diplomatReceive.resultFlag) { 75 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 76 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 77 } 78 return new CanonicalCombiningClassMap(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 79 } 80 81 finally { 82 diplomatReceive.free(); 83 } 84 } 85 86 /** 87 * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMapBorrowed.html#method.get) for more information. 88 * 89 * Additional information: [1](https://docs.rs/icu/latest/icu/properties/props/struct.CanonicalCombiningClass.html) 90 */ 91 get(ch) { 92 93 const result = wasm.icu4x_CanonicalCombiningClassMap_get_mv1(this.ffiValue, ch); 94 95 try { 96 return result; 97 } 98 99 finally { 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 }