1// generated by diplomat-tool 2import { DataError } from "./DataError.mjs" 3import { DataProvider } from "./DataProvider.mjs" 4import { GeneralCategoryGroup } from "./GeneralCategoryGroup.mjs" 5import wasm from "./diplomat-wasm.mjs"; 6import * as diplomatRuntime from "./diplomat-runtime.mjs"; 7 8 9/** A type capable of looking up General Category Group values from a string name. 10* 11*See the [Rust documentation for `PropertyParser`](https://docs.rs/icu/latest/icu/properties/struct.PropertyParser.html) for more information. 12* 13*See the [Rust documentation for `GeneralCategory`](https://docs.rs/icu/latest/icu/properties/props/struct.GeneralCategory.html) for more information. 14*/ 15const GeneralCategoryNameToGroupMapper_box_destroy_registry = new FinalizationRegistry((ptr) => { 16 wasm.icu4x_GeneralCategoryNameToGroupMapper_destroy_mv1(ptr); 17}); 18 19export class GeneralCategoryNameToGroupMapper { 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("GeneralCategoryNameToGroupMapper 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 GeneralCategoryNameToGroupMapper_box_destroy_registry.register(this, this.#ptr); 40 } 41 42 return this; 43 } 44 get ffiValue() { 45 return this.#ptr; 46 } 47 48 getStrict(name) { 49 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 50 51 const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)); 52 53 const result = wasm.icu4x_GeneralCategoryNameToGroupMapper_get_strict_mv1(this.ffiValue, ...nameSlice.splat()); 54 55 try { 56 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 57 } 58 59 finally { 60 functionCleanupArena.free(); 61 } 62 } 63 64 getLoose(name) { 65 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 66 67 const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)); 68 69 const result = wasm.icu4x_GeneralCategoryNameToGroupMapper_get_loose_mv1(this.ffiValue, ...nameSlice.splat()); 70 71 try { 72 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 73 } 74 75 finally { 76 functionCleanupArena.free(); 77 } 78 } 79 80 #defaultConstructor() { 81 const result = wasm.icu4x_GeneralCategoryNameToGroupMapper_create_mv1(); 82 83 try { 84 return new GeneralCategoryNameToGroupMapper(diplomatRuntime.internalConstructor, result, []); 85 } 86 87 finally {} 88 } 89 90 static createWithProvider(provider) { 91 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 92 93 const result = wasm.icu4x_GeneralCategoryNameToGroupMapper_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); 94 95 try { 96 if (!diplomatReceive.resultFlag) { 97 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 98 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 99 } 100 return new GeneralCategoryNameToGroupMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 101 } 102 103 finally { 104 diplomatReceive.free(); 105 } 106 } 107 108 constructor() { 109 if (arguments[0] === diplomatRuntime.exposeConstructor) { 110 return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1)); 111 } else if (arguments[0] === diplomatRuntime.internalConstructor) { 112 return this.#internalConstructor(...arguments); 113 } else { 114 return this.#defaultConstructor(...arguments); 115 } 116 } 117}