The easiest way to shim a CommonJS-like functionality into the JS shell would be to provide a function evalAt(src, filename, lineno) that evaluates source code with a given file name and line number. This would make it possible to wrap CommonJS source code loaded from a file with the necessary CommonJS boilerplate without losing source location information. Dave
Created attachment 591357 [details] [diff] [review] initial implementation
Here's a simple patch. Seems ... not unreasonable. Anyone opposed? I'll probably r? someone tomorrow. Dave
Not opposition per se, but why? The JS shell is basically our own little internal testing repl, not particularly for public use; and slightly a demonstration of good, kosher JSAPI use. What's the reason we'd be shimming something CommonJSy into it?
We run the dom.js test suite with the spidermonkey shell; it sure would be nice to have sane tracebacks. Right now, when you get a traceback that came from a <script> tag inside an html page that dom.js parsed and executed, you get dom.js as the filename and a line number that doesn't exist at all, instead of the url of the html file as the filename and the correct line number to the script inside the html file.
Ah, that makes sense. Carry on, Mr. Bowditch.
> Not opposition per se, but why? The JS shell is basically our own little > internal testing repl, not particularly for public use; and slightly a > demonstration of good, kosher JSAPI use. What's the reason we'd be shimming > something CommonJSy into it? Narcissus's REPL is built to work with the SpiderMonkey shell, and I want to refactor the modules to be CommonJS so they can also work out-of-the-box in Node. Dave
https://hg.mozilla.org/mozilla-central/rev/8d39654512d5 fwiw, the bug number in the commit message is wrong