1// generated by diplomat-tool 2import { DataError } from "./DataError.mjs" 3import { DataProvider } from "./DataProvider.mjs" 4import { TimeZoneAndCanonicalAndNormalized } from "./TimeZoneAndCanonicalAndNormalized.mjs" 5import { TimeZoneAndCanonicalAndNormalizedIterator } from "./TimeZoneAndCanonicalAndNormalizedIterator.mjs" 6import { TimeZoneAndCanonicalIterator } from "./TimeZoneAndCanonicalIterator.mjs" 7import wasm from "./diplomat-wasm.mjs"; 8import * as diplomatRuntime from "./diplomat-runtime.mjs"; 9 10 11/** A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. 12* 13*This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. 14*It also supports normalizing and canonicalizing the IANA strings. 15* 16*See the [Rust documentation for `IanaParserExtended`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtended.html) for more information. 17*/ 18const IanaParserExtended_box_destroy_registry = new FinalizationRegistry((ptr) => { 19 wasm.icu4x_IanaParserExtended_destroy_mv1(ptr); 20}); 21 22export class IanaParserExtended { 23 24 // Internal ptr reference: 25 #ptr = null; 26 27 // Lifetimes are only to keep dependencies alive. 28 // Since JS won't garbage collect until there are no incoming edges. 29 #selfEdge = []; 30 31 #internalConstructor(symbol, ptr, selfEdge) { 32 if (symbol !== diplomatRuntime.internalConstructor) { 33 console.error("IanaParserExtended is an Opaque type. You cannot call its constructor."); 34 return; 35 } 36 37 this.#ptr = ptr; 38 this.#selfEdge = selfEdge; 39 40 // Are we being borrowed? If not, we can register. 41 if (this.#selfEdge.length === 0) { 42 IanaParserExtended_box_destroy_registry.register(this, this.#ptr); 43 } 44 45 return this; 46 } 47 get ffiValue() { 48 return this.#ptr; 49 } 50 51 #defaultConstructor() { 52 const result = wasm.icu4x_IanaParserExtended_create_mv1(); 53 54 try { 55 return new IanaParserExtended(diplomatRuntime.internalConstructor, result, []); 56 } 57 58 finally {} 59 } 60 61 static createWithProvider(provider) { 62 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 63 64 const result = wasm.icu4x_IanaParserExtended_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); 65 66 try { 67 if (!diplomatReceive.resultFlag) { 68 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 69 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 70 } 71 return new IanaParserExtended(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 72 } 73 74 finally { 75 diplomatReceive.free(); 76 } 77 } 78 79 parse(value) { 80 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 81 82 const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)); 83 84 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 20, 4, false); 85 86 // This lifetime edge depends on lifetimes 'a 87 let aEdges = [this]; 88 89 const result = wasm.icu4x_IanaParserExtended_parse_mv1(diplomatReceive.buffer, this.ffiValue, ...valueSlice.splat()); 90 91 try { 92 return TimeZoneAndCanonicalAndNormalized._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer, aEdges); 93 } 94 95 finally { 96 functionCleanupArena.free(); 97 98 diplomatReceive.free(); 99 } 100 } 101 102 iter() { 103 // This lifetime edge depends on lifetimes 'a 104 let aEdges = [this]; 105 106 const result = wasm.icu4x_IanaParserExtended_iter_mv1(this.ffiValue); 107 108 try { 109 return new TimeZoneAndCanonicalIterator(diplomatRuntime.internalConstructor, result, [], aEdges); 110 } 111 112 finally {} 113 } 114 115 iterAll() { 116 // This lifetime edge depends on lifetimes 'a 117 let aEdges = [this]; 118 119 const result = wasm.icu4x_IanaParserExtended_iter_all_mv1(this.ffiValue); 120 121 try { 122 return new TimeZoneAndCanonicalAndNormalizedIterator(diplomatRuntime.internalConstructor, result, [], aEdges); 123 } 124 125 finally {} 126 } 127 128 constructor() { 129 if (arguments[0] === diplomatRuntime.exposeConstructor) { 130 return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1)); 131 } else if (arguments[0] === diplomatRuntime.internalConstructor) { 132 return this.#internalConstructor(...arguments); 133 } else { 134 return this.#defaultConstructor(...arguments); 135 } 136 } 137}