Closed Bug 1375829 Opened 7 years ago Closed 6 years ago

[WebIDL] Replace serializers/jsonifiers with toJSON and [Default] extended attribute

Categories

(Core :: DOM: Bindings (WebIDL), defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla62
Tracking Status
firefox62 --- fixed

People

(Reporter: tobie.langel, Assigned: bzbarsky, Mentored)

References

(Blocks 1 open bug)

Details

Attachments

(5 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

Steps to reproduce:

We just removed serializers[1] from WebIDL and allowed editors to specify toJSON operations[2] directly instead (WebIDL treated toJSON as a reserved identifier up until now).

To deal with common cases, we added a new [Default] extended attribute[3] which triggers the default toJSON operation[4] that behaves *very* similarly to how jsonifier does.

All serializer-related productions were removed from the WebIDL grammar. In particular the following non-terminals:

* Serializer
    * Serializer was also removed from the rhs expression of InterfaceMember.
* SerializerRest
* OperationRest
* SerializationPattern
* SerializationPatternMap
* SerializationPatternList

and the following terminals:

* "serializer" in ArgumentNameKeyword.

As usual, please feel free to reach out if anything needs clarification or if you have questions.

Thanks!

[1]: https://github.com/heycam/webidl/pull/323
[2]: https://heycam.github.io/webidl/#idl-tojson-operation
[3]: https://heycam.github.io/webidl/#Default
[4]]: https://heycam.github.io/webidl/#es-default-tojson
So I guess in practice we need to remove "serializer" from keywords and "SERIALIZER" from the ArgumentName production.

Then we probaly want to nix jsonifier and implement the [Default] toJSON thing.  And check how it differs from what we do right now.

This is a pretty good bug for someone who wants to learn about our IDL parser and codegen.  I'm happy to mentor.
Mentor: bzbarsky
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: [WebIDL] Replace serializers with toJSON and [Default] extended attribute → [WebIDL] Replace serializers/jsonifiers with toJSON and [Default] extended attribute
And as an implementation note, we can probably keep most of our infrastructure in place and just make isJsonifier() test true when [Default] is used on a method called toJSON.  [Default] used on anything else should fail parsing.
Hi Eden, this matches your interests. Do you wanna try this one?

Hi Boris, I am inferring this is something we'd like to see happening in the near future but not with urgency, correct?
Flags: needinfo?(echuang)
Flags: needinfo?(bzbarsky)
That looks interesting to me, I will take this bug.
Flags: needinfo?(echuang)
> something we'd like to see happening in the near future but not with urgency

Exactly.
Flags: needinfo?(bzbarsky)
Priority: -- → P2
See Also: → 863402
Blocks: 1322186
Assignee: nobody → echuang
Status: NEW → ASSIGNED
Eden is presumably not working on this (account is disabled).
Assignee: echuang → nobody
Status: ASSIGNED → NEW
The spec calls these types "JSON types".
Attachment #8976503 - Flags: review?(kyle)
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
Without this, we will start including mozMemory in performance.toJSON() even if
the pref for it is not set, once 'object' becomes a JSON type.

This changes behavior in the following observable ways:

1) We stop exposing PerformanceResourceTiming's .serverTiming in the JSON
serialization in insecure contexts.

2) We stop exposing PerformanceTiming's timeToNonBlankPaint and
timeToDOMContentFlushed in the JSON serialization unless the relevant
preferences are turned on.
Attachment #8976504 - Flags: review?(kyle)
Compared to the spec, we had the following differences:

* Date was a JSON type in our implementation.  It doesn't even exist as a type
  in the spec.  It stops being a JSON type.
* Annotated types are not supported yet.  Nothing changes here.
* Typedef types were not JSON types in our implementation.  They become JSON
  types if the type it's a typedef for is one.
* Frozen arrays are not supported yet.  nothing changes here.
* Records were not JSON types in our implementation.  They become JSON types
  when the value type is a JSON type.
* Object was not a JSON type in our implementation.  It becomes a JSON type.
* Interface types were only JSON types in our implementation if they had a
  jsonifier.  We change to treating them as JSON types if there is a jsonifier
  anywhere on the inheritance chain.

In terms of observable behavior, the following properties now get included by
toJSON methods that didn't use to be included:

  PaymentResponse.details
  Performance.mozMemory

both because they're of type "object".
Attachment #8976505 - Flags: review?(kyle)
There are two restrictions: such methods must take no arguments and must return a JSON type.
Attachment #8976506 - Flags: review?(kyle)
Attachment #8976503 - Flags: review?(kyle) → review+
Attachment #8976504 - Flags: review?(kyle) → review+
Attachment #8976505 - Flags: review?(kyle) → review+
Attachment #8976506 - Flags: review?(kyle) → review+
Attachment #8976507 - Flags: review?(kyle) → review+
Might be worth filing a followup on this for filling out the JSON type tests. Could be a good-first-bug.
> Might be worth filing a followup on this for filling out the JSON type tests. Could be a good-first-bug.

Good point.  Filed bug 1462537.
Blocks: 1462537
Pushed by bzbarsky@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/db208ef2f3cb
part 1.  Rename isSerializable() to isJSONType().  r=qdot
https://hg.mozilla.org/integration/mozilla-inbound/rev/5a9cdc8de26a
part 2.  The default binding toJSON should skip over attributes that are not exposed in the current global.  r=qdot
https://hg.mozilla.org/integration/mozilla-inbound/rev/3db98d12d700
part 3.  Align our definition of "JSON type" with the spec.  r=qdot
https://hg.mozilla.org/integration/mozilla-inbound/rev/23c967ee8611
part 4.  Enforce the spec restrictions on methods named toJSON().  r=qdot
https://hg.mozilla.org/integration/mozilla-inbound/rev/1f3dbe030f57
part 5.  Switch from using "jsonifier" syntax to the spec's "[Default] toJSON" syntax. r=qdot
Depends on: 1465602
Component: DOM → DOM: Bindings (WebIDL)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: