aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEhsan Akhgari <ehsan.akhgari@gmail.com>2012-01-24 16:32:54 -0500
committerEhsan Akhgari <ehsan.akhgari@gmail.com>2012-01-24 16:32:54 -0500
commit47e2885417baef4683c4ed4b2fb667b2fcde4883 (patch)
tree8486b98fb80f43f080e5ccd1c9ce7bafc370c456 /src
parent9bbb3f7c01a20534181b15645579d851f922aa98 (diff)
Add a copy helper for typed arrays
Diffstat (limited to 'src')
-rw-r--r--src/preamble.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/preamble.js b/src/preamble.js
index f19a68f1..e94d807b 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -692,6 +692,18 @@ function Array_copy(ptr, num) {
}
Module['Array_copy'] = Array_copy;
+// Copies a list of num items on the HEAP into a
+// JavaScript typed array.
+function TypedArray_copy(ptr, num) {
+ // TODO: optimize this!
+ var arr = new Uint8Array(num);
+ for (var i = 0; i < num; ++i) {
+ arr[i] = {{{ makeGetValue('ptr', 'i', 'i8') }}};
+ }
+ return arr.buffer;
+}
+Module['TypedArray_copy'] = TypedArray_copy;
+
function String_len(ptr) {
var i = 0;
while ({{{ makeGetValue('ptr', 'i', 'i8') }}}) i++; // Note: should be |!= 0|, technically. But this helps catch bugs with undefineds