| 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 { ICU4XListLength_js_to_rust, ICU4XListLength_rust_to_js } from "./ICU4XListLength.mjs" |
| 5 |
|
| 6 |
const ICU4XListFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 7 |
wasm.ICU4XListFormatter_destroy(underlying); |
| 8 |
}); |
| 9 |
|
| 10 |
export class ICU4XListFormatter { |
| 11 |
#lifetimeEdges = []; |
| 12 |
constructor(underlying, owned, edges) { |
| 13 |
this.underlying = underlying; |
| 14 |
this.#lifetimeEdges.push(...edges); |
| 15 |
if (owned) { |
| 16 |
ICU4XListFormatter_box_destroy_registry.register(this, underlying); |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
static create_and_with_length(arg_provider, arg_locale, arg_length) { |
| 21 |
return (() => { |
| 22 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 23 |
wasm.ICU4XListFormatter_create_and_with_length(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ICU4XListLength_js_to_rust[arg_length]); |
| 24 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 25 |
if (is_ok) { |
| 26 |
const ok_value = new ICU4XListFormatter(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_or_with_length(arg_provider, arg_locale, arg_length) { |
| 38 |
return (() => { |
| 39 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 40 |
wasm.ICU4XListFormatter_create_or_with_length(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ICU4XListLength_js_to_rust[arg_length]); |
| 41 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 42 |
if (is_ok) { |
| 43 |
const ok_value = new ICU4XListFormatter(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 |
static create_unit_with_length(arg_provider, arg_locale, arg_length) { |
| 55 |
return (() => { |
| 56 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 57 |
wasm.ICU4XListFormatter_create_unit_with_length(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ICU4XListLength_js_to_rust[arg_length]); |
| 58 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 59 |
if (is_ok) { |
| 60 |
const ok_value = new ICU4XListFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 61 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 62 |
return ok_value; |
| 63 |
} else { |
| 64 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 65 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 66 |
throw new diplomatRuntime.FFIError(throw_value); |
| 67 |
} |
| 68 |
})(); |
| 69 |
} |
| 70 |
|
| 71 |
format(arg_list) { |
| 72 |
return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 73 |
return (() => { |
| 74 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 75 |
wasm.ICU4XListFormatter_format(diplomat_receive_buffer, this.underlying, arg_list.underlying, writeable); |
| 76 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 77 |
if (is_ok) { |
| 78 |
const ok_value = {}; |
| 79 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 80 |
return ok_value; |
| 81 |
} else { |
| 82 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 83 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 84 |
throw new diplomatRuntime.FFIError(throw_value); |
| 85 |
} |
| 86 |
})(); |
| 87 |
}); |
| 88 |
} |
| 89 |
} |