| 1 |
import wasm from "./diplomat-wasm.mjs" |
| 2 |
import * as diplomatRuntime from "./diplomat-runtime.mjs" |
| 3 |
import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs" |
| 4 |
import { ICU4XLocaleFallbackPriority_js_to_rust, ICU4XLocaleFallbackPriority_rust_to_js } from "./ICU4XLocaleFallbackPriority.mjs" |
| 5 |
import { ICU4XLocaleFallbackSupplement_js_to_rust, ICU4XLocaleFallbackSupplement_rust_to_js } from "./ICU4XLocaleFallbackSupplement.mjs" |
| 6 |
import { ICU4XLocaleFallbackerWithConfig } from "./ICU4XLocaleFallbackerWithConfig.mjs" |
| 7 |
|
| 8 |
const ICU4XLocaleFallbacker_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 9 |
wasm.ICU4XLocaleFallbacker_destroy(underlying); |
| 10 |
}); |
| 11 |
|
| 12 |
export class ICU4XLocaleFallbacker { |
| 13 |
#lifetimeEdges = []; |
| 14 |
constructor(underlying, owned, edges) { |
| 15 |
this.underlying = underlying; |
| 16 |
this.#lifetimeEdges.push(...edges); |
| 17 |
if (owned) { |
| 18 |
ICU4XLocaleFallbacker_box_destroy_registry.register(this, underlying); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
static create(arg_provider) { |
| 23 |
return (() => { |
| 24 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 25 |
wasm.ICU4XLocaleFallbacker_create(diplomat_receive_buffer, arg_provider.underlying); |
| 26 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 27 |
if (is_ok) { |
| 28 |
const ok_value = new ICU4XLocaleFallbacker(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 29 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 30 |
return ok_value; |
| 31 |
} else { |
| 32 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 33 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 34 |
throw new diplomatRuntime.FFIError(throw_value); |
| 35 |
} |
| 36 |
})(); |
| 37 |
} |
| 38 |
|
| 39 |
static create_without_data() { |
| 40 |
return new ICU4XLocaleFallbacker(wasm.ICU4XLocaleFallbacker_create_without_data(), true, []); |
| 41 |
} |
| 42 |
|
| 43 |
for_config(arg_config) { |
| 44 |
const field_priority_arg_config = arg_config["priority"]; |
| 45 |
const field_extension_key_arg_config = arg_config["extension_key"]; |
| 46 |
const buf_field_extension_key_arg_config = diplomatRuntime.DiplomatBuf.str8(wasm, field_extension_key_arg_config); |
| 47 |
const field_fallback_supplement_arg_config = arg_config["fallback_supplement"]; |
| 48 |
const diplomat_out = (() => { |
| 49 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 50 |
wasm.ICU4XLocaleFallbacker_for_config(diplomat_receive_buffer, this.underlying, ICU4XLocaleFallbackPriority_js_to_rust[field_priority_arg_config], buf_field_extension_key_arg_config.ptr, buf_field_extension_key_arg_config.size, ICU4XLocaleFallbackSupplement_js_to_rust[field_fallback_supplement_arg_config]); |
| 51 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 52 |
if (is_ok) { |
| 53 |
const ok_value = new ICU4XLocaleFallbackerWithConfig(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, [this]); |
| 54 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 55 |
return ok_value; |
| 56 |
} else { |
| 57 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 58 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 59 |
throw new diplomatRuntime.FFIError(throw_value); |
| 60 |
} |
| 61 |
})(); |
| 62 |
buf_field_extension_key_arg_config.free(); |
| 63 |
return diplomat_out; |
| 64 |
} |
| 65 |
} |