Bug 439110 - xpcshell's load() just silently fails for non-existent files; r=mrbkap
authorbrian crowder <crowder@fiverocks.com>
Sun, 08 Mar 2009 10:38:55 +0100
changeset 25833 8c5d11efd45260b41505400b8bc89384805653c8
parent 25832 7db7d5ab702a23382662e10e488f2349332d5045
child 25834 00bae8a117f617a22e5ead5fc3027189ed8f684a
push idunknown
push userunknown
push dateunknown
reviewersmrbkap
bugs439110
milestone1.9.2a1pre
Bug 439110 - xpcshell's load() just silently fails for non-existent files; r=mrbkap
js/src/xpconnect/shell/xpcshell.cpp
--- a/js/src/xpconnect/shell/xpcshell.cpp
+++ b/js/src/xpconnect/shell/xpcshell.cpp
@@ -442,28 +442,30 @@ Load(JSContext *cx, JSObject *obj, uintN
 
     for (i = 0; i < argc; i++) {
         str = JS_ValueToString(cx, argv[i]);
         if (!str)
             return JS_FALSE;
         argv[i] = STRING_TO_JSVAL(str);
         filename = JS_GetStringBytes(str);
         file = fopen(filename, "r");
+        if (!file) {
+            JS_ReportError(cx, "cannot open file '%s' for reading", filename);
+            return JS_FALSE;
+        }
         script = JS_CompileFileHandleForPrincipals(cx, obj, filename, file,
                                                    gJSPrincipals);
-        if (file)
-            fclose(file);
+        fclose(file);
         if (!script)
-            ok = JS_FALSE;
-        else {
-            ok = !compileOnly
-                 ? JS_ExecuteScript(cx, obj, script, &result)
-                 : JS_TRUE;
-            JS_DestroyScript(cx, script);
-        }
+            return JS_FALSE;
+
+        ok = !compileOnly
+             ? JS_ExecuteScript(cx, obj, script, &result)
+             : JS_TRUE;
+        JS_DestroyScript(cx, script);
         if (!ok)
             return JS_FALSE;
     }
     return JS_TRUE;
 }
 
 static JSBool
 Version(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)