Skip to content

Commit

Permalink
Bug 1461225 [wpt PR 10977] - Test BigInt as keys and values in Indexe…
Browse files Browse the repository at this point in the history
…dDB, 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

UltraBlame original commit: 57ffaa0dbfa1639f73937cf7af08367a466b8eda
  • Loading branch information
marco-c committed Oct 3, 2019
1 parent 03dd318 commit d3a0ac2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
10 changes: 10 additions & 0 deletions testing/web-platform/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -309958,6 +309958,12 @@
{}
]
],
"IndexedDB/bigint_value.htm": [
[
"/IndexedDB/bigint_value.htm",
{}
]
],
"IndexedDB/bindings-inject-key.html": [
[
"/IndexedDB/bindings-inject-key.html",
Expand Down Expand Up @@ -406201,6 +406207,10 @@
"4cd712bd5fed3581ed770c4dbc4200f3a50c5299",
"testharness"
],
"IndexedDB/bigint_value.htm": [
"dcfface11b3fbbf7ba21262d687c2a0f4ed99300",
"testharness"
],
"IndexedDB/bindings-inject-key.html": [
"95f44900d9565baf718be23bafd33e48e6f4fc52",
"testharness"
Expand Down
72 changes: 72 additions & 0 deletions testing/web-platform/tests/IndexedDB/bigint_value.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IndexedDB: BigInt keys and values</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<script>
// BigInt and BigInt objects are supported in serialization, per
// https://github.com/whatwg/html/pull/3480
// This support allows them to be used as IndexedDB values.

function value_test(value, predicate, name) {
async_test(t => {
t.step(function() {
assert_true(predicate(value),
"Predicate should return true for the initial value.");
});

createdb(t).onupgradeneeded = t.step_func(e => {
e.target.result
.createObjectStore("store")
.add(value, 1);

e.target.onsuccess = t.step_func(e => {
e.target.result
.transaction("store")
.objectStore("store")
.get(1)
.onsuccess = t.step_func(e =>
{
assert_true(predicate(e.target.result),
"Predicate should return true for the deserialized result.");
t.done();
});
});
});
}, "BigInts as values in IndexedDB - " + name);
}

value_test(1n,
x => x === 1n,
"primitive BigInt");
value_test(Object(1n),
x => typeof x === 'object' &&
x instanceof BigInt &&
x.valueOf() === 1n,
"BigInt object");
value_test({val: 1n},
x => x.val === 1n,
"primitive BigInt inside object");
value_test({val: Object(1n)},
x => x.val.valueOf() === 1n &&
x.val instanceof BigInt &&
x.val.valueOf() === 1n,
"BigInt object inside object");

// 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
// https://github.com/w3c/IndexedDB/pull/231

function invalidKey(key, name) {
test(t => {
assert_throws("DataError", () => indexedDB.cmp(0, key));
}, "BigInts as keys in IndexedDB - " + name);
}

invalidKey(1n, "primitive BigInt");
// Still an error even if the IndexedDB patch lands
invalidKey(Object(1n), "BigInt object");
</script>

0 comments on commit d3a0ac2

Please sign in to comment.