diff options
author | Chad Austin <chad@imvu.com> | 2013-04-11 00:14:23 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-18 20:08:11 +0300 |
commit | 6ca9bffb114f206c13d9954be32d6b8034ce5eef (patch) | |
tree | 1bb5f27bfd1cc8adacf9e3b40ab08f32893de27f /src/embind | |
parent | 53c228a260b7a5e90e430860e130ed6006bd328a (diff) |
assert if, when trying to convert JS string to std::string, the JS string has code units that do not fit in 8 bits
Diffstat (limited to 'src/embind')
-rwxr-xr-x | src/embind/embind.js | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index f66b0495..f9b15fa3 100755 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -336,7 +336,12 @@ function __embind_register_std_string(rawType, name) { var ptr = _malloc(4 + length); HEAPU32[ptr >> 2] = length; for (var i = 0; i < length; ++i) { - HEAPU8[ptr + 4 + i] = value.charCodeAt(i); + var charCode = value.charCodeAt(i); + if (charCode > 255) { + _free(ptr); + throwBindingError('String has UTF-16 code units that do not fit in 8 bits'); + } + HEAPU8[ptr + 4 + i] = charCode; } destructors.push(_free, ptr); return ptr; |