# 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.
_______________________________________________
dev-platform mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to