aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Tarnawski <gthetarnav@gmail.com>2023-10-19 18:45:04 +0200
committerDamian Tarnawski <gthetarnav@gmail.com>2023-10-19 18:45:04 +0200
commitc19af95db0a965ce49864f0881778cdddf305291 (patch)
treecd16618f64c3b98cd8b087a581517392221474b8
parent840459bdb09690ff34814af5a99eb29a40637d1e (diff)
Fix calling time.now() in wasm js runtime
-rw-r--r--core/time/time_js.odin4
-rw-r--r--vendor/wasm/js/runtime.js11
2 files changed, 5 insertions, 10 deletions
diff --git a/core/time/time_js.odin b/core/time/time_js.odin
index 226f921f9..932fc2b8e 100644
--- a/core/time/time_js.odin
+++ b/core/time/time_js.odin
@@ -10,7 +10,7 @@ _now :: proc "contextless" () -> Time {
foreign odin_env {
time_now :: proc "contextless" () -> i64 ---
}
- return Time{time_now()}
+ return Time{time_now()*1e6}
}
_sleep :: proc "contextless" (d: Duration) {
@@ -26,7 +26,7 @@ _tick_now :: proc "contextless" () -> Tick {
foreign odin_env {
tick_now :: proc "contextless" () -> i64 ---
}
- return Tick{tick_now()}
+ return Tick{tick_now()*1e6}
}
_yield :: proc "contextless" () {
diff --git a/vendor/wasm/js/runtime.js b/vendor/wasm/js/runtime.js
index 8ab73338a..77344bea8 100644
--- a/vendor/wasm/js/runtime.js
+++ b/vendor/wasm/js/runtime.js
@@ -1334,14 +1334,9 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
abort: () => { Module.abort() },
evaluate: (str_ptr, str_len) => { eval.call(null, wasmMemoryInterface.loadString(str_ptr, str_len)); },
- time_now: () => {
- // convert ms to ns
- return Date.now() * 1e6;
- },
- tick_now: () => {
- // convert ms to ns
- return performance.now() * 1e6;
- },
+ // return a bigint to be converted to i64
+ time_now: () => BigInt(Date.now()),
+ tick_now: () => BigInt(performance.now()),
time_sleep: (duration_ms) => {
if (duration_ms > 0) {
// TODO(bill): Does this even make any sense?