[META] Symbols as WeakMap property keys
Categories
(Core :: JavaScript Engine, enhancement, P3)
Tracking
()
People
(Reporter: yulia, Unassigned)
References
(Blocks 1 open bug, )
Details
(4 keywords, Whiteboard: [DocArea=JS])
Currently at stage 2
| Reporter | ||
Updated•4 years ago
|
Updated•3 years ago
|
Comment 2•2 years ago
|
||
I have the following test code:
const map = new WeakMap();
const key = Symbol();
map.set(key, 42);
It throws error:
Uncaught
TypeError:WeakMapkeySymbol()must be an object or an unregistered symbol
However, it works fine on both Chrome and Safari, which means there can be compatibility issue arises from it, and the behavior here is inconsistent with this error message, which is very confusing.
(In reply to Xidorn Quan [:xidorn] UTC+11 from comment #2)
However, it works fine on both Chrome and Safari, which means there can be compatibility issue arises from it, and the behavior here is inconsistent with this error message, which is very confusing.
Have you turned on the pref "javascript.options.experimental.symbols_as_weakmap_keys" ?
It is still off by default.
Comment 4•2 years ago
|
||
(In reply to Yoshi Cheng-Hao Huang [:allstars.chh][:allstarschh][:yoshi] from comment #3)
Have you turned on the pref "javascript.options.experimental.symbols_as_weakmap_keys" ?
It is still off by default.
No. Should there be a bug tracking this pref change? Also should we have the error thrown adapt to the availability of this feature, and potentially even mention the tracking bug?
Updated•2 years ago
|
Any updates on this one? I wanted to start using Symbols as WeakMap keys, but I just noticed that it breaks in FF when I test. Thanks!
I think when using "lib": ["es2023"] with Typescript, the es2023.collection is only unsupported in Firefox now. It would be great if this last "ES2023" feature was supported in Firefox as well.
Updated•1 year ago
|
Comment 8•1 year ago
|
||
Hi Tom
Since we keep meta bugs open to track future spec changes and issues, should we move the webcompat webcompat:risk-moderate whiteboard tag to Bug 1863140?
Comment 9•1 year ago
|
||
Yes, definitely. I was intending to revisit meta-bugs which I've marked with risk scores ASAP, to move the scores as appropriate to their sub-bugs. I'll move this one as you suggested now (and mark that bug as parity-chrome and -safari, since that seems to be the case).
Comment 10•1 year ago
|
||
Hey Will, is there any bug tracking enabling this feature itself? I believe not enabling symbols as weak key itself has webcompat implications. This is especially true given that TypeScript is shipping this in their declaration for es2023.collection as mentioned in comment 7, and if devs use that as a guide without checking compatibility with Firefox, things can fall dramatically.
Personally I have seen a few times internally in my current company (Canva) that someone tries to use symbol as weak key. Those instances are either stopped by review, or caught in staging before reaching production. But this isn't a reliable way to catch such an issue, so the sooner we can close this webcompat gap the better.
Comment 11•1 year ago
|
||
Will is no longer at Mozilla so I'm redirecting the NI.
Updated•1 year ago
|
Comment 13•9 months ago
|
||
Bug 1966745 is resolved, and it works great when I tried this in Nightly Firefox! 🎉
const wm = new WeakMap();
const s = Symbol();
wm.set(s, '🎉');
console.log(wm.get(s));
-> 🎉
Does the support table on MDN for WeakMap need to be updated manually, to show that this feature is supported in a pre-release version (similar to Atomits.waitAsync())? Or is the table only updated when a version reaches the Beta channel and not Nightly?
Can this issue be closed, or does it need to reach Beta/Stable before closing?
Comment 14•8 days ago
|
||
This has shipped so closing the bug.
Description
•