console helpers should not override same-name top-level let/const variables
Categories
(DevTools :: Console, defect, P2)
Tracking
(Not tracked)
People
(Reporter: ntim, Assigned: nchevobbe)
Details
Attachments
(1 file, 2 obsolete files)
263.06 KB,
image/png
|
Details |
Reporter | ||
Comment 1•6 years ago
|
||
Reporter | ||
Comment 2•6 years ago
|
||
Reporter | ||
Updated•6 years ago
|
Assignee | ||
Comment 3•6 years ago
|
||
Assignee | ||
Updated•6 years ago
|
Assignee | ||
Updated•6 years ago
|
Comment 4•4 years ago
|
||
What if the let
assignment internally got changed to var
assignment, somehow? Is that possible?
Note that this is what Chrome does, obviously.
Simple test:
- Load
data:text/html,<script>setInterval(() => console.log($('body')), 1000)</script>
=> Errors will be logged that $ is undefined. - In the console execute
let $ = x => document.querySelector(x);
=> The function is defined and the <body> element will be logged. - In the console execute
let $ = 1;
=> Errors will be logged that $ is undefined. There is no error logged that $ cannot be redeclared!
Furthermore, this also applies to any other global variables defined via let
in the console.
Sebastian
Comment 5•4 years ago
|
||
The best place to do that would be in the getEvalInput()
function, I think.
And the simplest solution would be to simply run a string.replace(/^let\s+/, "var ");
before returning. A more complex solution would parse the input and replace all global let assignments by var assignments.
Sebastian
Assignee | ||
Comment 6•4 years ago
|
||
(In reply to Sebastian Zartner [:sebo] from comment #4)
What if the
let
assignment internally got changed tovar
assignment, somehow? Is that possible?
Furthermore, this also applies to any other global variables defined vialet
in the console.
We have Bug 1580891 about this. My concern was that it's not a simple things to do. let
and var
are different things in regards to their scope:
var myVar = 1;
let myLet = 2;
console.log(globalThis.myVar, globalThis.myLet) // -> 1 undefined
Hence the discussion we had around for UI needs: https://github.com/firefox-devtools/ux/issues/30
Note that this is what Chrome does, obviously.
They are doing some things to be able to re-declare let and const variables, but it's not a simple let -> var replacement
let a = 1
let a = 2
is still throwing in Chrome console (which is what we want), and variables assigned with let
are not put on globalThis
.
For this specific bug, we might want to adjust what we do in bindCommands
(devtools/server/actors/webconsole/eval-with-debugger.js#584-619), or/and directly in executeInGlobalWithBindings
Comment 7•4 years ago
|
||
(In reply to Nicolas Chevobbe [:nchevobbe] from comment #6)
(In reply to Sebastian Zartner [:sebo] from comment #4)
Note that this is what Chrome does, obviously.
They are doing some things to be able to re-declare let and const variables, but it's not a simple let -> var replacement
I already assumed that, otherwise you'd already have implemented that. :-)
let a = 1 let a = 2
is still throwing in Chrome console (which is what we want), and variables assigned with
let
are not put onglobalThis
.
If executed in one command, it throws, in two it doesn't.
Also, this throws:
var a = 1
let a = 2
I think, the related Chromium issue is https://crbug.com/542594. Anyway, you obviously already put some more thought into this than I did. Thank you for adding the reference links! I just wanted to state the supposedly simple solution for this.
Sebastian
Updated•3 years ago
|
Assignee | ||
Updated•2 years ago
|
Assignee | ||
Comment 8•2 years ago
|
||
Updated•2 years ago
|
Comment 10•2 years ago
•
|
||
Backed out for causing multiple dt failures.
-
Failure log for failures on browser_storage_indexeddb_hide_internal_dbs.js
-
Failure log for failures on browser_document_devtools_basics.js
-
Failure log for failures on browser_jsterm_autocomplete_null.js
-
Failure log for failures on browser_console_content_object_context_menu.js
-
Failure log for failures on browser_dbg-backgroundtask-debugging.js
Assignee | ||
Comment 11•2 years ago
|
||
I'm looking into this
Here's a push with a potential fix: https://treeherder.mozilla.org/jobs?repo=try&revision=ca7c8139b13a06c1e5b7205136a6f5eea86f65a1
Comment 12•2 years ago
|
||
Comment on attachment 9342335 [details]
Bug 1517907 - [devtools] Don't add webconsole helper bindings if variable exists. r=#devtools-reviewers.
Revision D182717 was moved to bug 1385198. Setting attachment 9342335 [details] to obsolete.
Description
•