diff --git a/HISTORY.md b/HISTORY.md index 27a60d1c4..2d417b4e0 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,12 @@ https://github.com/josdejong/mathjs +## not yet released, version 0.23.1 + +- Fixed imported, wrapped functions not accepting `null` and `undefined` as + function arguments. + + ## 2014-06-10, version 0.23.0 - Renamed some functions (everything now has a logical, camel case name): diff --git a/lib/function/utils/import.js b/lib/function/utils/import.js index aebac0951..2e6ec2114 100644 --- a/lib/function/utils/import.js +++ b/lib/function/utils/import.js @@ -117,7 +117,8 @@ module.exports = function (math) { math[name] = function () { var args = []; for (var i = 0, len = arguments.length; i < len; i++) { - args[i] = arguments[i].valueOf(); + var arg = arguments[i]; + args[i] = arg && arg.valueOf(); } return value.apply(math, args); }; diff --git a/test/function/utils/import.test.js b/test/function/utils/import.test.js index caf934c2e..28e605982 100644 --- a/test/function/utils/import.test.js +++ b/test/function/utils/import.test.js @@ -59,6 +59,26 @@ describe('import', function() { assert.equal(math.getSizeNotWrapped(math.matrix([1,2,3])), undefined); }); + it('wrapped imported functions should accept undefined and null', function () { + math.import({ + isNull: function (obj) { + return obj === null; + } + }, { wrap: true }); + assert.equal(math.isNull(null), true); + assert.equal(math.isNull(0), false); + + math.import({ + isUndefined: function (obj) { + return obj === undefined; + } + }, { wrap: true }); + assert.equal(math.isUndefined(undefined), true); + assert.equal(math.isUndefined(0), false); + assert.equal(math.isUndefined(null), false); + + }); + it('should extend math with numbers', function() { // extend math.js with numbers.js // examples copied from https://github.com/sjkaliski/numbers.js/blob/master/examples/statistic.js