aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-09-20 14:13:43 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-09-20 14:13:43 -0700
commitd9e13a5a3ceeaa500e9c75e52547c8b67950c441 (patch)
tree986b6af442e8c503bedab9912e8913dbd129d2e1 /src
parentafa818a5cbc78bb862f0cae8b305c8033a5b0fc3 (diff)
parent83c6675368ce14ee34b52147792b1073a074ed24 (diff)
Merge branch 'incoming'
Diffstat (limited to 'src')
-rw-r--r--src/library_browser.js21
-rw-r--r--src/preamble.js15
2 files changed, 25 insertions, 11 deletions
diff --git a/src/library_browser.js b/src/library_browser.js
index 43732e5b..5291dcee 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -384,7 +384,7 @@ mergeInto(LibraryManager.library, {
if (Browser.mainLoop.queue.length > 0) {
var start = Date.now();
var blocker = Browser.mainLoop.queue.shift();
- blocker.func();
+ blocker.func(blocker.arg);
if (Browser.mainLoop.remainingBlockers) {
var remaining = Browser.mainLoop.remainingBlockers;
var next = remaining%1 == 0 ? remaining-1 : Math.floor(remaining);
@@ -451,13 +451,13 @@ mergeInto(LibraryManager.library, {
Browser.mainLoop.resume();
},
- _emscripten_push_main_loop_blocker: function(func, name) {
- Browser.mainLoop.queue.push({ func: FUNCTION_TABLE[func], name: Pointer_stringify(name), counted: true });
+ _emscripten_push_main_loop_blocker: function(func, arg, name) {
+ Browser.mainLoop.queue.push({ func: FUNCTION_TABLE[func], arg: arg, name: Pointer_stringify(name), counted: true });
Browser.mainLoop.updateStatus();
},
- _emscripten_push_uncounted_main_loop_blocker: function(func, name) {
- Browser.mainLoop.queue.push({ func: FUNCTION_TABLE[func], name: Pointer_stringify(name), counted: false });
+ _emscripten_push_uncounted_main_loop_blocker: function(func, arg, name) {
+ Browser.mainLoop.queue.push({ func: FUNCTION_TABLE[func], arg: arg, name: Pointer_stringify(name), counted: false });
Browser.mainLoop.updateStatus();
},
@@ -467,14 +467,17 @@ mergeInto(LibraryManager.library, {
Browser.mainLoop.updateStatus();
},
- emscripten_async_call: function(func, millis) {
+ emscripten_async_call: function(func, arg, millis) {
Module['noExitRuntime'] = true;
- var asyncCall = Runtime.getFuncWrapper(func);
+ function wrapper() {
+ Runtime.getFuncWrapper(func)(arg);
+ }
+
if (millis >= 0) {
- setTimeout(asyncCall, millis);
+ setTimeout(wrapper, millis);
} else {
- Browser.requestAnimationFrame(asyncCall);
+ Browser.requestAnimationFrame(wrapper);
}
},
diff --git a/src/preamble.js b/src/preamble.js
index b3cfca85..f1b95958 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -457,8 +457,6 @@ function getValue(ptr, type, noSafe) {
}
Module['getValue'] = getValue;
-// Allocates memory for some data and initializes it properly.
-
var ALLOC_NORMAL = 0; // Tries to use _malloc()
var ALLOC_STACK = 1; // Lives for the duration of the current function call
var ALLOC_STATIC = 2; // Cannot be freed
@@ -466,6 +464,19 @@ Module['ALLOC_NORMAL'] = ALLOC_NORMAL;
Module['ALLOC_STACK'] = ALLOC_STACK;
Module['ALLOC_STATIC'] = ALLOC_STATIC;
+// allocate(): This is for internal use. You can use it yourself as well, but the interface
+// is a little tricky (see docs right below). The reason is that it is optimized
+// for multiple syntaxes to save space in generated code. So you should
+// normally not use allocate(), and instead allocate memory using _malloc(),
+// initialize it with setValue(), and so forth.
+// @slab: An array of data, or a number. If a number, then the size of the block to allocate,
+// in *bytes* (note that this is sometimes confusing: the next parameter does not
+// affect this!)
+// @types: Either an array of types, one for each byte (or 0 if no type at that position),
+// or a single type which is used for the entire block. This only matters if there
+// is initial data - if @slab is a number, then this does not matter at all and is
+// ignored.
+// @allocator: How to allocate memory, see ALLOC_*
function allocate(slab, types, allocator) {
var zeroinit, size;
if (typeof slab === 'number') {