.then getted twice when await in devtools console
Categories
(DevTools :: Console, defect, P3)
Tracking
(firefox103 verified)
| Tracking | Status | |
|---|---|---|
| firefox103 | --- | verified |
People
(Reporter: alanas.00, Assigned: nchevobbe)
Details
Attachments
(1 file)
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Steps to reproduce:
- open any web page like https://example.net/
- press Ctrl+Shift+I
- select "Console" tab
- type
obj={get then(){console.log("get then")}}into console - press enter
- type
await obj - press enter
Actual results:
get then appeared twice in console
Expected results:
get then appeared once in console (like if you run (async()=>{await obj})())
Comment 1•4 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'DevTools::Console' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 2•4 years ago
|
||
This seems to be a side-effect of the way we wrap top-level await expressions in the console:
https://searchfox.org/mozilla-central/rev/b462b11e71b500e084f51e61fbd9e19ea0122c78/devtools/client/debugger/src/workers/parser/mapAwaitExpression.js#181
Basically when we execute await obj in the Firefox DevTools webconsole, we actually run:
(async () => {
return await obj;
})();
Comment 3•4 years ago
|
||
To check with Nicolas after PTO
Comment 4•4 years ago
|
||
This is most likely going to be a technical limitation for now, but Nicolas might share more details.
| Assignee | ||
Comment 5•4 years ago
|
||
As Julian pointed out in Comment 2 , await obj is transformed into
(async () => {
return await obj;
})();
When this is evaluated, await obj does trigger the first call to then
And then, since await obj returns a thenable and given that the wrapping async function returns a Promise, it will also call then.
We should probably tweak our babel mapper to transform the expression into
(async () => {
return obj;
})();
which should be enough for what we want to achieve (and won't call then twice)
| Assignee | ||
Comment 6•4 years ago
|
||
We use to transform expression like await obj into
(async () => {
return await obj;
})()
``
So we were basically returning the expression, wrapped in an async iife, adding
a `return` statement before the last statement.
But in the case the last statement is an `AwaitExpression`, we can simply return
the argument, stripping the `await` keyword.
This fixes an issue when awaiting for an object with a `then` getter would execute
the getter twice.
A test case is added in mochitest, and unit test are updated to reflect the new
output.
Updated•4 years ago
|
Comment 8•4 years ago
|
||
| bugherder | ||
Updated•4 years ago
|
Comment 9•4 years ago
|
||
Reproduced the issue in release 102.
Verified - Fixed in Beta 103.0b4 and the latest Nightly build 104.0a1 (2022-07-05) using Windows 10 and macOS 12. "get then" appeared only once in console.
Description
•