Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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) {
163 163
     source: null
164 164
   }, options);
165 165
 
166  
-  return source ? Cu.evalInSandbox(source, sandbox, version, uri, line)
167  
-                : loadSubScript(uri, sandbox, encoding);
  166
+  try {
  167
+    return source ? Cu.evalInSandbox(source, sandbox, version, uri, line)
  168
+                  : loadSubScript(uri, sandbox, encoding);
  169
+  } catch (exc if exc instanceof SyntaxError) {
2
ochameau Collaborator
ochameau added a note August 23, 2012

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 August 23, 2012

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
Collaborator

Looks like a fix for 551604 already landed.

KWierso KWierso closed this December 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Aug 20, 2012
David Creswick temporary mitigation of bug 551604 336b60f
Aug 23, 2012
David Creswick oops; feedback from pull request 528 aa88313
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 8 additions and 2 deletions. Show diff stats Hide diff stats

  1. 10  packages/api-utils/lib/loader.js
10  packages/api-utils/lib/loader.js
@@ -163,8 +163,14 @@ const evaluate = iced(function evaluate(sandbox, uri, options) {
163 163
     source: null
164 164
   }, options);
165 165
 
166  
-  return source ? Cu.evalInSandbox(source, sandbox, version, uri, line)
167  
-                : loadSubScript(uri, sandbox, encoding);
  166
+  try {
  167
+    return source ? Cu.evalInSandbox(source, sandbox, version, uri, line)
  168
+                  : loadSubScript(uri, sandbox, encoding);
  169
+  } catch (exc if exc.name === "SyntaxError") {
  170
+    // see https://bugzilla.mozilla.org/show_bug.cgi?id=551604
  171
+    throw SyntaxError(exc.message+' at '+exc.fileName+':'+exc.lineNumber,
  172
+                      exc.fileName, exc.lineNumber);
  173
+  }
168 174
 });
169 175
 exports.evaluate = evaluate;
170 176
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.