Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test BigInt as keys and values in IndexedDB #9667

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions IndexedDB/bigint_value.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Values</title>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe clarify the name: BigInts as Values and Keys in IndexedDB ?

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

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

let i = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this unique_test_id to make the usage clear?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But see below...

function value(value, test) {
var t = async_test(document.title + " - " + (i++));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: I find the async_test(t => { /*test body... */ }, description); form more readable, and it appears to be more common.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if the test name said something about what was being tested in this case; rather than document.title, how about "BigInts as values in IndexedDB"

This really helps implementers/reviewers when looking a big table of failures: you can tell what the failure was without reading the test.

Can this be passed in to the value() function rather than just using numbers, so it's clear what each case does?

t.step(function() {
assert_true(test(value),
"condition does not apply to initial value");
});

createdb(t).onupgradeneeded = function(e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap the function in t.step_func() so that unexpected exceptions thrown in the async callback are tied to the test, e.g.

createdb(t).onupgradeneeded = t.step_func(e => { ... });

e.target.result
.createObjectStore("store")
.add(value, 1);

e.target.onsuccess = t.step_func(function(e) {
e.target.result
.transaction("store")
.objectStore("store")
.get(1)
.onsuccess = t.step_func(function(e)
{
assert_true(test(e.target.result),
"condition does not apply to deserialized result")
t.done();
});
});
};
}

value(1n, x => x === 1n);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add case where it's not the top-level record, e.g. {val: 1n} ?

value(Object(1n), x => typeof x === 'object' && x instanceof BigInt
&& x.valueOf() === 1n);

// 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) {
var t = async_test(document.title + " - " + (i++));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above, re: style and description.


createdb(t).onupgradeneeded = function(e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.step_func is needed here too.

let store = e.target.result.createObjectStore("store")
assert_throws('DataError', () => store.add(1, key));
t.done();
};
}

invalidKey(1n);
invalidKey(Object(1n)); // Still an error even if the IndexedDB patch lands

</script>

<div id="log"></div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed; testharness will create this dynamically as needed