Object.prototype.toSource interferes with destructuring
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox70 | --- | affected |
People
(Reporter: vsmenon, Unassigned)
Details
Attachments
(1 file)
|
136 bytes,
text/html
|
Details |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
Steps to reproduce:
Load the following in FF:
<html>
<body>
<script>
function foo(opts) {
let {toSource = 42} = opts;
return toSource;
}
console.log(foo({}));
</script>
</body>
</html>
Actual results:
The console shows: "function toSource()"
Expected results:
The console should show: "42"
I see "42" on Chrome and Safari. I also "42" in FF if I:
- have the debugger open
- set a breakpoint on the "return toSource" line
- at the stopped breakpoint, hover on the "toSource" in the let line above
- continue
Hi Vsmenon,
Can you attach a test page with the code so we can try to reproduce it on our end?
Also, please download the latest Firefox Nightly version and let us know if you are still reproducing the problem. You can download it from here: https://nightly.mozilla.org/.
If you still have the issue please create a new profile, you have the steps here:https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles?redirectlocale=en-US&redirectslug=Managing-profiles#w_starting-the-profile-manager
Please test if the issue is reproducible in safe mode, here is a link that can help you:
https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode
If there is any other info you can provide to help us figure out how we can can reproduce the issue please share them.
Thanks for your contribution.
Test page (toSource.html) attached.
Yes, I'm seeing the same behavior in nightly (70.0a1 (2019-08-13)). I've attached the source as a file (and modified console.log to alert - this doesn't affect the bug).
Hi vsmenon,
Thank you for providing us with the test page. I was able to reproduce the issue using the latest Firefox Nightly version 70.0a1 on Mac OSX 10.14.
I'll assign a product and component so the corresponding team can take a look at this. If you think this is not the right component, feel free to change it.
Regards,
Updated•7 years ago
|
Updated•7 years ago
|
Comment 5•7 years ago
|
||
The bug is that the method Object.prototype.toSource exists in Firefox and not in other implementations.
So when assigning
let {toSource = 42} = opts;
other browsers find opts.toSource to be undefined, and therefore use the default value of 42; but SpiderMonkey sees the method and uses that.
We've had this method for many, many years, but I've never had it reported as a bug before. Maybe we should consider finally getting rid of it (bug 1418769).
Updated•3 years ago
|
Comment 6•1 year ago
|
||
Attached testcase shows 42 in both Nightly and Chrome.
Closing this bug.
Description
•