aboutsummaryrefslogtreecommitdiff
path: root/src/preamble.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/preamble.js')
-rw-r--r--src/preamble.js48
1 files changed, 3 insertions, 45 deletions
diff --git a/src/preamble.js b/src/preamble.js
index 997e5ab3..ae00b796 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -326,6 +326,7 @@ function ccall(ident, returnType, argTypes, args) {
var stack = 0;
function toC(value, type) {
if (type == 'string') {
+ if (value === null || value === undefined || value === 0) return 0; // null string
if (!stack) stack = Runtime.stackSave();
var ret = Runtime.stackAlloc(value.length+1);
writeStringToMemory(value, ret);
@@ -721,40 +722,6 @@ function exitRuntime() {
CorrectionsMonitor.print();
}
-
-// Copies a list of num items on the HEAP into a
-// a normal JavaScript array of numbers
-function Array_copy(ptr, num) {
-#if USE_TYPED_ARRAYS == 1
- // TODO: In the SAFE_HEAP case, do some reading here, for debugging purposes - currently this is an 'unnoticed read'.
- return Array.prototype.slice.call(IHEAP.subarray(ptr, ptr+num)); // Make a normal array out of the typed 'view'
- // Consider making a typed array here, for speed?
-#endif
-#if USE_TYPED_ARRAYS == 2
- return Array.prototype.slice.call(HEAP8.subarray(ptr, ptr+num)); // Make a normal array out of the typed 'view'
- // Consider making a typed array here, for speed?
-#endif
- return HEAP.slice(ptr, ptr+num);
-}
-Module['Array_copy'] = Array_copy;
-
-#if USE_TYPED_ARRAYS
-// Copies a list of num items on the HEAP into a
-// JavaScript typed array.
-function TypedArray_copy(ptr, num, offset /*optional*/) {
- // TODO: optimize this!
- if (offset === undefined) {
- offset = 0;
- }
- var arr = new Uint8Array(num - offset);
- for (var i = offset; i < num; ++i) {
- arr[i - offset] = {{{ makeGetValue('ptr', 'i', 'i8') }}};
- }
- return arr.buffer;
-}
-Module['TypedArray_copy'] = TypedArray_copy;
-#endif
-
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
@@ -762,17 +729,6 @@ function String_len(ptr) {
}
Module['String_len'] = String_len;
-// Copies a C-style string, terminated by a zero, from the HEAP into
-// a normal JavaScript array of numbers
-function String_copy(ptr, addZero) {
- var len = String_len(ptr);
- if (addZero) len++;
- var ret = Array_copy(ptr, len);
- if (addZero) ret[len-1] = 0;
- return ret;
-}
-Module['String_copy'] = String_copy;
-
// Tools
// This processes a JS string into a C-line array of numbers, 0-terminated.
@@ -864,6 +820,7 @@ function addRunDependency() {
Module['monitorRunDependencies'](runDependencies);
}
}
+Module['addRunDependency'] = addRunDependency;
function removeRunDependency() {
runDependencies--;
if (Module['monitorRunDependencies']) {
@@ -871,6 +828,7 @@ function removeRunDependency() {
}
if (runDependencies == 0) run();
}
+Module['removeRunDependency'] = removeRunDependency;
// === Body ===