Bug 1320249 - Preferences.jsm now throws error objects instead of strings. r=Gijs

MozReview-Commit-ID: 6eJCmQBC482

--HG--
extra : rebase_source : c5cf6fda38082ed0fc722907b3f307cea757b77f
This commit is contained in:
Mark Hammond 2016-11-24 15:58:58 +11:00
parent 76662a4138
commit 1ac8cbde15

View File

@ -71,9 +71,9 @@ Preferences._get = function(prefName, defaultValue, valueType) {
default:
// This should never happen.
throw "Error getting pref " + prefName + "; its value's type is " +
this._prefBranch.getPrefType(prefName) + ", which I don't " +
"know how to handle.";
throw new Error(`Error getting pref ${prefName}; its value's type is ` +
`${this._prefBranch.getPrefType(prefName)}, which I don't ` +
`know how to handle.`);
}
};
@ -130,10 +130,11 @@ Preferences._set = function(prefName, prefValue) {
// if the number is non-integer, since the consumer might not mind
// the loss of precision.
if (prefValue > MAX_INT || prefValue < MIN_INT)
throw ("you cannot set the " + prefName + " pref to the number " +
prefValue + ", as number pref values must be in the signed " +
"32-bit integer range -(2^31-1) to 2^31-1. To store numbers " +
"outside that range, store them as strings.");
throw new Error(
`you cannot set the ${prefName} pref to the number ` +
`${prefValue}, as number pref values must be in the signed ` +
`32-bit integer range -(2^31-1) to 2^31-1. To store numbers ` +
`outside that range, store them as strings.`);
this._prefBranch.setIntPref(prefName, prefValue);
if (prefValue % 1 != 0)
Cu.reportError("Warning: setting the " + prefName + " pref to the " +
@ -148,8 +149,8 @@ Preferences._set = function(prefName, prefValue) {
break;
default:
throw "can't set pref " + prefName + " to value '" + prefValue +
"'; it isn't a String, Number, or Boolean";
throw new Error(`can't set pref ${prefName} to value '${prefValue}'; ` +
`it isn't a String, Number, or Boolean`);
}
};