Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

temporary mitigation of bug 551604 #528

Closed
wants to merge 2 commits into from

3 participants

David Creswick KWierso ochameau
David Creswick

The file name and line number are included the SyntaxError object thrown from require(). The problem is that the information isn't included in the stack trace nor in the error message. This commit appends that info to the error message. It's sort of a hack, but it gets the job done for now and will hold until something better is implemented.

packages/api-utils/lib/loader.js
@@ -163,8 +163,14 @@ const evaluate = iced(function evaluate(sandbox, uri, options) {
source: null
}, options);
- return source ? Cu.evalInSandbox(source, sandbox, version, uri, line)
- : loadSubScript(uri, sandbox, encoding);
+ try {
+ return source ? Cu.evalInSandbox(source, sandbox, version, uri, line)
+ : loadSubScript(uri, sandbox, encoding);
+ } catch (exc if exc instanceof SyntaxError) {
ochameau Owner

Hum that's weird, it shouldn't work and it doesn't work for me.
Because of cross-sandboxes/compartments values, exc is never an instance of SyntaxError.
It is an instance of sandbox's SyntaxError.
We should do something like this instead:
} catch (exc if exc.name === "SyntaxError") {

David Creswick
dcrewi added a note

I could swear it worked earlier. I judged instanceof to be more proper than checking name, but you're right that it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
KWierso
Owner

Looks like a fix for 551604 already landed.

KWierso KWierso closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 20, 2012
  1. David Creswick
Commits on Aug 24, 2012
  1. David Creswick
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 2 deletions.
  1. +8 −2 packages/api-utils/lib/loader.js
10 packages/api-utils/lib/loader.js
View
@@ -163,8 +163,14 @@ const evaluate = iced(function evaluate(sandbox, uri, options) {
source: null
}, options);
- return source ? Cu.evalInSandbox(source, sandbox, version, uri, line)
- : loadSubScript(uri, sandbox, encoding);
+ try {
+ return source ? Cu.evalInSandbox(source, sandbox, version, uri, line)
+ : loadSubScript(uri, sandbox, encoding);
+ } catch (exc if exc.name === "SyntaxError") {
+ // see https://bugzilla.mozilla.org/show_bug.cgi?id=551604
+ throw SyntaxError(exc.message+' at '+exc.fileName+':'+exc.lineNumber,
+ exc.fileName, exc.lineNumber);
+ }
});
exports.evaluate = evaluate;
Something went wrong with that request. Please try again.