| 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 |
|
| 5 |
const ICU4XDataProvider_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 6 |
wasm.ICU4XDataProvider_destroy(underlying); |
| 7 |
}); |
| 8 |
|
| 9 |
export class ICU4XDataProvider { |
| 10 |
#lifetimeEdges = []; |
| 11 |
constructor(underlying, owned, edges) { |
| 12 |
this.underlying = underlying; |
| 13 |
this.#lifetimeEdges.push(...edges); |
| 14 |
if (owned) { |
| 15 |
ICU4XDataProvider_box_destroy_registry.register(this, underlying); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
static create_compiled() { |
| 20 |
return new ICU4XDataProvider(wasm.ICU4XDataProvider_create_compiled(), true, []); |
| 21 |
} |
| 22 |
|
| 23 |
static create_fs(arg_path) { |
| 24 |
const buf_arg_path = diplomatRuntime.DiplomatBuf.str8(wasm, arg_path); |
| 25 |
const diplomat_out = (() => { |
| 26 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 27 |
wasm.ICU4XDataProvider_create_fs(diplomat_receive_buffer, buf_arg_path.ptr, buf_arg_path.size); |
| 28 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 29 |
if (is_ok) { |
| 30 |
const ok_value = new ICU4XDataProvider(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 31 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 32 |
return ok_value; |
| 33 |
} else { |
| 34 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 35 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 36 |
throw new diplomatRuntime.FFIError(throw_value); |
| 37 |
} |
| 38 |
})(); |
| 39 |
buf_arg_path.free(); |
| 40 |
return diplomat_out; |
| 41 |
} |
| 42 |
|
| 43 |
static create_test() { |
| 44 |
return new ICU4XDataProvider(wasm.ICU4XDataProvider_create_test(), true, []); |
| 45 |
} |
| 46 |
|
| 47 |
static create_from_byte_slice(arg_blob) { |
| 48 |
const buf_arg_blob = diplomatRuntime.DiplomatBuf.slice(wasm, arg_blob, "u8"); |
| 49 |
const diplomat_out = (() => { |
| 50 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 51 |
wasm.ICU4XDataProvider_create_from_byte_slice(diplomat_receive_buffer, buf_arg_blob.ptr, buf_arg_blob.size); |
| 52 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 53 |
if (is_ok) { |
| 54 |
const ok_value = new ICU4XDataProvider(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 55 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 56 |
return ok_value; |
| 57 |
} else { |
| 58 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 59 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 60 |
throw new diplomatRuntime.FFIError(throw_value); |
| 61 |
} |
| 62 |
})(); |
| 63 |
buf_arg_blob.leak(); |
| 64 |
return diplomat_out; |
| 65 |
} |
| 66 |
|
| 67 |
static create_empty() { |
| 68 |
return new ICU4XDataProvider(wasm.ICU4XDataProvider_create_empty(), true, []); |
| 69 |
} |
| 70 |
|
| 71 |
fork_by_key(arg_other) { |
| 72 |
return (() => { |
| 73 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 74 |
wasm.ICU4XDataProvider_fork_by_key(diplomat_receive_buffer, this.underlying, arg_other.underlying); |
| 75 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 76 |
if (is_ok) { |
| 77 |
const ok_value = {}; |
| 78 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 79 |
return ok_value; |
| 80 |
} else { |
| 81 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 82 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 83 |
throw new diplomatRuntime.FFIError(throw_value); |
| 84 |
} |
| 85 |
})(); |
| 86 |
} |
| 87 |
|
| 88 |
fork_by_locale(arg_other) { |
| 89 |
return (() => { |
| 90 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 91 |
wasm.ICU4XDataProvider_fork_by_locale(diplomat_receive_buffer, this.underlying, arg_other.underlying); |
| 92 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 93 |
if (is_ok) { |
| 94 |
const ok_value = {}; |
| 95 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 96 |
return ok_value; |
| 97 |
} else { |
| 98 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 99 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 100 |
throw new diplomatRuntime.FFIError(throw_value); |
| 101 |
} |
| 102 |
})(); |
| 103 |
} |
| 104 |
|
| 105 |
enable_locale_fallback() { |
| 106 |
return (() => { |
| 107 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 108 |
wasm.ICU4XDataProvider_enable_locale_fallback(diplomat_receive_buffer, this.underlying); |
| 109 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 110 |
if (is_ok) { |
| 111 |
const ok_value = {}; |
| 112 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 113 |
return ok_value; |
| 114 |
} else { |
| 115 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 116 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 117 |
throw new diplomatRuntime.FFIError(throw_value); |
| 118 |
} |
| 119 |
})(); |
| 120 |
} |
| 121 |
|
| 122 |
enable_locale_fallback_with(arg_fallbacker) { |
| 123 |
return (() => { |
| 124 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 125 |
wasm.ICU4XDataProvider_enable_locale_fallback_with(diplomat_receive_buffer, this.underlying, arg_fallbacker.underlying); |
| 126 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 127 |
if (is_ok) { |
| 128 |
const ok_value = {}; |
| 129 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 130 |
return ok_value; |
| 131 |
} else { |
| 132 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 133 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 134 |
throw new diplomatRuntime.FFIError(throw_value); |
| 135 |
} |
| 136 |
})(); |
| 137 |
} |
| 138 |
} |