LocaleDirectionality.mjs (6317B)
1 // generated by diplomat-tool 2 import { DataError } from "./DataError.mjs" 3 import { DataProvider } from "./DataProvider.mjs" 4 import { Locale } from "./Locale.mjs" 5 import { LocaleDirection } from "./LocaleDirection.mjs" 6 import wasm from "./diplomat-wasm.mjs"; 7 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 8 9 10 /** 11 * See the [Rust documentation for `LocaleDirectionality`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html) for more information. 12 */ 13 const LocaleDirectionality_box_destroy_registry = new FinalizationRegistry((ptr) => { 14 wasm.icu4x_LocaleDirectionality_destroy_mv1(ptr); 15 }); 16 17 export class LocaleDirectionality { 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("LocaleDirectionality 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 LocaleDirectionality_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 LocaleDirectionality instance using compiled data. 47 * 48 * See the [Rust documentation for `new_common`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.new_common) for more information. 49 */ 50 #defaultConstructor() { 51 52 const result = wasm.icu4x_LocaleDirectionality_create_common_mv1(); 53 54 try { 55 return new LocaleDirectionality(diplomatRuntime.internalConstructor, result, []); 56 } 57 58 finally { 59 } 60 } 61 62 /** 63 * Construct a new LocaleDirectionality instance using a particular data source. 64 * 65 * See the [Rust documentation for `new_common`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.new_common) for more information. 66 */ 67 static createCommonWithProvider(provider) { 68 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 69 70 71 const result = wasm.icu4x_LocaleDirectionality_create_common_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 LocaleDirectionality(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 79 } 80 81 finally { 82 diplomatReceive.free(); 83 } 84 } 85 86 /** 87 * Construct a new LocaleDirectionality instance using compiled data. 88 * 89 * See the [Rust documentation for `new_extended`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.new_extended) for more information. 90 */ 91 static createExtended() { 92 93 const result = wasm.icu4x_LocaleDirectionality_create_extended_mv1(); 94 95 try { 96 return new LocaleDirectionality(diplomatRuntime.internalConstructor, result, []); 97 } 98 99 finally { 100 } 101 } 102 103 /** 104 * Construct a new LocaleDirectionality instance using a particular data source. 105 * 106 * See the [Rust documentation for `new_extended`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.new_extended) for more information. 107 */ 108 static createExtendedWithProvider(provider) { 109 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 110 111 112 const result = wasm.icu4x_LocaleDirectionality_create_extended_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); 113 114 try { 115 if (!diplomatReceive.resultFlag) { 116 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 117 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 118 } 119 return new LocaleDirectionality(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 120 } 121 122 finally { 123 diplomatReceive.free(); 124 } 125 } 126 127 /** 128 * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.get) for more information. 129 */ 130 get(locale) { 131 132 const result = wasm.icu4x_LocaleDirectionality_get_mv1(this.ffiValue, locale.ffiValue); 133 134 try { 135 return new LocaleDirection(diplomatRuntime.internalConstructor, result); 136 } 137 138 finally { 139 } 140 } 141 142 /** 143 * See the [Rust documentation for `is_left_to_right`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.is_left_to_right) for more information. 144 */ 145 isLeftToRight(locale) { 146 147 const result = wasm.icu4x_LocaleDirectionality_is_left_to_right_mv1(this.ffiValue, locale.ffiValue); 148 149 try { 150 return result; 151 } 152 153 finally { 154 } 155 } 156 157 /** 158 * See the [Rust documentation for `is_right_to_left`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.is_right_to_left) for more information. 159 */ 160 isRightToLeft(locale) { 161 162 const result = wasm.icu4x_LocaleDirectionality_is_right_to_left_mv1(this.ffiValue, locale.ffiValue); 163 164 try { 165 return result; 166 } 167 168 finally { 169 } 170 } 171 172 constructor() { 173 if (arguments[0] === diplomatRuntime.exposeConstructor) { 174 return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1)); 175 } else if (arguments[0] === diplomatRuntime.internalConstructor) { 176 return this.#internalConstructor(...arguments); 177 } else { 178 return this.#defaultConstructor(...arguments); 179 } 180 } 181 }