-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Values</title> | ||
<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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call this There was a problem hiding this comment. Choose a reason for hiding this commentThe 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++)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style nit: I find the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
t.step(function() { | ||
assert_true(test(value), | ||
"condition does not apply to initial value"); | ||
}); | ||
|
||
createdb(t).onupgradeneeded = function(e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add case where it's not the top-level record, e.g. |
||
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++)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed; testharness will create this dynamically as needed |
There was a problem hiding this comment.
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 ?