-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Normative: Permit serialization of BigInt #3480
Conversation
Primitives are only serialized if they are on the safelist in step 4 of StructuredSerializeInternal. Should we allow them to be serialized too? |
@domenic Thanks for pointing this out; fixed in the new version of the patch. |
source
Outdated
@@ -8127,7 +8127,7 @@ interface <dfn>DOMStringList</dfn> { | |||
<li><p>Let <var>deep</var> be false.</p></li> | |||
|
|||
<li><p>If <span data-x="js-Type">Type</span>(<var>value</var>) is Undefined, Null, Boolean, | |||
String, or Number, then return { [[Type]]: "primitive", [[Value]]: <var>value</var> }.</p></li> | |||
String, BigInt, or Number, then return { [[Type]]: "primitive", [[Value]]: <var>value</var> }.</p></li> |
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.
Is this the same order that the JavaScript specification will use?
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.
I can't find a list containing these three types in the JavaScript specification. The definition of == contains "String, Number, BigInt, or Symbol" but I didn't really give it any thought when I inserted BigInt in that position.
Should we have a total order of JS primitive types, and whenever we have a list, sort them by that order? What should be this total order? I'd like to defer these advanced editorial questions to the JS spec community's more experienced editorialists, e.g., @jmdyck
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.
I was thinking about the order of the section 6.1 subsections.
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.
Speaking of which, is the fact that we omit Symbol here a bug?
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.
No, it seems we made a decision to throw on symbols. I'm not sure why, but they are quite different from other primitives, so maybe it makes sense.
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.
A: Undefined, Null, Boolean, Number, String, Symbol, Object
B: Undefined, Null, Boolean, Number, Symbol, String
C: Undefined, Null, Boolean, String, Symbol, Number, Object
D: Undefined, Null, Boolean, Number, String, Symbol, Object
E: Undefined, Null, Boolean, Number, String, Symbol, Object
F: Undefined, Null, Boolean, Number, String, Symbol, Object
G: Undefined, Null, Boolean, Number, String, Symbol, Object
H: Undefined, Null, Boolean, Number, String, Symbol, Object
I: Undefined, Null, Boolean, String, Symbol, Number, Object
J: Undefined, Null, Boolean, Number, String, Symbol, Object
So a fair bit of consistency, but also some variation.
About the only benefit I can think of for a consistent order is that it makes it easier to check by eye that some list (set of cases) is complete. Mind you, this benefit would increase as more types are added to the language.
About the only disadvantage I can think of is that if you're doing a case analysis, it might make more sense to the reader to describe the handling of Type X before that for Type Y, and those orderings might not be consistent over the whole spec.
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.
I can't remember from who, but I remember hearing some interest in extending structured clone to Symbols. My impression was that it was left out because it'd be somewhat complicated to make the proper global registry so that if you postMessage the symbol around multiple ways, you get the same one (e.g., sending S from A -> B -> C and also A -> C directly, you'd hope to get the same S').
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.
@jmdyck Where do you think BigInt should be inserted in the list?
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.
Adjacent to Number, presumably, but I'm not sure about before or after.
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.
Let's say BigInt goes after Number, unless someone has a preference otherwise.
source
Outdated
@@ -8149,6 +8149,10 @@ interface <dfn>DOMStringList</dfn> { | |||
<var>serialized</var> to { [[Type]]: "Date", [[DateValue]]: <var>value</var>.[[DateValue]] | |||
}.</p></li> | |||
|
|||
<li><p>Otherwise, if <var>value</var> has a [[BigIntValue]] internal slot, then set | |||
<var>serialized</var> to { [[Type]]: "BigInt", [[BigIntValue]]: <var>value</var>.[[BigIntValue]] | |||
}.</p></li> |
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.
I was going to ask about the above aspect here too, but it seems we're already inconsistent in that we put Number before String here...
Rearranged to be consistent with the ordering @jmdyck suggested. |
Design decisions: - BigInts compare greater than Number and less than everything else - No type coercion between BigInt and Number; they are simply distinct, unrelated keys, even if mathematically equal - No BigInt autoIncrement support--53 bits should be enough for anyone BigInts and BigInt wrappers are proposed to be made serializable, and therefore available as IndexedDB values, in whatwg/html#3480 Addresses w3c#230
This looks good to me, although you'll need to add a reference to the BigInt spec similar to https://html.spec.whatwg.org/#import() . (No need for a bulletted list, just a sentence and a bibliography entry.) We'll also need Igalia to sign the participation agreement. Finally we'll need multi-implementer interest. |
Just as @annevk said in our BigInt implementation bug, I also think this should happen. In fact it seems entirely obvious to me that it's needed. |
Agreed with @tschneidereit, this seems like a straightforward and reasonable thing to do. CC @jakobkummerow @GeorgNeis |
Thanks for the pointer. It seems like there are a couple things that would make sense to linkify, so I added a bulleted list.
Done
Does the thread here demonstrate Firefox and Chrome interest? |
source
Outdated
|
||
<ul class="brief"> | ||
<li>The <dfn data-x="js-BigInt" data-x-href="https://tc39.github.io/proposal-bigint/#sec-ecmascript-language-types-bigint-type">BigInt</dfn> type.</li> | ||
<li>The <dfn data-x="js-BigIntData" data-x-href="https://tc39.github.io/proposal-bigint/#sec-toobject">[[BigIntData]]</dfn> internal slot</li> |
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.
Since we don't link these for other primitives, I don't think we should link them here.
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.
What's the reason that other primitives aren't linked?
I was thinking it could be especially useful to link these, since they relate to a new proposal that people who encounter the spec text may not be familiar with.
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.
Basically to match the JS spec.
I'd rather we stay consistent; we could depart from the JS spec and link everything, but I'd rather do that for everything, not just BigInt.
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.
We could add <ref spec=JSBIGINT>
at the end of the lines that use these if we want to give people such a pointer.
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.
Good idea, done.
Yeah, all good to go; I'd just like to revert the extra (inconsistent) linkified terms first. |
The goal of this PR is to integrate BigInt with HTML serialization. This patch - Adds BigInt to the "safe list" of primitives permitted for serialization. - Adds serialization of BigInt wrappers, analogous to other wrappers. Note that BigInt, like (the unserializable) Symbol does not have a new-able constructor: use of wrappers is explicitly discouraged by the specification. Nevertheless, this patch adds serialization support for consistency with other wrappers. web-platform-tests against postMessage on BigInt are out for review in web-platform-tests/wpt#9565
@domenic The current version tries to take your suggestion for references. How does it seem to you? |
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
…ed clone integration, a=testonly Automatic update from web-platform-testsHTML: add tests to verify BigInt structured clone integration See whatwg/html#3480. wpt-commits: c92168a4fbb507dae4f8caa49ecf0dd6d6bf271e wpt-pr: 9565 wpt-commits: c92168a4fbb507dae4f8caa49ecf0dd6d6bf271e wpt-pr: 9565
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
…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
…ed clone integration, a=testonly Automatic update from web-platform-testsHTML: add tests to verify BigInt structured clone integration See whatwg/html#3480. wpt-commits: c92168a4fbb507dae4f8caa49ecf0dd6d6bf271e wpt-pr: 9565 wpt-commits: c92168a4fbb507dae4f8caa49ecf0dd6d6bf271e wpt-pr: 9565 UltraBlame original commit: 4bde644e6c99b069f197a274e239ab5152b1bac9
…ed clone integration, a=testonly Automatic update from web-platform-testsHTML: add tests to verify BigInt structured clone integration See whatwg/html#3480. wpt-commits: c92168a4fbb507dae4f8caa49ecf0dd6d6bf271e wpt-pr: 9565 wpt-commits: c92168a4fbb507dae4f8caa49ecf0dd6d6bf271e wpt-pr: 9565 UltraBlame original commit: 4bde644e6c99b069f197a274e239ab5152b1bac9
…ed clone integration, a=testonly Automatic update from web-platform-testsHTML: add tests to verify BigInt structured clone integration See whatwg/html#3480. wpt-commits: c92168a4fbb507dae4f8caa49ecf0dd6d6bf271e wpt-pr: 9565 wpt-commits: c92168a4fbb507dae4f8caa49ecf0dd6d6bf271e wpt-pr: 9565 UltraBlame original commit: 4bde644e6c99b069f197a274e239ab5152b1bac9
…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
…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
…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
The goal of this PR is to integrate BigInt with HTML serialization.
This patch
serialization.
Note that BigInt, like (the unserializable) Symbol does not have a
new-able constructor: use of wrappers is explicitly discouraged by
the specification. Nevertheless, this patch adds serialization support
for consistency with other wrappers.
web-platform-tests against postMessage on BigInt are out for review in
web-platform-tests/wpt#9565
/infrastructure.html ( diff )
/references.html ( diff )
/structured-data.html ( diff )