| 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 ICU4XTime_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 6 |
wasm.ICU4XTime_destroy(underlying); |
| 7 |
}); |
| 8 |
|
| 9 |
export class ICU4XTime { |
| 10 |
#lifetimeEdges = []; |
| 11 |
constructor(underlying, owned, edges) { |
| 12 |
this.underlying = underlying; |
| 13 |
this.#lifetimeEdges.push(...edges); |
| 14 |
if (owned) { |
| 15 |
ICU4XTime_box_destroy_registry.register(this, underlying); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
static create(arg_hour, arg_minute, arg_second, arg_nanosecond) { |
| 20 |
return (() => { |
| 21 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 22 |
wasm.ICU4XTime_create(diplomat_receive_buffer, arg_hour, arg_minute, arg_second, arg_nanosecond); |
| 23 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 24 |
if (is_ok) { |
| 25 |
const ok_value = new ICU4XTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 26 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 27 |
return ok_value; |
| 28 |
} else { |
| 29 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 30 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 31 |
throw new diplomatRuntime.FFIError(throw_value); |
| 32 |
} |
| 33 |
})(); |
| 34 |
} |
| 35 |
|
| 36 |
static create_midnight() { |
| 37 |
return (() => { |
| 38 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 39 |
wasm.ICU4XTime_create_midnight(diplomat_receive_buffer); |
| 40 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 41 |
if (is_ok) { |
| 42 |
const ok_value = new ICU4XTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 43 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 44 |
return ok_value; |
| 45 |
} else { |
| 46 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 47 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 48 |
throw new diplomatRuntime.FFIError(throw_value); |
| 49 |
} |
| 50 |
})(); |
| 51 |
} |
| 52 |
|
| 53 |
hour() { |
| 54 |
return wasm.ICU4XTime_hour(this.underlying); |
| 55 |
} |
| 56 |
|
| 57 |
minute() { |
| 58 |
return wasm.ICU4XTime_minute(this.underlying); |
| 59 |
} |
| 60 |
|
| 61 |
second() { |
| 62 |
return wasm.ICU4XTime_second(this.underlying); |
| 63 |
} |
| 64 |
|
| 65 |
nanosecond() { |
| 66 |
return wasm.ICU4XTime_nanosecond(this.underlying); |
| 67 |
} |
| 68 |
} |