Closed Bug 738468 Opened 8 years ago Closed 8 years ago

DebuggerScript_getUrl crashes if script->filename is null

Categories

(Core :: JavaScript Engine, defect)

Other Branch
defect
Not set

Tracking

()

RESOLVED FIXED
mozilla15

People

(Reporter: jorendorff, Assigned: jorendorff)

References

Details

(Whiteboard: [chrome-debug])

Attachments

(1 file)

This definitely happens in the browser. We need a shell function that creates functions with null filenames in order to test it.
Whiteboard: [chrome-debug]
So I can't tell if we're actually supposed to support NULL filenames or not. The JSAPI documentation doesn't really say, but we don't JS_ASSERT(filename), and if we did I think we'd break Gecko.

So we probably should support NULL filenames, but there are no tests and in fact if I make it testable then I immediately get weird behavior:

js> evaluate("throw new Error()", {fileName: null});
js>

The error is never thrown. In fact creating the error object mysteriously fails, because of this code in jsexn.cpp:Exception():

669	            filename = FilenameToString(cx, iter.script()->filename);
670	            if (!filename)
671	                return false;

So basically this is a mess.
Assignee: general → nobody
Component: JavaScript Engine → js-ctypes
QA Contact: general → js-ctypes
Target Milestone: --- → mozilla14
Version: Other Branch → 15 Branch
oh for the love of Mike
Assignee: nobody → general
Component: js-ctypes → JavaScript Engine
QA Contact: js-ctypes → general
Target Milestone: mozilla14 → ---
Version: 15 Branch → Other Branch
OK, we definitely have null-filename scripts running around, because the patch in bug 738480 causes us to segfault when browser/devtools/commandline/test/browser_gcli_break.js tries to examine them.

Better to support this everywhere than to ban it... I guess? Any other JSAPI people care?
Blocks: 738480
Assignee: general → jorendorff
Attached patch v1Splinter Review
This is gross. I'm convinced we should do away with null filenames, but let's stop the crashes first and do the API change in a different bug.
Attachment #626690 - Flags: review?(jimb)
Comment on attachment 626690 [details] [diff] [review]
v1

Review of attachment 626690 [details] [diff] [review]:
-----------------------------------------------------------------

Looks great. One semi-nit; only change if you agree it's clearer.

::: js/src/jsexn.cpp
@@ +563,5 @@
>              return false;
>          args[1].setString(filename);
>      } else {
> +        const char *cfilename;
> +        if (!iter.done() && (cfilename = iter.script()->filename)) {

nit: Assignment operators in 'if' conditions aren't very legible. Could we perhaps:

filename = cx->runtime->emptyString;
if (!iter.done()) {
  const char *cfilename = iter.script()->filename;
  if (cfilename) {
    filename = FilenameToString(cx, cfilename);
    if (!filename)
      return false;
  }
}
Attachment #626690 - Flags: review?(jimb) → review+
https://hg.mozilla.org/mozilla-central/rev/29a18a93721d
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla15
You need to log in before you can comment on or make changes to this bug.