Closed
Bug 1057699
Opened 11 years ago
Closed 7 years ago
Structured cloning should support symbols
Categories
(Core :: JavaScript Engine, enhancement)
Core
JavaScript Engine
Tracking
()
RESOLVED
WONTFIX
People
(Reporter: Waldo, Unassigned, Mentored)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
|
7.41 KB,
patch
|
Waldo
:
review-
|
Details | Diff | Splinter Review |
In order to send symbols as values through postMessage and similar, symbols need to be able to be structured-cloned. This should be a relatively short, but not ridiculously trivial, first bug.
You'll want to be aware of the data that a symbol encapsulates/represents. I believe this comes down to 1) the description associated with it, 2) whether the symbol is or isn't registered, and 3) whether it's one of the well-known symbols.
You'll then need to add code to both read and write symbols, in js/src/vm/StructuredClone.cpp. There's probably a little bit of design work that'll have to go into this -- ask in #jsapi if you're unsure how to proceed on this point, or comment here.
Finally, you'll want to write some tests to make sure your code works. js/src/jit-test/tests/structured-clone/ may be a good place to look to see how to write these tests, and where to add them.
This should be nearly all the information needed to write a patch for this. If you have questions, comment here or head onto #jsapi on Mozilla's IRC servers and ask questions there.
| Reporter | ||
Comment 1•11 years ago
|
||
A minor complication is that because Symbol("foo") !== Symbol("foo"), symbols will have to be hooked into the don't-duplicate-serialize mechanics in structured cloning. These are probably a little more complicated. We already have code handling this for objects, to possibly either that can be repurposed, or it can be generalized to objects-or-symbols. Again, questions to #jsapi.
Comment 2•11 years ago
|
||
I can work on this bug.
Comment 3•9 years ago
|
||
AIUI, StructuredClone is specified here https://html.spec.whatwg.org/multipage/infrastructure.html#structuredclone, and in Step 4, it explicitly states that if the input value is of the Symbol type, it should throw an DataCloneError. Are we wilfully veering off spec here?
Assuming that we are to deviate from the spec, I can't really seem to find the relevant data for Symbol in its struct definition except for its description. Is there a special function that I need to call in order to extract data about 1) whether it's registered or not and 2) whether it's one of the well-known symbols? Also, is a Symbol an object, or is it its own type?
Flags: needinfo?(jwalden+bmo)
| Reporter | ||
Comment 4•9 years ago
|
||
No proposal to deviate from spec. If the spec doesn't support this, changing it so it does would be the first step. I think my semi-assumption was that it would eventually change to support some classes of symbol.
That said, this is only really supportable for |Symbol.for(...)| symbols, which may not be enough to make this useful. If spec-upstream were sure it wasn't worth supporting only registered symbols, this would be WONTFIX. But I don't know whether they've done that or not. (And I'm not sure whether ECMA-262 has spec hooks that the structured clone spec could call, if it wanted to do this, to determine whether a symbol is a registered symbol or not.)
Flags: needinfo?(jwalden+bmo)
Comment 5•9 years ago
|
||
Attachment #8796822 -
Flags: review?(jwalden+bmo)
Comment 6•9 years ago
|
||
Oh, and sorry, I forgot to comment here saying that I'm looking into this.
| Reporter | ||
Comment 7•9 years ago
|
||
Comment on attachment 8796822 [details] [diff] [review]
Bug1057699.patch
Review of attachment 8796822 [details] [diff] [review]:
-----------------------------------------------------------------
Spec right now doesn't say symbols of any sort should be clonable, so we can't take this right now. If you want to get this changed, you should go to WHATWG first and ask there, per comment 4 (which also should have noted the builtin symbols -- Symbol.iterator and so on -- should be considered for being supported for cloning).
Attachment #8796822 -
Flags: review?(jwalden+bmo) → review-
Comment 8•9 years ago
|
||
Comment 9•8 years ago
|
||
I think this should be closed as a WONTFIX, give the reply from WHATWG.
Comment 10•7 years ago
|
||
I agree with Keith, barring https://github.com/whatwg/html/issues/1862 getting re-opened. (Tidying https://codetribute.mozilla.org/projects/jseng)
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
You need to log in
before you can comment on or make changes to this bug.
Description
•