Line numbers for `Function("throw new Error()")()` eval are wrong
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
People
(Reporter: galiazzi.dayan, Unassigned)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
|
31.16 KB,
image/png
|
Details |
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0
Steps to reproduce:
- Execute the code below in console:
Function(console.log('test'); throw new Error('error'); //# sourceURL=test.js)(); - Click in error link
Actual results:
The line is not correct.
Breakingpoints also don't work correct
Expected results:
Select right line
Comment 1•6 years ago
|
||
Bugbug thinks this bug should belong to this component, but please revert this change in case of error.
Comment 2•6 years ago
|
||
Thanks for the report!
I am attaching a screenshot of what I am seeing on my machine. Is that what you see?
- The error location says line 3 -> BUG
- The source shows all on line 1 and there is no way to add BP -> BUG
Honza
Updated•6 years ago
|
Comment 3•5 years ago
|
||
This is because Function() internally creates a function with the source text
function anonymous(
) {
console.log('test'); throw new Error('error'); //# sourceURL=test.js
}
so in fact the code passed to Function is line 3 of the function.
Comment 4•5 years ago
|
||
The formatting for functions created through Function is required per spec, cf. CreateDynamicFunction, where line endings are added before and after the bodyArg (step 16).
Comment 5•5 years ago
|
||
@anba That's true, but the string there is used exclusively to populate F.[[SourceText]] for .toString(). I think users would entirely expect that line numbers for errors would correspond directly with the string passed to Function(), rather than relative to the overall function source text.
Comment 6•5 years ago
|
||
Oh, I realize I was speaking relative to the overall text, not the 2 wrapping newlines you mentioned, but I think the point stands.
Comment 7•5 years ago
|
||
I just wanted to clarify why we have that funny formatting. :-)
Updated•3 years ago
|
Updated•1 year ago
|
Description
•