Bug 1157257: Include error's name if it's not a WebDriver error

When native JavaScript errors are thrown because of internal errors,
this will include the Error prototype's name in the message.

This is useful since the WebDriver protocol doesn't allow for arbitrary
JS error marshaling.

r=chmanchester

--HG--
extra : rebase_source : d1bd290b1df1acf6c3f67a7fcd7d1f71b7006477
This commit is contained in:
Andreas Tolfsen 2015-04-23 14:34:40 +01:00
parent bec02ac087
commit 34c27181b2

View File

@ -55,9 +55,27 @@ const XPCOM_EXCEPTIONS = [];
this.error = {};
/**
* Marshals an error object into a WebDriver protocol error. The given
* error can be a prototypal Error or an object, as long as it has the
* properties message, stack, and status.
*
* If err is a native JavaScript error, the returned object's message
* property will be changed to include the error's name.
*
* @param {Object} err
* Object with the properties message, stack, and status.
*
* @return {Object}
* Object with the properties message, stacktrace, and status.
*/
error.toJSON = function(err) {
let msg = err.message;
if (!error.isWebDriverError(err) && "name" in error) {
msg = `${err.name}: ${msg}`;
}
return {
message: err.message,
message: msg,
stacktrace: err.stack || null,
status: err.status
};