| 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 { ICU4XFixedDecimalGroupingStrategy_js_to_rust, ICU4XFixedDecimalGroupingStrategy_rust_to_js } from "./ICU4XFixedDecimalGroupingStrategy.mjs" |
| 5 |
|
| 6 |
const ICU4XFixedDecimalFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 7 |
wasm.ICU4XFixedDecimalFormatter_destroy(underlying); |
| 8 |
}); |
| 9 |
|
| 10 |
export class ICU4XFixedDecimalFormatter { |
| 11 |
#lifetimeEdges = []; |
| 12 |
constructor(underlying, owned, edges) { |
| 13 |
this.underlying = underlying; |
| 14 |
this.#lifetimeEdges.push(...edges); |
| 15 |
if (owned) { |
| 16 |
ICU4XFixedDecimalFormatter_box_destroy_registry.register(this, underlying); |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
static create_with_grouping_strategy(arg_provider, arg_locale, arg_grouping_strategy) { |
| 21 |
return (() => { |
| 22 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 23 |
wasm.ICU4XFixedDecimalFormatter_create_with_grouping_strategy(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ICU4XFixedDecimalGroupingStrategy_js_to_rust[arg_grouping_strategy]); |
| 24 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 25 |
if (is_ok) { |
| 26 |
const ok_value = new ICU4XFixedDecimalFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 27 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 28 |
return ok_value; |
| 29 |
} else { |
| 30 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 31 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 32 |
throw new diplomatRuntime.FFIError(throw_value); |
| 33 |
} |
| 34 |
})(); |
| 35 |
} |
| 36 |
|
| 37 |
static create_with_decimal_symbols_v1(arg_data_struct, arg_grouping_strategy) { |
| 38 |
return (() => { |
| 39 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 40 |
wasm.ICU4XFixedDecimalFormatter_create_with_decimal_symbols_v1(diplomat_receive_buffer, arg_data_struct.underlying, ICU4XFixedDecimalGroupingStrategy_js_to_rust[arg_grouping_strategy]); |
| 41 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 42 |
if (is_ok) { |
| 43 |
const ok_value = new ICU4XFixedDecimalFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 44 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 45 |
return ok_value; |
| 46 |
} else { |
| 47 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 48 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 49 |
throw new diplomatRuntime.FFIError(throw_value); |
| 50 |
} |
| 51 |
})(); |
| 52 |
} |
| 53 |
|
| 54 |
format(arg_value) { |
| 55 |
return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 56 |
return (() => { |
| 57 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 58 |
wasm.ICU4XFixedDecimalFormatter_format(diplomat_receive_buffer, this.underlying, arg_value.underlying, writeable); |
| 59 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 60 |
if (is_ok) { |
| 61 |
const ok_value = {}; |
| 62 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 63 |
return ok_value; |
| 64 |
} else { |
| 65 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 66 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 67 |
throw new diplomatRuntime.FFIError(throw_value); |
| 68 |
} |
| 69 |
})(); |
| 70 |
}); |
| 71 |
} |
| 72 |
} |