Commit 427c643f 427c643f8019363bc0d9f6fd743bac2c18f86e69 by Nicolas Perriault

updated the way exceptions are thrown; now using throw new Error() everywhere

1 parent cc58b509
......@@ -208,7 +208,7 @@
try {
onComplete.call(self, self);
} catch (err) {
self.log("could not complete final step: " + err, "error");
self.log("Could not complete final step: " + err, "error");
}
} else {
// default behavior is to exit phantom
......@@ -245,7 +245,7 @@
*/
createStep: function(fn, options) {
if (!isType(fn, "function")) {
throw "createStep(): a step definition must be a function";
throw new Error("createStep(): a step definition must be a function");
}
fn.options = isType(options, "object") ? options : {};
return fn;
......@@ -447,10 +447,10 @@
fill: function(selector, vals, submit) {
submit = submit === true ? submit : false;
if (!isType(selector, "string") || !selector.length) {
throw "form selector must be a non-empty string";
throw new Error("Form selector must be a non-empty string");
}
if (!isType(vals, "object")) {
throw "form values must be provided as an object";
throw new Error("Form values must be provided as an object");
}
var fillResults = this.evaluate(function(selector, values) {
return __utils__.fill(selector, values);
......@@ -459,7 +459,7 @@
values: vals
});
if (!fillResults) {
throw "unable to fill form";
throw new Error("Unable to fill form");
} else if (fillResults.errors.length > 0) {
(function(self){
fillResults.errors.forEach(function(error) {
......@@ -467,7 +467,7 @@
});
})(this);
if (submit) {
this.log("errors encountered while filling form; submission aborted", "warning");
this.log("Errors encountered while filling form; submission aborted", "warning");
submit = false;
}
}
......@@ -708,10 +708,10 @@
*/
setHttpAuth: function(username, password) {
if (!this.started) {
throw "Casper must be started in order to use the setHttpAuth() method";
throw new Error("Casper must be started in order to use the setHttpAuth() method");
}
if (!isType(username, "string") || !isType(password, "string")) {
throw "Both username and password must be strings";
throw new Error("Both username and password must be strings");
}
this.page.settings.userName = username;
this.page.settings.password = password;
......@@ -783,10 +783,10 @@
*/
then: function(step) {
if (!this.started) {
throw "Casper not started; please use Casper#start";
throw new Error("Casper not started; please use Casper#start");
}
if (!isType(step, "function")) {
throw "You can only define a step as a function";
throw new Error("You can only define a step as a function");
}
// check if casper is running
if (this.checker === null) {
......@@ -1066,7 +1066,7 @@
*/
phantom.Casper.extend = function(proto) {
if (!isType(proto, "object")) {
throw "extends() only accept objects as prototypes";
throw new Error("extends() only accept objects as prototypes");
}
mergeObjects(phantom.Casper.prototype, proto);
};
......
......@@ -32,7 +32,7 @@
*/
phantom.Casper.FunctionArgsInjector = function(fn) {
if (!isType(fn, "function")) {
throw "FunctionArgsInjector() can only process functions";
throw new Error("FunctionArgsInjector() can only process functions");
}
this.fn = fn;
......@@ -55,7 +55,7 @@
this.process = function(values) {
var fnObj = this.extract(this.fn);
if (!isType(fnObj, "object")) {
throw "Unable to process function " + this.fn.toString();
throw new Error("Unable to process function " + this.fn.toString());
}
var inject = this.getArgsInjectionString(fnObj.args, values);
return 'function ' + (fnObj.name || '') + '(){' + inject + fnObj.body + '}';
......
......@@ -38,7 +38,7 @@
this.options = isType(options, "object") ? options : {};
if (!casper instanceof phantom.Casper) {
throw "phantom.Casper.Tester needs a phantom.Casper instance";
throw new Error("phantom.Casper.Tester needs a phantom.Casper instance");
}
// locals
......@@ -276,7 +276,7 @@
*/
this.exec = function(file) {
if (!fs.isFile(file) || !isJsFile(file)) {
throw "Can only exec() files with .js or .coffee extensions";
throw new Error("Can only exec() files with .js or .coffee extensions");
}
if (fileExt(file) === "coffee") {
phantom.injectJs(file); // FIXME: syntax validation?
......@@ -286,7 +286,7 @@
try {
parsed = esprima.parse(testContents);
} catch(e) {
throw "Unable to parse test file " + file + ": " + e.toString();
throw new Error("Unable to parse test file " + file + ": " + e.toString());
}
eval(testContents);
}
......@@ -395,7 +395,7 @@
this.runSuites = function() {
var testFiles = [], self = this;
if (arguments.length === 0) {
throw "No test suite to run";
throw new Error("No test suite to run");
}
Array.prototype.forEach.call(arguments, function(path) {
if (!fs.exists(path)) {
......