diff options
Diffstat (limited to 'src/embind/embind.js')
-rwxr-xr-x | src/embind/embind.js | 17 |
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'); |