diff options
Diffstat (limited to 'lib/__set__.js')
-rw-r--r-- | lib/__set__.js | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/__set__.js b/lib/__set__.js index 49e4494..79175ed 100644 --- a/lib/__set__.js +++ b/lib/__set__.js @@ -8,14 +8,16 @@ * @param {!String|!Object} varName name of the variable to set
* @param {String} varValue new value
* @throws {TypeError}
+ * @throws {ReferenceError} When the variable is unknown
* @return {*}
*/
-module.exports = function __set__() {
+function __set__() {
arguments.varName = arguments[0];
arguments.varValue = arguments[1];
arguments.src = "";
- arguments.checkExistsSrc = function (varName) {
- return "if (typeof " + varName + " === 'undefined') { throw new ReferenceError('Cannot __set__(): " + varName + " is not declared within the module.');} ";
+ arguments.checkExistsSrc = function (varName, varValue) {
+ return "if (typeof " + varName + " === 'undefined') { throw new ReferenceError('Cannot __set__(" + varName + ", " + varValue + "): " +
+ varName + " is not declared within the module.'); } ";
};
if (typeof arguments[0] === "object") {
@@ -32,10 +34,12 @@ module.exports = function __set__() { if (!arguments.varName) {
throw new TypeError("__set__ expects a non-empty string as a variable name");
}
- arguments.src = arguments.checkExistsSrc(arguments.varName) + arguments.varName + " = arguments.varValue;";
+ arguments.src = arguments.checkExistsSrc(arguments.varName, arguments.varValue) + arguments.varName + " = arguments.varValue;";
} else {
throw new TypeError("__set__ expects an environment object or a non-empty string as a variable name");
}
eval(arguments.src);
-};
\ No newline at end of file +}
+
+module.exports = __set__;
\ No newline at end of file |