aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-04-15 21:29:01 -0700
committerJukka Jylänki <jujjyl@gmail.com>2013-04-18 20:08:14 +0300
commitd2e6efdf4821ff1e9f16fc4884d398619c0d7a06 (patch)
tree1df7e4f5a824078df779381714085a2adacf5121
parente53dd06bf9ca763a65f8bc77dd3ae980843e8652 (diff)
can pass ArrayBuffer to std::string
-rwxr-xr-xsrc/embind/embind.js4
-rwxr-xr-xtests/embind/embind.test.js5
2 files changed, 9 insertions, 0 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 078b5c1c..bd13087d 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 (value instanceof ArrayBuffer) {
+ value = new Uint8Array(value);
+ }
+
function getTAElement(ta, index) {
return ta[index];
}
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 821355d2..82029de4 100755
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -419,6 +419,11 @@ module({
assert.equal('ABCD', e);
});
+ test("can pass ArrayBuffer to std::string", function() {
+ var e = cm.emval_test_take_and_return_std_string((new Int8Array([65, 66, 67, 68])).buffer);
+ assert.equal('ABCD', e);
+ });
+
test("non-ascii wstrings", function() {
var expected = String.fromCharCode(10) +
String.fromCharCode(1234) +