From 47551fc6fa2678c5e0351e2218ae3e1a1c77c742 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Tue, 2 Sep 2025 09:36:41 -0700 Subject: [PATCH] indexeddb: Finish implementation of key_type_to_jsval (#39008) Uses clipped time to convert dates that are stored as `f64`s into JS values. Testing: WPT Fixes: #25327 --------- Signed-off-by: Ashwin Naren --- components/script/indexed_db.rs | 7 ++++--- .../wpt/meta/IndexedDB/crashtests/create-index.any.js.ini | 2 +- tests/wpt/meta/IndexedDB/idbfactory_open.any.js.ini | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/components/script/indexed_db.rs b/components/script/indexed_db.rs index fc022b71bce..3da10316685 100644 --- a/components/script/indexed_db.rs +++ b/components/script/indexed_db.rs @@ -51,9 +51,10 @@ pub fn key_type_to_jsval( IndexedDBKeyType::Number(n) => result.set(DoubleValue(*n)), IndexedDBKeyType::String(s) => s.safe_to_jsval(cx, result), IndexedDBKeyType::Binary(b) => b.safe_to_jsval(cx, result), - IndexedDBKeyType::Date(_d) => { - // TODO: implement this when Date's representation is finalized. - result.set(UndefinedValue()); + IndexedDBKeyType::Date(d) => { + let time = js::jsapi::ClippedTime { t: *d }; + let date = unsafe { js::jsapi::NewDateObject(*cx, time) }; + date.safe_to_jsval(cx, result); }, IndexedDBKeyType::Array(a) => { rooted_vec!(let mut values <- repeat_n(UndefinedValue(), a.len())); diff --git a/tests/wpt/meta/IndexedDB/crashtests/create-index.any.js.ini b/tests/wpt/meta/IndexedDB/crashtests/create-index.any.js.ini index 1732fc6bad3..ffe92f91853 100644 --- a/tests/wpt/meta/IndexedDB/crashtests/create-index.any.js.ini +++ b/tests/wpt/meta/IndexedDB/crashtests/create-index.any.js.ini @@ -5,7 +5,7 @@ [create-index.any.worker.html] - expected: CRASH + expected: TIMEOUT [Assure no crash when populating index] expected: TIMEOUT diff --git a/tests/wpt/meta/IndexedDB/idbfactory_open.any.js.ini b/tests/wpt/meta/IndexedDB/idbfactory_open.any.js.ini index 8c9c0fd484e..5d0bb8190b3 100644 --- a/tests/wpt/meta/IndexedDB/idbfactory_open.any.js.ini +++ b/tests/wpt/meta/IndexedDB/idbfactory_open.any.js.ini @@ -14,6 +14,9 @@ [Calling open() with version argument 9007199254740991 should not throw.] expected: FAIL + [Calling open() with version argument 1.5 should not throw.] + expected: FAIL + [idbfactory_open.any.sharedworker.html] expected: ERROR