diff options
-rwxr-xr-x | src/embind/embind.js | 4 | ||||
-rwxr-xr-x | tests/embind/embind.test.js | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index 9afbf2fb..5fc8c948 100755 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -348,6 +348,10 @@ function __embind_register_std_string(rawType, name) { return a.join(''); }, toWireType: function(destructors, value) { + if (typeof value !== "string") { + throwBindingError('Cannot pass non-string to std::string'); + } + // assumes 4-byte alignment var length = value.length; var ptr = _malloc(4 + length); diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index fec7145a..6473573a 100755 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -403,6 +403,12 @@ module({ }); }); + test("can't pass integers as strings", function() { + var e = assert.throws(cm.BindingError, function() { + cm.emval_test_take_and_return_std_string(10); + }); + }); + test("non-ascii wstrings", function() { var expected = String.fromCharCode(10) + String.fromCharCode(1234) + |