aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-04-15 21:15:13 -0700
committerJukka Jylänki <jujjyl@gmail.com>2013-04-18 20:08:14 +0300
commite53dd06bf9ca763a65f8bc77dd3ae980843e8652 (patch)
tree14571b59144cf67562a2e2989031bd80ce33b057 /src
parent181e6abb2f3abb9c3dc07d769adb84f6bc5982bc (diff)
allow passing Int8Array and Uint8Array directly to std::string
Diffstat (limited to 'src')
-rwxr-xr-xsrc/embind/embind.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 5fc8c948..078b5c1c 100755
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -348,7 +348,20 @@ function __embind_register_std_string(rawType, name) {
return a.join('');
},
toWireType: function(destructors, value) {
- if (typeof value !== "string") {
+ function getTAElement(ta, index) {
+ return ta[index];
+ }
+ function getStringElement(string, index) {
+ return string.charCodeAt(index);
+ }
+ var getElement;
+ if (value instanceof Uint8Array) {
+ getElement = getTAElement;
+ } else if (value instanceof Int8Array) {
+ getElement = getTAElement;
+ } else if (typeof value === 'string') {
+ getElement = getStringElement;
+ } else {
throwBindingError('Cannot pass non-string to std::string');
}
@@ -357,7 +370,7 @@ function __embind_register_std_string(rawType, name) {
var ptr = _malloc(4 + length);
HEAPU32[ptr >> 2] = length;
for (var i = 0; i < length; ++i) {
- var charCode = value.charCodeAt(i);
+ var charCode = getElement(value, i);
if (charCode > 255) {
_free(ptr);
throwBindingError('String has UTF-16 code units that do not fit in 8 bits');