Open Bug 1592782 Opened 6 years ago Updated 1 year ago

Line numbers for `Function("throw new Error()")()` eval are wrong

Categories

(Core :: JavaScript Engine, defect, P3)

70 Branch
defect

Tracking

()

People

(Reporter: galiazzi.dayan, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0

Steps to reproduce:

  1. Execute the code below in console:
    Function(console.log('test'); throw new Error('error'); //# sourceURL=test.js)();
  2. Click in error link

Actual results:

The line is not correct.
Breakingpoints also don't work correct

Expected results:

Select right line

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Debugger
Product: Firefox → DevTools
Attached image image.png

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

Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3

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.

Component: Debugger → JavaScript Engine
Product: DevTools → Core
See Also: → 1631510
Summary: Wrong line in debugger when evaluate code with Function → Line numbers for `Function("throw new Error()")()` eval are wrong

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).

@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.

Oh, I realize I was speaking relative to the overall text, not the 2 wrapping newlines you mentioned, but I think the point stands.

I just wanted to clarify why we have that funny formatting. :-)

Severity: normal normal → S3 S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: