aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-05-09 12:39:22 -0700
committerChad Austin <chad@imvu.com>2013-05-17 12:58:29 -0700
commit17ab8d9f57f0cb31d2d83555ae898b32b99600f8 (patch)
tree9962bf393588bc1a45cb71938ae0a5bfc5c6b8a0
parent0074368080bee713232e0b152dc0cae790ec34d3 (diff)
Allow implicit conversion from booleans to ints/floats (for WebGL)
-rw-r--r--src/embind/embind.js6
-rw-r--r--tests/embind/embind.test.js9
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);