Bug 1092477 - Let the subscript Loader report any URL it fails on, when it can. r=bholley

This commit is contained in:
Alexander J. Vincent 2014-11-08 17:08:09 -08:00
parent a9bfa1c874
commit 1255b6cbe8
6 changed files with 64 additions and 9 deletions

View File

@ -327,7 +327,7 @@ const load = iced(function load(loader, module) {
// not puts `:` after `"Error"` unlike regular errors thrown by JS code.
// If there is a JS stack then this error has already been handled by an
// inner module load.
if (String(error) === "Error opening input stream (invalid filename?)") {
if (/^Error opening input stream/.test(String(error))) {
let caller = frames.slice(0).pop();
fileName = caller.fileName;
lineNumber = caller.lineNumber;

View File

@ -29,6 +29,7 @@
#include "mozilla/scache/StartupCacheUtils.h"
#include "mozilla/unused.h"
#include "nsContentUtils.h"
#include "nsStringGlue.h"
using namespace mozilla::scache;
using namespace JS;
@ -90,6 +91,23 @@ ReportError(JSContext *cx, const char *msg)
return NS_OK;
}
static nsresult
ReportError(JSContext *cx, const char *origMsg, nsIURI* uri)
{
if (!uri)
return ReportError(cx, origMsg);
nsAutoCString spec;
nsresult rv = uri->GetSpec(spec);
if (NS_FAILED(rv))
spec.Assign("(unknown)");
nsAutoCString msg(origMsg);
msg.Append(": ");
msg.Append(spec);
return ReportError(cx, msg.get());
}
// There probably aren't actually any consumers that rely on having the full
// scope chain up the parent chain of "obj" (instead of just having obj and then
// the global), but we do this for now to preserve backwards compat.
@ -139,18 +157,18 @@ mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *targetObj
}
if (NS_FAILED(rv)) {
return ReportError(cx, LOAD_ERROR_NOSTREAM);
return ReportError(cx, LOAD_ERROR_NOSTREAM, uri);
}
int64_t len = -1;
rv = chan->GetContentLength(&len);
if (NS_FAILED(rv) || len == -1) {
return ReportError(cx, LOAD_ERROR_NOCONTENT);
return ReportError(cx, LOAD_ERROR_NOCONTENT, uri);
}
if (len > INT32_MAX) {
return ReportError(cx, LOAD_ERROR_CONTENTTOOBIG);
return ReportError(cx, LOAD_ERROR_CONTENTTOOBIG, uri);
}
nsCString buf;
@ -171,7 +189,7 @@ mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *targetObj
JS::SourceBufferHolder::GiveOwnership);
if (NS_FAILED(rv)) {
return ReportError(cx, LOAD_ERROR_BADCHARSET);
return ReportError(cx, LOAD_ERROR_BADCHARSET, uri);
}
if (!reuseGlobal) {
@ -325,7 +343,7 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString &url,
rv = uri->GetScheme(scheme);
if (NS_FAILED(rv)) {
return ReportError(cx, LOAD_ERROR_NOSCHEME);
return ReportError(cx, LOAD_ERROR_NOSCHEME, uri);
}
if (!scheme.EqualsLiteral("chrome")) {
@ -333,7 +351,7 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString &url,
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(uri);
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(innerURI);
if (!fileURL) {
return ReportError(cx, LOAD_ERROR_URI_NOT_LOCAL);
return ReportError(cx, LOAD_ERROR_URI_NOT_LOCAL, uri);
}
// For file URIs prepend the filename with the filename of the

View File

@ -67,6 +67,7 @@ skip-if = buildapp == 'mulet'
[test_bug1050049.html]
[test_bug1065185.html]
[test_bug1074863.html]
[test_bug1092477.xul]
[test_xrayToJS.xul]
skip-if = buildapp == 'mulet'
[test_chrometoSource.xul]

View File

@ -0,0 +1,36 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1092477
-->
<window title="Mozilla Bug 1092477"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1092477"
target="_blank">Mozilla Bug 1092477</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
var Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
var exn;
var url = "resource://non-existent/script.js";
try {
Services.scriptloader.loadSubScript(url);
ok(false, "This line should never be reached!");
}
catch (e) {
exn = String(e);
}
var msg = "loadSubscript should throw an exception for trying to load a non-existent script"
is(exn, "Error opening input stream (invalid filename?): " + url, msg);
]]></script>
</window>

View File

@ -630,7 +630,7 @@ Tester.prototype = {
// Ignore if no head.js exists, but report all other errors. Note this
// will also ignore an existing head.js attempting to import a missing
// module - see bug 755558 for why this strategy is preferred anyway.
if (ex.toString() != 'Error opening input stream (invalid filename?)') {
if (!/^Error opening input stream/.test(ex.toString())) {
this.currentTest.addResult(new testResult(false, "head.js import threw an exception", ex, false));
}
}

View File

@ -153,7 +153,7 @@ function WorkerDebuggerLoader(options) {
try {
loadInSandbox(url, sandbox);
} catch (error) {
if (String(error) === "Error opening input stream (invalid filename?)") {
if (/^Error opening input stream/.test(String(error))) {
throw new Error("can't load module " + module.id + " with url " + url +
"!");
}