diff options
-rw-r--r-- | src/embind/embind.js | 6 | ||||
-rw-r--r-- | tests/embind/embind.test.js | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index ff402885..91386c69 100644 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -311,7 +311,7 @@ function __embind_register_integer(primitiveType, name, minRange, maxRange) { 'toWireType': function(destructors, value) { // todo: Here we have an opportunity for -O3 level "unsafe" optimizations: we could // avoid the following two if()s and assume value is of proper type. - if (typeof value !== "number") { + if (typeof value !== "number" && typeof value !== "boolean") { throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' + this.name); } if (value < minRange || value > maxRange) { @@ -333,8 +333,8 @@ function __embind_register_float(rawType, name) { 'toWireType': function(destructors, value) { // todo: Here we have an opportunity for -O3 level "unsafe" optimizations: we could // avoid the following if() and assume value is of proper type. - if (typeof value !== "number") { - throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' +this.name); + if (typeof value !== "number" && typeof value !== "boolean") { + throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' + this.name); } return value; }, diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index 8d6dd044..23d50fe1 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -493,6 +493,15 @@ module({ assert.equal(true, cm.emval_test_not(false)); }); + test("can pass booleans as integers", function() { + assert.equal(1, cm.emval_test_as_unsigned(true)); + assert.equal(0, cm.emval_test_as_unsigned(false)); + }); + + test("can pass booleans as floats", function() { + assert.equal(2, cm.const_ref_adder(true, true)); + }); + test("convert double to unsigned", function() { var rv = cm.emval_test_as_unsigned(1.5); assert.equal('number', typeof rv); |