Skip to content

Commit de12368

Browse files
Robin Templetonmoz-wptsync-bot
Robin Templeton
authored andcommitted
Bug 1461225 [wpt PR 10977] - Test BigInt as keys and values in IndexedDB, a=testonly
Automatic update from web-platform-testsTest BigInt as keys and values in IndexedDB (#10977) BigInt and BigInt wrappers are supported in serialization, per whatwg/html#3480 This support allows them to be used as IndexedDB values. However, BigInt is not supported as an IndexedDB key; support has been proposed in the following PR, but that change has not landed at the time this patch was written w3c/IndexedDB#231 -- wpt-commits: b2e3e49410657f7bc8adf42070ddef12ce3761d1 wpt-pr: 10977
1 parent 53f0158 commit de12368

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

testing/web-platform/meta/MANIFEST.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309958,6 +309958,12 @@
309958309958
{}
309959309959
]
309960309960
],
309961+
"IndexedDB/bigint_value.htm": [
309962+
[
309963+
"/IndexedDB/bigint_value.htm",
309964+
{}
309965+
]
309966+
],
309961309967
"IndexedDB/bindings-inject-key.html": [
309962309968
[
309963309969
"/IndexedDB/bindings-inject-key.html",
@@ -406201,6 +406207,10 @@
406201406207
"4cd712bd5fed3581ed770c4dbc4200f3a50c5299",
406202406208
"testharness"
406203406209
],
406210+
"IndexedDB/bigint_value.htm": [
406211+
"dcfface11b3fbbf7ba21262d687c2a0f4ed99300",
406212+
"testharness"
406213+
],
406204406214
"IndexedDB/bindings-inject-key.html": [
406205406215
"95f44900d9565baf718be23bafd33e48e6f4fc52",
406206406216
"testharness"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>IndexedDB: BigInt keys and values</title>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script src="support.js"></script>
7+
8+
<script>
9+
// BigInt and BigInt objects are supported in serialization, per
10+
// https://github.com/whatwg/html/pull/3480
11+
// This support allows them to be used as IndexedDB values.
12+
13+
function value_test(value, predicate, name) {
14+
async_test(t => {
15+
t.step(function() {
16+
assert_true(predicate(value),
17+
"Predicate should return true for the initial value.");
18+
});
19+
20+
createdb(t).onupgradeneeded = t.step_func(e => {
21+
e.target.result
22+
.createObjectStore("store")
23+
.add(value, 1);
24+
25+
e.target.onsuccess = t.step_func(e => {
26+
e.target.result
27+
.transaction("store")
28+
.objectStore("store")
29+
.get(1)
30+
.onsuccess = t.step_func(e =>
31+
{
32+
assert_true(predicate(e.target.result),
33+
"Predicate should return true for the deserialized result.");
34+
t.done();
35+
});
36+
});
37+
});
38+
}, "BigInts as values in IndexedDB - " + name);
39+
}
40+
41+
value_test(1n,
42+
x => x === 1n,
43+
"primitive BigInt");
44+
value_test(Object(1n),
45+
x => typeof x === 'object' &&
46+
x instanceof BigInt &&
47+
x.valueOf() === 1n,
48+
"BigInt object");
49+
value_test({val: 1n},
50+
x => x.val === 1n,
51+
"primitive BigInt inside object");
52+
value_test({val: Object(1n)},
53+
x => x.val.valueOf() === 1n &&
54+
x.val instanceof BigInt &&
55+
x.val.valueOf() === 1n,
56+
"BigInt object inside object");
57+
58+
// However, BigInt is not supported as an IndexedDB key; support
59+
// has been proposed in the following PR, but that change has not
60+
// landed at the time this patch was written
61+
// https://github.com/w3c/IndexedDB/pull/231
62+
63+
function invalidKey(key, name) {
64+
test(t => {
65+
assert_throws("DataError", () => indexedDB.cmp(0, key));
66+
}, "BigInts as keys in IndexedDB - " + name);
67+
}
68+
69+
invalidKey(1n, "primitive BigInt");
70+
// Still an error even if the IndexedDB patch lands
71+
invalidKey(Object(1n), "BigInt object");
72+
</script>

0 commit comments

Comments
 (0)