diff options
author | Chad Austin <chad@imvu.com> | 2013-04-15 17:40:16 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-18 20:08:13 +0300 |
commit | 181e6abb2f3abb9c3dc07d769adb84f6bc5982bc (patch) | |
tree | ac50bde1a70e95087d61081597dba21d214bf332 | |
parent | a9539326b89fec17dfe7fb4315eb5d256a1afcf6 (diff) |
cannot pass non-strings to std::string arguments :)
-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) + |