Intent to implement: `//# sourceURL=display-url.js` in Error.prototype.stack

27 views
Skip to first unread message

Fitzgerald, Nick

unread,
Oct 9, 2014, 6:38:00 PM10/9/14
to dev-pl...@lists.mozilla.org
# Summary

By appending "//# sourceURL=foo.js" to script text that is being passed
to `eval`, `new Function`, or as the text content of a dynamically
appended <script> tag, a JS developer can give a name to a script that
would otherwise be anonymous. This is used by many JS module loaders.

Here's an example:

eval("window.foo = function () { return Error().stack; }; //#
sourceURL=my-url.js");
window.foo();

The youngest frame in the stack returned by the call to `window.foo`
would have "my-url.js" reported as the filename.

# Bug

https://bugzilla.mozilla.org/show_bug.cgi?id=583083

# Link to standard

No standard, but the sourceURL trend started with Firebug:
https://blog.getfirebug.com/2009/08/11/give-your-eval-a-name-with-sourceurl/

Webkit Inspector and Chrome also supports it in their debuggers. We will
support it in our debugger Soon(tm), once work on making eval'd sources
properly debuggable lands.

Sometime since then, Chrome started actually using the given URL in the
stack traces exposed to web content via `Error.prototype.stack`.

There was some recent discussion on es-discuss that seemed to settle on
everyone agreeing that the //# sourceURL directive should be respected:
https://esdiscuss.org/topic/maximally-minimal-stack-trace-standardization#content-49

# Platform Coverage

Everywhere.

# Estimated Target Release

Unknown at this point. I just wanted to make sure everyone got a chance
to have their say on this topic. I think this should be a really easy
couple line change, since we already parse and store the directive's
content (but it's only currently used by SpiderMonkey's Debugger API).
That said, those are famous last words and I'd be squeezing this in
whenever I happen to get some time to work on it.

# Pref

None. My understanding is that there isn't a great story for prefs and
SpiderMonkey. I think it's ok in this case, as this is pretty unlikely
to break any web code.

David Rajchenbach-Teller

unread,
Oct 10, 2014, 3:32:14 AM10/10/14
to fit...@mozilla.com, dev-pl...@lists.mozilla.org, Fitzgerald, Nick
This would be very useful. I suspect that we can use it to speed up and
decrease the memory usage of the worker module loader.

Cheers,
David

On 10/10/14 00:36, Fitzgerald, Nick wrote:
> # Summary
>
> By appending "//# sourceURL=foo.js" to script text that is being passed
> to `eval`, `new Function`, or as the text content of a dynamically
> appended <script> tag, a JS developer can give a name to a script that
> would otherwise be anonymous. This is used by many JS module loaders.
>
> Here's an example:
>
> eval("window.foo = function () { return Error().stack; }; //#
> sourceURL=my-url.js");
> window.foo();
>
> The youngest frame in the stack returned by the call to `window.foo`
> would have "my-url.js" reported as the filename.



--
David Rajchenbach-Teller, PhD
Performance Team, Mozilla

signature.asc
Reply all
Reply to author
Forward
0 new messages