aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/analyzer.js3
-rw-r--r--src/emrun_postjs.js20
-rw-r--r--src/jsifier.js2
-rw-r--r--src/library_fs.js2
-rw-r--r--src/library_gl.js17
-rw-r--r--src/library_glfw.js8
-rw-r--r--src/library_sdl.js5
-rw-r--r--src/modules.js20
8 files changed, 65 insertions, 12 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 253c5505..17582ea3 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -1662,11 +1662,13 @@ function analyzer(data, sidePass) {
function stackAnalyzer() {
data.functions.forEach(function(func) {
var lines = func.labels[0].lines;
+ var hasAlloca = false;
for (var i = 0; i < lines.length; i++) {
var item = lines[i];
if (!item.assignTo || item.intertype != 'alloca' || !isNumber(item.ident)) break;
item.allocatedSize = func.variables[item.assignTo].impl === VAR_EMULATED ?
calcAllocatedSize(item.allocatedType)*item.ident: 0;
+ hasAlloca = true;
if (USE_TYPED_ARRAYS === 2) {
// We need to keep the stack aligned
item.allocatedSize = Runtime.forceAlign(item.allocatedSize, Runtime.STACK_ALIGN);
@@ -1682,6 +1684,7 @@ function analyzer(data, sidePass) {
}
func.initialStack = index;
func.otherStackAllocations = false;
+ if (func.initialStack === 0 && hasAlloca) func.otherStackAllocations = true; // a single alloca of zero still requires us to emit stack support code
while (func.initialStack == 0) { // one-time loop with possible abort in the middle
// If there is no obvious need for stack management, perhaps we don't need it
// (we try to optimize that way with SKIP_STACK_IN_SMALL). However,
diff --git a/src/emrun_postjs.js b/src/emrun_postjs.js
new file mode 100644
index 00000000..e1ef9e2d
--- /dev/null
+++ b/src/emrun_postjs.js
@@ -0,0 +1,20 @@
+function emrun_register_handlers() {
+ function post(msg) {
+ var http = new XMLHttpRequest();
+ http.open("POST", "stdio.html", true);
+ http.send(msg);
+ }
+ // If the address contains localhost, we can assume we're running the test runner and should post stdout logs.
+ if (document.URL.search("localhost") != -1) {
+ var emrun_http_sequence_number = 1;
+ var prevExit = Module['exit'];
+ var prevPrint = Module['print'];
+ var prevErr = Module['printErr'];
+ Module['exit'] = function emrun_exit(returncode) { post('^exit^'+returncode); prevExit(returncode); }
+ Module['print'] = function emrun_print(text) { post('^out^'+(emrun_http_sequence_number++)+'^'+text); prevPrint(text); }
+ Module['printErr'] = function emrun_printErr(text) { post('^err^'+(emrun_http_sequence_number++)+'^'+text); prevErr(text); }
+ }
+ // Notify emrun web server that this browser has successfully launched the page.
+ post('^pageload^');
+}
+emrun_register_handlers();
diff --git a/src/jsifier.js b/src/jsifier.js
index b5502741..6b831b04 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1859,7 +1859,7 @@ function JSify(data, functionsOnly, givenFunctions) {
// first row are utilities called from generated code, second are needed from fastLong
['i64Add', 'i64Subtract', 'bitshift64Shl', 'bitshift64Lshr', 'bitshift64Ashr',
'llvm_ctlz_i32', 'llvm_cttz_i32'].forEach(function(func) {
- if (!Functions.libraryFunctions[func] || (phase == 'glue' && func[0] === 'l')) { // TODO: one-by-one in fastcomp glue mode
+ if (!Functions.libraryFunctions[func] || (phase == 'glue' && func[0] === 'l' && !addedLibraryItems[func])) { // TODO: one-by-one in fastcomp glue mode
print(processLibraryFunction(LibraryManager.library[func], func)); // must be first to be close to generated code
Functions.implementedFunctions['_' + func] = LibraryManager.library[func + '__sig'];
Functions.libraryFunctions[func] = phase == 'glue' ? 2 : 1; // XXX
diff --git a/src/library_fs.js b/src/library_fs.js
index 5412185f..1e7856aa 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -961,7 +961,7 @@ mergeInto(LibraryManager.library, {
throw new FS.ErrnoError(ERRNO_CODES.EACCES);
}
if (!stream.stream_ops.mmap) {
- throw new FS.errnoError(ERRNO_CODES.ENODEV);
+ throw new FS.ErrnoError(ERRNO_CODES.ENODEV);
}
return stream.stream_ops.mmap(stream, buffer, offset, length, position, prot, flags);
},
diff --git a/src/library_gl.js b/src/library_gl.js
index cc39b048..29f78c8a 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -210,21 +210,30 @@ var LibraryGL = {
},
get: function(name_, p, type) {
+ // Guard against user passing a null pointer.
+ // Note that GLES2 spec does not say anything about how passing a null pointer should be treated.
+ // Testing on desktop core GL 3, the application crashes on glGetIntegerv to a null pointer, but
+ // better to report an error instead of doing anything random.
+ if (!p) {
+#if GL_ASSERTIONS
+ Module.printErr('GL_INVALID_VALUE in glGet' + type + 'v(name=' + name_ + ': Function called with null out pointer!');
+#endif
+ GL.recordError(0x0501 /* GL_INVALID_VALUE */);
+ return;
+ }
var ret = undefined;
switch(name_) { // Handle a few trivial GLES values
case 0x8DFA: // GL_SHADER_COMPILER
ret = 1;
break;
case 0x8DF8: // GL_SHADER_BINARY_FORMATS
- if (type === 'Integer') {
- // fall through, see gles2_conformance.cpp
- } else {
+ if (type !== 'Integer') {
GL.recordError(0x0500); // GL_INVALID_ENUM
#if GL_ASSERTIONS
Module.printErr('GL_INVALID_ENUM in glGet' + type + 'v(GL_SHADER_BINARY_FORMATS): Invalid parameter type!');
#endif
- return;
}
+ return; // Do not write anything to the out pointer, since no binary formats are supported.
case 0x8DF9: // GL_NUM_SHADER_BINARY_FORMATS
ret = 0;
break;
diff --git a/src/library_glfw.js b/src/library_glfw.js
index 647d4bb6..17e8956a 100644
--- a/src/library_glfw.js
+++ b/src/library_glfw.js
@@ -120,7 +120,6 @@ var LibraryGLFW = {
if (event.charCode) {
var char = GLFW.getUnicodeChar(event.charCode);
if (char !== null && GLFW.charFunc) {
- event.preventDefault();
Runtime.dynCall('vii', GLFW.charFunc, [event.charCode, 1]);
}
}
@@ -130,13 +129,18 @@ var LibraryGLFW = {
var key = GLFW.DOMToGLFWKeyCode(event.keyCode);
if (key && GLFW.keyFunc) {
GLFW.keys[key] = status;
- event.preventDefault();
Runtime.dynCall('vii', GLFW.keyFunc, [key, status]);
}
},
onKeydown: function(event) {
GLFW.onKeyChanged(event, 1);//GLFW_PRESS
+ // This logic comes directly from the sdl implementation. We cannot
+ // call preventDefault on all keydown events otherwise onKeyPress will
+ // not get called
+ if (event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */) {
+ event.preventDefault();
+ }
},
onKeyup: function(event) {
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 40e5e3ab..2efc1271 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -1247,10 +1247,7 @@ var LibrarySDL = {
return 0;
},
- SDL_LowerBlit__deps: ['SDL_UpperBlit'],
- SDL_LowerBlit: function(src, srcrect, dst, dstrect) {
- return _SDL_UpperBlit(src, srcrect, dst, dstrect);
- },
+ SDL_LowerBlit: 'SDL_UpperBlit',
SDL_FillRect: function(surf, rect, color) {
var surfData = SDL.surfaces[surf];
diff --git a/src/modules.js b/src/modules.js
index b9b8ab5e..3e7405f8 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -429,6 +429,26 @@ var LibraryManager = {
eval(processMacros(preprocess(read(libraries[i]))));
}
+ /*
+ // export code for CallHandlers.h
+ printErr('============================');
+ for (var x in this.library) {
+ var y = this.library[x];
+ if (typeof y === 'string' && x.indexOf('__sig') < 0 && x.indexOf('__postset') < 0 && y.indexOf(' ') < 0) {
+ printErr('DEF_REDIRECT_HANDLER(' + x + ', ' + y + ');');
+ }
+ }
+ printErr('============================');
+ for (var x in this.library) {
+ var y = this.library[x];
+ if (typeof y === 'string' && x.indexOf('__sig') < 0 && x.indexOf('__postset') < 0 && y.indexOf(' ') < 0) {
+ printErr(' SETUP_CALL_HANDLER(' + x + ');');
+ }
+ }
+ printErr('============================');
+ // end export code for CallHandlers.h
+ */
+
this.loaded = true;
},