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

Normative: Permit serialization of BigInt #3480

Merged
merged 2 commits into from
Feb 26, 2018
Merged

Conversation

littledan
Copy link
Contributor

@littledan littledan commented Feb 17, 2018

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


/infrastructure.html ( diff )
/references.html ( diff )
/structured-data.html ( diff )

@domenic
Copy link
Member

domenic commented Feb 17, 2018

Primitives are only serialized if they are on the safelist in step 4 of StructuredSerializeInternal. Should we allow them to be serialized too?

@littledan
Copy link
Contributor Author

@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>
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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').

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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>
Copy link
Member

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...

@littledan
Copy link
Contributor Author

Rearranged to be consistent with the ordering @jmdyck suggested.

littledan added a commit to littledan/IndexedDB that referenced this pull request Feb 19, 2018
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
@domenic
Copy link
Member

domenic commented Feb 20, 2018

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.

@domenic domenic added the needs implementer interest Moving the issue forward requires implementers to express interest label Feb 20, 2018
@tschneidereit
Copy link

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.

@ajklein
Copy link
Contributor

ajklein commented Feb 21, 2018

Agreed with @tschneidereit, this seems like a straightforward and reasonable thing to do. CC @jakobkummerow @GeorgNeis

@domenic domenic removed the needs implementer interest Moving the issue forward requires implementers to express interest label Feb 21, 2018
@littledan
Copy link
Contributor Author

@domenic

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.)

Thanks for the pointer. It seems like there are a couple things that would make sense to linkify, so I added a bulleted list.

We'll also need Igalia to sign the participation agreement.

Done

Finally we'll need multi-implementer interest.

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>
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, done.

@domenic
Copy link
Member

domenic commented Feb 22, 2018

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
@littledan
Copy link
Contributor Author

@domenic The current version tries to take your suggestion for references. How does it seem to you?

@domenic domenic merged commit 01bc5df into whatwg:master Feb 26, 2018
annevk pushed a commit to web-platform-tests/wpt that referenced this pull request Feb 26, 2018
littledan added a commit to littledan/web-platform-tests that referenced this pull request Feb 26, 2018
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
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Apr 1, 2018
…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
inexorabletash pushed a commit to web-platform-tests/wpt that referenced this pull request May 22, 2018
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
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request May 25, 2018
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 2, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 2, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 2, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 3, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 3, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 3, 2019
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

6 participants