summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS2
-rw-r--r--CONTRIBUTING.markdown5
-rwxr-xr-xemcc6
-rwxr-xr-xemscripten.py2
-rw-r--r--src/analyzer.js2
-rw-r--r--src/intertyper.js10
-rw-r--r--src/jsifier.js24
-rw-r--r--src/library.js106
-rw-r--r--src/library_browser.js50
-rw-r--r--src/library_egl.js8
-rw-r--r--src/library_fs.js210
-rw-r--r--src/library_gl.js168
-rw-r--r--src/library_glfw.js4
-rw-r--r--src/library_glut.js6
-rw-r--r--src/library_idbfs.js28
-rw-r--r--src/library_memfs.js106
-rw-r--r--src/library_nodefs.js12
-rw-r--r--src/library_path.js22
-rw-r--r--src/library_sdl.js60
-rw-r--r--src/library_sockfs.js4
-rw-r--r--src/parseTools.js103
-rw-r--r--src/preamble.js16
-rw-r--r--src/proxyClient.js2
-rw-r--r--src/proxyWorker.js20
-rw-r--r--src/runtime.js8
-rw-r--r--src/settings.js3
-rw-r--r--src/shell.html5
-rw-r--r--src/shell.js22
-rw-r--r--system/include/compat/ctype.h17
-rw-r--r--system/include/compat/wchar.h23
-rw-r--r--system/include/compat/wctype.h23
-rw-r--r--system/include/emscripten/vector.h10
-rw-r--r--tests/aniso.c3
-rw-r--r--tests/cases/caall.ll2
-rw-r--r--tests/cases/selectadd.ll29
-rw-r--r--tests/cubegeom.c6
-rw-r--r--tests/mmap_file.c27
-rw-r--r--tests/test_browser.py53
-rw-r--r--tests/test_core.py180
-rw-r--r--tests/test_other.py87
-rw-r--r--tests/test_sanity.py6
-rw-r--r--tests/test_webgl_context_attributes_common.c262
-rw-r--r--tests/test_webgl_context_attributes_glfw.c47
-rw-r--r--tests/test_webgl_context_attributes_glut.c42
-rw-r--r--tests/test_webgl_context_attributes_sdl.c50
-rw-r--r--tools/file_packager.py62
-rw-r--r--tools/js_optimizer.py8
-rw-r--r--tools/shared.py2
48 files changed, 1425 insertions, 528 deletions
diff --git a/AUTHORS b/AUTHORS
index 5ad3f98d..5c49e65e 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -104,4 +104,6 @@ a license to everyone to use it as detailed in LICENSE.)
* Daniel Aquino <mr.danielaquino@gmail.com>
* Remi Papillie <remi.papillie@gmail.com>
* Fraser Adams <fraser.adams@blueyonder.co.uk>
+* Michael Tirado <icetooth333@gmail.com>
+* Ben Noordhuis <info@bnoordhuis.nl>
diff --git a/CONTRIBUTING.markdown b/CONTRIBUTING.markdown
new file mode 100644
index 00000000..ceea8735
--- /dev/null
+++ b/CONTRIBUTING.markdown
@@ -0,0 +1,5 @@
+
+See our wiki for information about contributing to Emscripten:
+
+[Contribution section on wiki](https://github.com/kripken/emscripten/wiki#contributing)
+
diff --git a/emcc b/emcc
index 3406ff83..8f8ad4aa 100755
--- a/emcc
+++ b/emcc
@@ -777,6 +777,7 @@ try:
save_bc = False
memory_init_file = False
use_preload_cache = False
+ no_heap_copy = False
proxy_to_worker = False
if use_cxx:
@@ -897,6 +898,9 @@ try:
elif newargs[i].startswith('--use-preload-cache'):
use_preload_cache = True
newargs[i] = ''
+ elif newargs[i].startswith('--no-heap-copy'):
+ no_heap_copy = True
+ newargs[i] = ''
elif newargs[i] == '--ignore-dynamic-linking':
ignore_dynamic_linking = True
newargs[i] = ''
@@ -1667,6 +1671,8 @@ try:
file_args += ['--compress', Compression.encoder, Compression.decoder, Compression.js_name]
if use_preload_cache:
file_args.append('--use-preload-cache')
+ if no_heap_copy:
+ file_args.append('--no-heap-copy')
file_code = execute([shared.PYTHON, shared.FILE_PACKAGER, unsuffixed(target) + '.data'] + file_args, stdout=PIPE)[0]
pre_js = file_code + pre_js
diff --git a/emscripten.py b/emscripten.py
index dbea6eb2..5576baba 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -578,7 +578,7 @@ var asm = (function(global, env, buffer) {
var HEAPU32 = new global.Uint32Array(buffer);
var HEAPF32 = new global.Float32Array(buffer);
var HEAPF64 = new global.Float64Array(buffer);
-''' % (asm_setup, "'use asm';" if not forwarded_json['Types']['hasInlineJS'] and not settings['SIDE_MODULE'] else "'almost asm';") + '\n' + asm_global_vars + '''
+''' % (asm_setup, "'use asm';" if not forwarded_json['Types']['hasInlineJS'] and not settings['SIDE_MODULE'] and settings['ASM_JS'] == 1 else "'almost asm';") + '\n' + asm_global_vars + '''
var __THREW__ = 0;
var threwValue = 0;
var setjmpId = 0;
diff --git a/src/analyzer.js b/src/analyzer.js
index 2b74a83f..253c5505 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -418,7 +418,7 @@ function analyzer(data, sidePass) {
toAdd.push({
intertype: 'value',
assignTo: element.ident,
- type: element.bits,
+ type: 'i' + element.bits,
ident: 'tempRet' + (j - 1)
});
assert(j<10); // TODO: dynamically create more than 10 tempRet-s
diff --git a/src/intertyper.js b/src/intertyper.js
index d3640889..fceeb38d 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -682,7 +682,7 @@ function intertyper(lines, sidePass, baseLineNums) {
}
if (item.assignTo) item.ident = 'return ' + item.ident;
item.ident = '(function(' + params + ') { ' + item.ident + ' })(' + args + ');';
- return { forward: null, ret: item, item: item };
+ return { ret: item, item: item };
}
if (item.ident.substr(-2) == '()') {
// See comment in isStructType()
@@ -705,13 +705,12 @@ function intertyper(lines, sidePass, baseLineNums) {
if (item.indent == 2) {
// standalone call - not in assign
item.standalone = true;
- return { forward: null, ret: item, item: item };
+ return { ret: item, item: item };
}
- return { forward: item, ret: null, item: item };
+ return { ret: null, item: item };
}
function callHandler(item) {
var result = makeCall.call(this, item, 'call');
- if (result.forward) this.forwardItem(result.forward, 'Reintegrator');
return result.ret;
}
function invokeHandler(item) {
@@ -721,10 +720,9 @@ function intertyper(lines, sidePass, baseLineNums) {
finalResults.push({
intertype: 'branch',
label: result.item.toLabel,
- lineNum: (result.forward ? item.parentLineNum : item.lineNum) + 0.5
+ lineNum: item.lineNum + 0.5
});
}
- if (result.forward) this.forwardItem(result.forward, 'Reintegrator');
return result.ret;
}
function atomicHandler(item) {
diff --git a/src/jsifier.js b/src/jsifier.js
index b36e11ed..0da48a8c 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -948,11 +948,12 @@ function JSify(data, functionsOnly, givenFunctions) {
}
if (item.valueType[item.valueType.length-1] === '>') {
// vector store TODO: move to makeSetValue?
- var base = getVectorBaseType(item.valueType);
- return '(' + makeSetValue(item.ident, 0, value + '.x', base, 0, 0, item.align) + ',' +
- makeSetValue(item.ident, 4, value + '.y', base, 0, 0, item.align) + ',' +
- makeSetValue(item.ident, 8, value + '.z', base, 0, 0, item.align) + ',' +
- makeSetValue(item.ident, 12, value + '.w', base, 0, 0, item.align) + ')';
+ var native = getVectorNativeType(item.valueType);
+ var base = getSIMDName(native);
+ return '(' + makeSetValue(item.ident, 0, value + '.x', native, 0, 0, item.align) + ',' +
+ makeSetValue(item.ident, 4, value + '.y', native, 0, 0, item.align) + ',' +
+ makeSetValue(item.ident, 8, value + '.z', native, 0, 0, item.align) + ',' +
+ makeSetValue(item.ident, 12, value + '.w', native, 0, 0, item.align) + ');';
}
switch (impl) {
case VAR_NATIVIZED:
@@ -1323,11 +1324,12 @@ function JSify(data, functionsOnly, givenFunctions) {
var value = finalizeLLVMParameter(item.pointer);
if (item.valueType[item.valueType.length-1] === '>') {
// vector load
- var base = getVectorBaseType(item.valueType);
- return base + '32x4(' + makeGetValue(value, 0, base, 0, item.unsigned, 0, item.align) + ',' +
- makeGetValue(value, 4, base, 0, item.unsigned, 0, item.align) + ',' +
- makeGetValue(value, 8, base, 0, item.unsigned, 0, item.align) + ',' +
- makeGetValue(value, 12, base, 0, item.unsigned, 0, item.align) + ')';
+ var native = getVectorNativeType(item.valueType);
+ var base = getSIMDName(native);
+ return base + '32x4(' + makeGetValue(value, 0, native, 0, item.unsigned, 0, item.align) + ',' +
+ makeGetValue(value, 4, native, 0, item.unsigned, 0, item.align) + ',' +
+ makeGetValue(value, 8, native, 0, item.unsigned, 0, item.align) + ',' +
+ makeGetValue(value, 12, native, 0, item.unsigned, 0, item.align) + ');';
}
var impl = item.ident ? getVarImpl(item.funcData, item.ident) : VAR_EMULATED;
switch (impl) {
@@ -1489,7 +1491,7 @@ function JSify(data, functionsOnly, givenFunctions) {
}
params.forEach(function(param, i) {
- var val = finalizeParam(param);
+ var val = finalizeLLVMParameter(param);
if (!hasVarArgs || useJSArgs || i < normalArgs) {
args.push(val);
argsTypes.push(param.type);
diff --git a/src/library.js b/src/library.js
index 875d8bab..501f766c 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1579,12 +1579,12 @@ LibraryManager.library = {
// stdio.h
// ==========================================================================
- _isFloat: function(text) {
- return !!(/^[+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?$/.exec(text));
+ _getFloat: function(text) {
+ return /^[+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?/.exec(text);
},
// TODO: Document.
- _scanString__deps: ['_isFloat'],
+ _scanString__deps: ['_getFloat'],
_scanString: function(format, get, unget, varargs) {
if (!__scanString.whiteSpace) {
__scanString.whiteSpace = {};
@@ -1602,12 +1602,12 @@ LibraryManager.library = {
if (format.indexOf('%n') >= 0) {
// need to track soFar
var _get = get;
- get = function() {
+ get = function get() {
soFar++;
return _get();
}
var _unget = unget;
- unget = function() {
+ unget = function unget() {
soFar--;
return _unget();
}
@@ -1743,15 +1743,13 @@ LibraryManager.library = {
// Read characters according to the format. floats are trickier, they may be in an unfloat state in the middle, then be a valid float later
if (type == 'f' || type == 'e' || type == 'g' ||
type == 'F' || type == 'E' || type == 'G') {
- var last = 0;
next = get();
- while (next > 0) {
+ while (next > 0 && (!(next in __scanString.whiteSpace))) {
buffer.push(String.fromCharCode(next));
- if (__isFloat(buffer.join(''))) {
- last = buffer.length;
- }
next = get();
}
+ var m = __getFloat(buffer.join(''));
+ var last = m ? m[0].length : 0;
for (var i = 0; i < buffer.length - last + 1; i++) {
unget();
}
@@ -2757,12 +2755,12 @@ LibraryManager.library = {
return -1;
}
var buffer = [];
- var get = function() {
+ function get() {
var c = _fgetc(stream);
buffer.push(c);
return c;
};
- var unget = function() {
+ function unget() {
_ungetc(buffer.pop(), stream);
};
return __scanString(format, get, unget, varargs);
@@ -2779,8 +2777,8 @@ LibraryManager.library = {
// int sscanf(const char *restrict s, const char *restrict format, ... );
// http://pubs.opengroup.org/onlinepubs/000095399/functions/scanf.html
var index = 0;
- var get = function() { return {{{ makeGetValue('s', 'index++', 'i8') }}}; };
- var unget = function() { index--; };
+ function get() { return {{{ makeGetValue('s', 'index++', 'i8') }}}; };
+ function unget() { index--; };
return __scanString(format, get, unget, varargs);
},
snprintf__deps: ['_formatString'],
@@ -3042,7 +3040,7 @@ LibraryManager.library = {
},
bsearch: function(key, base, num, size, compar) {
- var cmp = function(x, y) {
+ function cmp(x, y) {
#if ASM_JS
return Module['dynCall_iii'](compar, x, y);
#else
@@ -5110,7 +5108,7 @@ LibraryManager.library = {
table[from + i] = {};
sigs.forEach(function(sig) { // TODO: new Function etc.
var full = 'dynCall_' + sig;
- table[from + i][sig] = function() {
+ table[from + i][sig] = function dynCall_sig() {
arguments[0] -= from;
return asm[full].apply(null, arguments);
}
@@ -5134,7 +5132,7 @@ LibraryManager.library = {
// patch js module dynCall_* to use functionTable
sigs.forEach(function(sig) {
- jsModule['dynCall_' + sig] = function() {
+ jsModule['dynCall_' + sig] = function dynCall_sig() {
return table[arguments[0]][sig].apply(null, arguments);
};
});
@@ -5297,6 +5295,16 @@ LibraryManager.library = {
}
},
+ dladdr: function(addr, info) {
+ // report all function pointers as coming from this program itself XXX not really correct in any way
+ var fname = allocate(intArrayFromString("/bin/this.program"), 'i8', ALLOC_NORMAL); // XXX leak
+ {{{ makeSetValue('addr', 0, 'fname', 'i32') }}};
+ {{{ makeSetValue('addr', QUANTUM_SIZE, '0', 'i32') }}};
+ {{{ makeSetValue('addr', QUANTUM_SIZE*2, '0', 'i32') }}};
+ {{{ makeSetValue('addr', QUANTUM_SIZE*3, '0', 'i32') }}};
+ return 1;
+ },
+
// ==========================================================================
// pwd.h
// ==========================================================================
@@ -5598,7 +5606,7 @@ LibraryManager.library = {
var WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
- var leadingSomething = function(value, digits, character) {
+ function leadingSomething(value, digits, character) {
var str = typeof value === 'number' ? value.toString() : (value || '');
while (str.length < digits) {
str = character[0]+str;
@@ -5606,12 +5614,12 @@ LibraryManager.library = {
return str;
};
- var leadingNulls = function(value, digits) {
+ function leadingNulls(value, digits) {
return leadingSomething(value, digits, '0');
};
- var compareByDay = function(date1, date2) {
- var sgn = function(value) {
+ function compareByDay(date1, date2) {
+ function sgn(value) {
return value < 0 ? -1 : (value > 0 ? 1 : 0);
};
@@ -5624,7 +5632,7 @@ LibraryManager.library = {
return compare;
};
- var getFirstWeekStartDate = function(janFourth) {
+ function getFirstWeekStartDate(janFourth) {
switch (janFourth.getDay()) {
case 0: // Sunday
return new Date(janFourth.getFullYear()-1, 11, 29);
@@ -5643,7 +5651,7 @@ LibraryManager.library = {
}
};
- var getWeekBasedYear = function(date) {
+ function getWeekBasedYear(date) {
var thisDate = __addDays(new Date(date.tm_year+1900, 0, 1), date.tm_yday);
var janFourthThisYear = new Date(thisDate.getFullYear(), 0, 4);
@@ -5930,8 +5938,8 @@ LibraryManager.library = {
var matches = new RegExp('^'+pattern).exec(Pointer_stringify(buf))
// Module['print'](Pointer_stringify(buf)+ ' is matched by '+((new RegExp('^'+pattern)).source)+' into: '+JSON.stringify(matches));
- var initDate = function() {
- var fixup = function(value, min, max) {
+ function initDate() {
+ function fixup(value, min, max) {
return (typeof value !== 'number' || isNaN(value)) ? min : (value>=min ? (value<=max ? value: max): min);
};
return {
@@ -5948,7 +5956,7 @@ LibraryManager.library = {
var date = initDate();
var value;
- var getMatch = function(symbol) {
+ function getMatch(symbol) {
var pos = capture.indexOf(symbol);
// check if symbol appears in regexp
if (pos >= 0) {
@@ -6878,6 +6886,10 @@ LibraryManager.library = {
pthread_mutex_trylock: function() {
return 0;
},
+ pthread_mutexattr_setpshared: function(attr, pshared) {
+ // XXX implement if/when getpshared is required
+ return 0;
+ },
pthread_cond_init: function() {},
pthread_cond_destroy: function() {},
pthread_cond_broadcast: function() {
@@ -6973,6 +6985,10 @@ LibraryManager.library = {
_pthread_cleanup_push.level = __ATEXIT__.length;
},
+ pthread_rwlock_init: function() {
+ return 0; // XXX
+ },
+
// ==========================================================================
// malloc.h
// ==========================================================================
@@ -7683,7 +7699,7 @@ LibraryManager.library = {
var session = Module['webrtc']['session'];
var peer = new Peer(broker);
var listenOptions = Module['webrtc']['hostOptions'] || {};
- peer.onconnection = function(connection) {
+ peer.onconnection = function peer_onconnection(connection) {
console.log('connected');
var addr;
/* If this peer is connecting to the host, assign 10.0.0.1 to the host so it can be
@@ -7697,7 +7713,7 @@ LibraryManager.library = {
}
connection['addr'] = addr;
Sockets.connections[addr] = connection;
- connection.ondisconnect = function() {
+ connection.ondisconnect = function connection_ondisconnect() {
console.log('disconnect');
// Don't return the host address (10.0.0.1) to the pool
if (!(session && session === Sockets.connections[addr]['route'])) {
@@ -7709,12 +7725,12 @@ LibraryManager.library = {
Module['webrtc']['ondisconnect'](peer);
}
};
- connection.onerror = function(error) {
+ connection.onerror = function connection_onerror(error) {
if (Module['webrtc']['onerror'] && 'function' === typeof Module['webrtc']['onerror']) {
Module['webrtc']['onerror'](error);
}
};
- connection.onmessage = function(label, message) {
+ connection.onmessage = function connection_onmessage(label, message) {
if ('unreliable' === label) {
handleMessage(addr, message.data);
}
@@ -7724,13 +7740,13 @@ LibraryManager.library = {
Module['webrtc']['onconnect'](peer);
}
};
- peer.onpending = function(pending) {
+ peer.onpending = function peer_onpending(pending) {
console.log('pending from: ', pending['route'], '; initiated by: ', (pending['incoming']) ? 'remote' : 'local');
};
- peer.onerror = function(error) {
+ peer.onerror = function peer_onerror(error) {
console.error(error);
};
- peer.onroute = function(route) {
+ peer.onroute = function peer_onroute(route) {
if (Module['webrtc']['onpeer'] && 'function' === typeof Module['webrtc']['onpeer']) {
Module['webrtc']['onpeer'](peer, route);
}
@@ -7746,7 +7762,7 @@ LibraryManager.library = {
console.log("unable to deliver message: ", addr, header[1], message);
}
}
- window.onbeforeunload = function() {
+ window.onbeforeunload = function window_onbeforeunload() {
var ids = Object.keys(Sockets.connections);
ids.forEach(function(id) {
Sockets.connections[id].close();
@@ -7815,7 +7831,7 @@ LibraryManager.library = {
}
info.addr = Sockets.localAddr; // 10.0.0.254
info.host = __inet_ntop4_raw(info.addr);
- info.close = function() {
+ info.close = function info_close() {
Sockets.portmap[info.port] = undefined;
}
Sockets.portmap[info.port] = info;
@@ -8547,7 +8563,13 @@ LibraryManager.library = {
return -1;
}
var arg = {{{ makeGetValue('varargs', '0', 'i32') }}};
- return FS.ioctl(stream, request, arg);
+
+ try {
+ return FS.ioctl(stream, request, arg);
+ } catch (e) {
+ FS.handleFSError(e);
+ return -1;
+ }
},
#endif
@@ -8580,7 +8602,7 @@ LibraryManager.library = {
},
emscripten_run_script_string: function(ptr) {
- var s = eval(Pointer_stringify(ptr));
+ var s = eval(Pointer_stringify(ptr)) + '';
var me = _emscripten_run_script_string;
if (!me.bufferSize || me.bufferSize < s.length+1) {
if (me.bufferSize) _free(me.buffer);
@@ -8623,6 +8645,14 @@ LibraryManager.library = {
},
//============================
+ // emscripten vector ops
+ //============================
+
+ emscripten_float32x4_signmask__inline: function(x) {
+ return x + '.signMask()';
+ },
+
+ //============================
// i64 math
//============================
@@ -8718,6 +8748,6 @@ function autoAddDeps(object, name) {
// Add aborting stubs for various libc stuff needed by libc++
['pthread_cond_signal', 'pthread_equal', 'wcstol', 'wcstoll', 'wcstoul', 'wcstoull', 'wcstof', 'wcstod', 'wcstold', 'pthread_join', 'pthread_detach', 'catgets', 'catopen', 'catclose', 'fputwc', '__lockfile', '__unlockfile'].forEach(function(aborter) {
- LibraryManager.library[aborter] = function() { throw 'TODO: ' + aborter };
+ LibraryManager.library[aborter] = function aborting_stub() { throw 'TODO: ' + aborter };
});
diff --git a/src/library_browser.js b/src/library_browser.js
index 0d5bf6db..b70dbc84 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -4,12 +4,12 @@
mergeInto(LibraryManager.library, {
$Browser__deps: ['$PATH'],
- $Browser__postset: 'Module["requestFullScreen"] = function(lockPointer, resizeCanvas) { Browser.requestFullScreen(lockPointer, resizeCanvas) };\n' + // exports
- 'Module["requestAnimationFrame"] = function(func) { Browser.requestAnimationFrame(func) };\n' +
- 'Module["setCanvasSize"] = function(width, height, noUpdates) { Browser.setCanvasSize(width, height, noUpdates) };\n' +
- 'Module["pauseMainLoop"] = function() { Browser.mainLoop.pause() };\n' +
- 'Module["resumeMainLoop"] = function() { Browser.mainLoop.resume() };\n' +
- 'Module["getUserMedia"] = function() { Browser.getUserMedia() }',
+ $Browser__postset: 'Module["requestFullScreen"] = function Module_requestFullScreen(lockPointer, resizeCanvas) { Browser.requestFullScreen(lockPointer, resizeCanvas) };\n' + // exports
+ 'Module["requestAnimationFrame"] = function Module_requestAnimationFrame(func) { Browser.requestAnimationFrame(func) };\n' +
+ 'Module["setCanvasSize"] = function Module_setCanvasSize(width, height, noUpdates) { Browser.setCanvasSize(width, height, noUpdates) };\n' +
+ 'Module["pauseMainLoop"] = function Module_pauseMainLoop() { Browser.mainLoop.pause() };\n' +
+ 'Module["resumeMainLoop"] = function Module_resumeMainLoop() { Browser.mainLoop.resume() };\n' +
+ 'Module["getUserMedia"] = function Module_getUserMedia() { Browser.getUserMedia() }',
$Browser: {
mainLoop: {
scheduler: null,
@@ -77,10 +77,10 @@ mergeInto(LibraryManager.library, {
// might create some side data structure for use later (like an Image element, etc.).
var imagePlugin = {};
- imagePlugin['canHandle'] = function(name) {
+ imagePlugin['canHandle'] = function imagePlugin_canHandle(name) {
return !Module.noImageDecoding && /\.(jpg|jpeg|png|bmp)$/i.test(name);
};
- imagePlugin['handle'] = function(byteArray, name, onload, onerror) {
+ imagePlugin['handle'] = function imagePlugin_handle(byteArray, name, onload, onerror) {
var b = null;
if (Browser.hasBlobConstructor) {
try {
@@ -103,7 +103,7 @@ mergeInto(LibraryManager.library, {
assert(typeof url == 'string', 'createObjectURL must return a url as a string');
#endif
var img = new Image();
- img.onload = function() {
+ img.onload = function img_onload() {
assert(img.complete, 'Image ' + name + ' could not be decoded');
var canvas = document.createElement('canvas');
canvas.width = img.width;
@@ -114,7 +114,7 @@ mergeInto(LibraryManager.library, {
Browser.URLObject.revokeObjectURL(url);
if (onload) onload(byteArray);
};
- img.onerror = function(event) {
+ img.onerror = function img_onerror(event) {
console.log('Image ' + url + ' could not be decoded');
if (onerror) onerror();
};
@@ -123,10 +123,10 @@ mergeInto(LibraryManager.library, {
Module['preloadPlugins'].push(imagePlugin);
var audioPlugin = {};
- audioPlugin['canHandle'] = function(name) {
+ audioPlugin['canHandle'] = function audioPlugin_canHandle(name) {
return !Module.noAudioDecoding && name.substr(-4) in { '.ogg': 1, '.wav': 1, '.mp3': 1 };
};
- audioPlugin['handle'] = function(byteArray, name, onload, onerror) {
+ audioPlugin['handle'] = function audioPlugin_handle(byteArray, name, onload, onerror) {
var done = false;
function finish(audio) {
if (done) return;
@@ -152,7 +152,7 @@ mergeInto(LibraryManager.library, {
#endif
var audio = new Audio();
audio.addEventListener('canplaythrough', function() { finish(audio) }, false); // use addEventListener due to chromium bug 124926
- audio.onerror = function(event) {
+ audio.onerror = function audio_onerror(event) {
if (done) return;
console.log('warning: browser could not fully decode audio ' + name + ', trying slower base64 approach');
function encode64(data) {
@@ -268,7 +268,7 @@ mergeInto(LibraryManager.library, {
(function(prop) {
switch (typeof tempCtx[prop]) {
case 'function': {
- wrapper[prop] = function() {
+ wrapper[prop] = function gl_wrapper() {
if (GL.debug) {
var printArgs = Array.prototype.slice.call(arguments).map(Runtime.prettyPrint);
Module.printErr('[gl_f:' + prop + ':' + printArgs + ']');
@@ -501,7 +501,7 @@ mergeInto(LibraryManager.library, {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
- xhr.onload = function() {
+ xhr.onload = function xhr_onload() {
if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
onload(xhr.response);
} else {
@@ -614,7 +614,7 @@ mergeInto(LibraryManager.library, {
http.responseType = 'arraybuffer';
// LOAD
- http.onload = function(e) {
+ http.onload = function http_onload(e) {
if (http.status == 200) {
FS.createDataFile( _file.substr(0, index), _file.substr(index + 1), new Uint8Array(http.response), true, true);
if (onload) Runtime.dynCall('vii', onload, [arg, file]);
@@ -624,12 +624,12 @@ mergeInto(LibraryManager.library, {
};
// ERROR
- http.onerror = function(e) {
+ http.onerror = function http_onerror(e) {
if (onerror) Runtime.dynCall('vii', onerror, [arg, http.status]);
};
// PROGRESS
- http.onprogress = function(e) {
+ http.onprogress = function http_onprogress(e) {
var percentComplete = (e.position / e.totalSize)*100;
if (onprogress) Runtime.dynCall('vii', onprogress, [arg, percentComplete]);
};
@@ -709,7 +709,7 @@ mergeInto(LibraryManager.library, {
assert(runDependencies === 0, 'async_load_script must be run when no other dependencies are active');
var script = document.createElement('script');
- script.onload = function() {
+ script.onload = function script_onload() {
if (runDependencies > 0) {
dependenciesFulfilled = onload;
} else {
@@ -724,7 +724,7 @@ mergeInto(LibraryManager.library, {
emscripten_set_main_loop: function(func, fps, simulateInfiniteLoop) {
Module['noExitRuntime'] = true;
- Browser.mainLoop.runner = function() {
+ Browser.mainLoop.runner = function Browser_mainLoop_runner() {
if (ABORT) return;
if (Browser.mainLoop.queue.length > 0) {
var start = Date.now();
@@ -781,11 +781,11 @@ mergeInto(LibraryManager.library, {
Browser.mainLoop.scheduler();
}
if (fps && fps > 0) {
- Browser.mainLoop.scheduler = function() {
+ Browser.mainLoop.scheduler = function Browser_mainLoop_scheduler() {
setTimeout(Browser.mainLoop.runner, 1000/fps); // doing this each time means that on exception, we stop
}
} else {
- Browser.mainLoop.scheduler = function() {
+ Browser.mainLoop.scheduler = function Browser_mainLoop_scheduler() {
Browser.requestAnimationFrame(Browser.mainLoop.runner);
}
}
@@ -874,14 +874,14 @@ mergeInto(LibraryManager.library, {
emscripten_get_now: function() {
if (!_emscripten_get_now.actual) {
if (ENVIRONMENT_IS_NODE) {
- _emscripten_get_now.actual = function() {
+ _emscripten_get_now.actual = function _emscripten_get_now_actual() {
var t = process['hrtime']();
return t[0] * 1e3 + t[1] / 1e6;
}
} else if (typeof dateNow !== 'undefined') {
_emscripten_get_now.actual = dateNow;
} else if (ENVIRONMENT_IS_WEB && window['performance'] && window['performance']['now']) {
- _emscripten_get_now.actual = function() { return window['performance']['now'](); };
+ _emscripten_get_now.actual = function _emscripten_get_now_actual() { return window['performance']['now'](); };
} else {
_emscripten_get_now.actual = Date.now;
}
@@ -899,7 +899,7 @@ mergeInto(LibraryManager.library, {
buffer: 0,
bufferSize: 0
};
- info.worker.onmessage = function(msg) {
+ info.worker.onmessage = function info_worker_onmessage(msg) {
var info = Browser.workers[id];
if (!info) return; // worker was destroyed meanwhile
var callbackId = msg.data['callbackId'];
diff --git a/src/library_egl.js b/src/library_egl.js
index 69902785..cc702fec 100644
--- a/src/library_egl.js
+++ b/src/library_egl.js
@@ -421,10 +421,10 @@ var LibraryEGL = {
if (EGL.stringCache[name]) return EGL.stringCache[name];
var ret;
switch(name) {
- case 0x3053 /* EGL_VENDOR */: ret = allocate(intArrayFromString("Emscripten"), 'i8', ALLOC_NORMAL);
- case 0x3054 /* EGL_VERSION */: ret = allocate(intArrayFromString("1.4 Emscripten EGL"), 'i8', ALLOC_NORMAL);
- case 0x3055 /* EGL_EXTENSIONS */: ret = allocate(intArrayFromString(""), 'i8', ALLOC_NORMAL); // Currently not supporting any EGL extensions.
- case 0x308D /* EGL_CLIENT_APIS */: ret = allocate(intArrayFromString("OpenGL_ES"), 'i8', ALLOC_NORMAL);
+ case 0x3053 /* EGL_VENDOR */: ret = allocate(intArrayFromString("Emscripten"), 'i8', ALLOC_NORMAL); break;
+ case 0x3054 /* EGL_VERSION */: ret = allocate(intArrayFromString("1.4 Emscripten EGL"), 'i8', ALLOC_NORMAL); break;
+ case 0x3055 /* EGL_EXTENSIONS */: ret = allocate(intArrayFromString(""), 'i8', ALLOC_NORMAL); break; // Currently not supporting any EGL extensions.
+ case 0x308D /* EGL_CLIENT_APIS */: ret = allocate(intArrayFromString("OpenGL_ES"), 'i8', ALLOC_NORMAL); break;
default:
EGL.setErrorCode(0x300C /* EGL_BAD_PARAMETER */);
return 0;
diff --git a/src/library_fs.js b/src/library_fs.js
index bd1522a8..5412185f 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -28,6 +28,7 @@ mergeInto(LibraryManager.library, {
ignorePermissions: true,
ErrnoError: null, // set during init
+ genericErrors: {},
handleFSError: function(e) {
if (!(e instanceof FS.ErrnoError)) throw e + ' : ' + stackTrace();
@@ -62,7 +63,7 @@ mergeInto(LibraryManager.library, {
}
current = FS.lookupNode(current, parts[i]);
- current_path = PATH.join(current_path, parts[i]);
+ current_path = PATH.join2(current_path, parts[i]);
// jump to the mount's root node if this is a mountpoint
if (FS.isMountpoint(current)) {
@@ -94,9 +95,11 @@ mergeInto(LibraryManager.library, {
var path;
while (true) {
if (FS.isRoot(node)) {
- return path ? PATH.join(node.mount.mountpoint, path) : node.mount.mountpoint;
+ var mount = node.mount.mountpoint;
+ if (!path) return mount;
+ return mount[mount.length-1] !== '/' ? mount + '/' + path : mount + path;
}
- path = path ? PATH.join(node.name, path) : node.name;
+ path = path ? node.name + '/' + path : node.name;
node = node.parent;
}
},
@@ -158,44 +161,50 @@ mergeInto(LibraryManager.library, {
return FS.lookup(parent, name);
},
createNode: function(parent, name, mode, rdev) {
- var node = {
- id: FS.nextInode++,
- name: name,
- mode: mode,
- node_ops: {},
- stream_ops: {},
- rdev: rdev,
- parent: null,
- mount: null
- };
- if (!parent) {
- parent = node; // root node sets parent to itself
- }
- node.parent = parent;
- node.mount = parent.mount;
- // compatibility
- var readMode = {{{ cDefine('S_IRUGO') }}} | {{{ cDefine('S_IXUGO') }}};
- var writeMode = {{{ cDefine('S_IWUGO') }}};
- // NOTE we must use Object.defineProperties instead of individual calls to
- // Object.defineProperty in order to make closure compiler happy
- Object.defineProperties(node, {
- read: {
- get: function() { return (node.mode & readMode) === readMode; },
- set: function(val) { val ? node.mode |= readMode : node.mode &= ~readMode; }
- },
- write: {
- get: function() { return (node.mode & writeMode) === writeMode; },
- set: function(val) { val ? node.mode |= writeMode : node.mode &= ~writeMode; }
- },
- isFolder: {
- get: function() { return FS.isDir(node.mode); },
- },
- isDevice: {
- get: function() { return FS.isChrdev(node.mode); },
- },
- });
- FS.hashAddNode(node);
- return node;
+ if (!FS.FSNode) {
+ FS.FSNode = function(parent, name, mode, rdev) {
+ this.id = FS.nextInode++;
+ this.name = name;
+ this.mode = mode;
+ this.node_ops = {};
+ this.stream_ops = {};
+ this.rdev = rdev;
+ this.parent = null;
+ this.mount = null;
+ if (!parent) {
+ parent = this; // root node sets parent to itself
+ }
+ this.parent = parent;
+ this.mount = parent.mount;
+ FS.hashAddNode(this);
+ };
+
+ // compatibility
+ var readMode = {{{ cDefine('S_IRUGO') }}} | {{{ cDefine('S_IXUGO') }}};
+ var writeMode = {{{ cDefine('S_IWUGO') }}};
+
+ FS.FSNode.prototype = {};
+
+ // NOTE we must use Object.defineProperties instead of individual calls to
+ // Object.defineProperty in order to make closure compiler happy
+ Object.defineProperties(FS.FSNode.prototype, {
+ read: {
+ get: function() { return (this.mode & readMode) === readMode; },
+ set: function(val) { val ? this.mode |= readMode : this.mode &= ~readMode; }
+ },
+ write: {
+ get: function() { return (this.mode & writeMode) === writeMode; },
+ set: function(val) { val ? this.mode |= writeMode : this.mode &= ~writeMode; }
+ },
+ isFolder: {
+ get: function() { return FS.isDir(this.mode); },
+ },
+ isDevice: {
+ get: function() { return FS.isChrdev(this.mode); },
+ },
+ });
+ }
+ return new FS.FSNode(parent, name, mode, rdev);
},
destroyNode: function(node) {
FS.hashRemoveNode(node);
@@ -351,24 +360,38 @@ mergeInto(LibraryManager.library, {
// object isn't directly passed in. not possible until
// SOCKFS is completed.
createStream: function(stream, fd_start, fd_end) {
+ if (!FS.FSStream) {
+ FS.FSStream = function(){};
+ FS.FSStream.prototype = {};
+ // compatibility
+ Object.defineProperties(FS.FSStream.prototype, {
+ object: {
+ get: function() { return this.node; },
+ set: function(val) { this.node = val; }
+ },
+ isRead: {
+ get: function() { return (this.flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_WRONLY') }}}; }
+ },
+ isWrite: {
+ get: function() { return (this.flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_RDONLY') }}}; }
+ },
+ isAppend: {
+ get: function() { return (this.flags & {{{ cDefine('O_APPEND') }}}); }
+ }
+ });
+ }
+ if (stream.__proto__) {
+ // reuse the object
+ stream.__proto__ = FS.FSStream.prototype;
+ } else {
+ var newStream = new FS.FSStream();
+ for (var p in stream) {
+ newStream[p] = stream[p];
+ }
+ stream = newStream;
+ }
var fd = FS.nextfd(fd_start, fd_end);
stream.fd = fd;
- // compatibility
- Object.defineProperties(stream, {
- object: {
- get: function() { return stream.node; },
- set: function(val) { stream.node = val; }
- },
- isRead: {
- get: function() { return (stream.flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_WRONLY') }}}; }
- },
- isWrite: {
- get: function() { return (stream.flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_RDONLY') }}}; }
- },
- isAppend: {
- get: function() { return (stream.flags & {{{ cDefine('O_APPEND') }}}); }
- }
- });
FS.streams[fd] = stream;
return stream;
},
@@ -426,7 +449,7 @@ mergeInto(LibraryManager.library, {
var completed = 0;
var total = FS.mounts.length;
- var done = function(err) {
+ function done(err) {
if (err) {
return callback(err);
}
@@ -771,7 +794,6 @@ mergeInto(LibraryManager.library, {
});
},
open: function(path, flags, mode, fd_start, fd_end) {
- path = PATH.normalize(path);
flags = typeof flags === 'string' ? FS.modeStringToFlags(flags) : flags;
mode = typeof mode === 'undefined' ? 0666 : mode;
if ((flags & {{{ cDefine('O_CREAT') }}})) {
@@ -780,13 +802,18 @@ mergeInto(LibraryManager.library, {
mode = 0;
}
var node;
- try {
- var lookup = FS.lookupPath(path, {
- follow: !(flags & {{{ cDefine('O_NOFOLLOW') }}})
- });
- node = lookup.node;
- } catch (e) {
- // ignore
+ if (typeof path === 'object') {
+ node = path;
+ } else {
+ path = PATH.normalize(path);
+ try {
+ var lookup = FS.lookupPath(path, {
+ follow: !(flags & {{{ cDefine('O_NOFOLLOW') }}})
+ });
+ node = lookup.node;
+ } catch (e) {
+ // ignore
+ }
}
// perhaps we need to create the node
if ((flags & {{{ cDefine('O_CREAT') }}})) {
@@ -1079,6 +1106,11 @@ mergeInto(LibraryManager.library, {
};
FS.ErrnoError.prototype = new Error();
FS.ErrnoError.prototype.constructor = FS.ErrnoError;
+ // Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
+ [ERRNO_CODES.ENOENT].forEach(function(code) {
+ FS.genericErrors[code] = new FS.ErrnoError(code);
+ FS.genericErrors[code].stack = '<generic error, no stack>';
+ });
},
staticInit: function() {
FS.ensureErrnoError();
@@ -1173,7 +1205,7 @@ mergeInto(LibraryManager.library, {
return ret;
},
createFolder: function(parent, name, canRead, canWrite) {
- var path = PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name);
+ var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
var mode = FS.getMode(canRead, canWrite);
return FS.mkdir(path, mode);
},
@@ -1183,7 +1215,7 @@ mergeInto(LibraryManager.library, {
while (parts.length) {
var part = parts.pop();
if (!part) continue;
- var current = PATH.join(parent, part);
+ var current = PATH.join2(parent, part);
try {
FS.mkdir(current);
} catch (e) {
@@ -1194,12 +1226,12 @@ mergeInto(LibraryManager.library, {
return current;
},
createFile: function(parent, name, properties, canRead, canWrite) {
- var path = PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name);
+ var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
var mode = FS.getMode(canRead, canWrite);
return FS.create(path, mode);
},
createDataFile: function(parent, name, data, canRead, canWrite, canOwn) {
- var path = name ? PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name) : parent;
+ var path = name ? PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name) : parent;
var mode = FS.getMode(canRead, canWrite);
var node = FS.create(path, mode);
if (data) {
@@ -1209,16 +1241,16 @@ mergeInto(LibraryManager.library, {
data = arr;
}
// make sure we can write to the file
- FS.chmod(path, mode | {{{ cDefine('S_IWUGO') }}});
- var stream = FS.open(path, 'w');
+ FS.chmod(node, mode | {{{ cDefine('S_IWUGO') }}});
+ var stream = FS.open(node, 'w');
FS.write(stream, data, 0, data.length, 0, canOwn);
FS.close(stream);
- FS.chmod(path, mode);
+ FS.chmod(node, mode);
}
return node;
},
createDevice: function(parent, name, input, output) {
- var path = PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name);
+ var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
var mode = FS.getMode(!!input, !!output);
if (!FS.createDevice.major) FS.createDevice.major = 64;
var dev = FS.makedev(FS.createDevice.major++, 0);
@@ -1272,7 +1304,7 @@ mergeInto(LibraryManager.library, {
return FS.mkdev(path, mode, dev);
},
createLink: function(parent, name, target, canRead, canWrite) {
- var path = PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name);
+ var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
return FS.symlink(target, path);
},
// Makes sure a file's contents are loaded. Returns whether the file has
@@ -1304,11 +1336,11 @@ mergeInto(LibraryManager.library, {
if (typeof XMLHttpRequest !== 'undefined') {
if (!ENVIRONMENT_IS_WORKER) throw 'Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc';
// Lazy chunked Uint8Array (implements get and length from Uint8Array). Actual getting is abstracted away for eventual reuse.
- var LazyUint8Array = function() {
+ function LazyUint8Array() {
this.lengthKnown = false;
this.chunks = []; // Loaded chunks. Index is the chunk number
}
- LazyUint8Array.prototype.get = function(idx) {
+ LazyUint8Array.prototype.get = function LazyUint8Array_get(idx) {
if (idx > this.length-1 || idx < 0) {
return undefined;
}
@@ -1316,10 +1348,10 @@ mergeInto(LibraryManager.library, {
var chunkNum = Math.floor(idx / this.chunkSize);
return this.getter(chunkNum)[chunkOffset];
}
- LazyUint8Array.prototype.setDataGetter = function(getter) {
+ LazyUint8Array.prototype.setDataGetter = function LazyUint8Array_setDataGetter(getter) {
this.getter = getter;
}
- LazyUint8Array.prototype.cacheLength = function() {
+ LazyUint8Array.prototype.cacheLength = function LazyUint8Array_cacheLength() {
// Find length
var xhr = new XMLHttpRequest();
xhr.open('HEAD', url, false);
@@ -1415,7 +1447,7 @@ mergeInto(LibraryManager.library, {
var keys = Object.keys(node.stream_ops);
keys.forEach(function(key) {
var fn = node.stream_ops[key];
- stream_ops[key] = function() {
+ stream_ops[key] = function forceLoadLazyFile() {
if (!FS.forceLoadFile(node)) {
throw new FS.ErrnoError(ERRNO_CODES.EIO);
}
@@ -1423,7 +1455,7 @@ mergeInto(LibraryManager.library, {
};
});
// use a custom read function
- stream_ops.read = function(stream, buffer, offset, length, position) {
+ stream_ops.read = function stream_ops_read(stream, buffer, offset, length, position) {
if (!FS.forceLoadFile(node)) {
throw new FS.ErrnoError(ERRNO_CODES.EIO);
}
@@ -1462,7 +1494,7 @@ mergeInto(LibraryManager.library, {
Browser.init();
// TODO we should allow people to just pass in a complete filename instead
// of parent and name being that we just join them anyways
- var fullname = name ? PATH.resolve(PATH.join(parent, name)) : parent;
+ var fullname = name ? PATH.resolve(PATH.join2(parent, name)) : parent;
function processData(byteArray) {
function finish(byteArray) {
if (!dontCreateFile) {
@@ -1517,12 +1549,12 @@ mergeInto(LibraryManager.library, {
} catch (e) {
return onerror(e);
}
- openRequest.onupgradeneeded = function() {
+ openRequest.onupgradeneeded = function openRequest_onupgradeneeded() {
console.log('creating db');
var db = openRequest.result;
db.createObjectStore(FS.DB_STORE_NAME);
};
- openRequest.onsuccess = function() {
+ openRequest.onsuccess = function openRequest_onsuccess() {
var db = openRequest.result;
var transaction = db.transaction([FS.DB_STORE_NAME], 'readwrite');
var files = transaction.objectStore(FS.DB_STORE_NAME);
@@ -1532,8 +1564,8 @@ mergeInto(LibraryManager.library, {
}
paths.forEach(function(path) {
var putRequest = files.put(FS.analyzePath(path).object.contents, path);
- putRequest.onsuccess = function() { ok++; if (ok + fail == total) finish() };
- putRequest.onerror = function() { fail++; if (ok + fail == total) finish() };
+ putRequest.onsuccess = function putRequest_onsuccess() { ok++; if (ok + fail == total) finish() };
+ putRequest.onerror = function putRequest_onerror() { fail++; if (ok + fail == total) finish() };
});
transaction.onerror = onerror;
};
@@ -1551,7 +1583,7 @@ mergeInto(LibraryManager.library, {
return onerror(e);
}
openRequest.onupgradeneeded = onerror; // no database to load from
- openRequest.onsuccess = function() {
+ openRequest.onsuccess = function openRequest_onsuccess() {
var db = openRequest.result;
try {
var transaction = db.transaction([FS.DB_STORE_NAME], 'readonly');
@@ -1566,7 +1598,7 @@ mergeInto(LibraryManager.library, {
}
paths.forEach(function(path) {
var getRequest = files.get(path);
- getRequest.onsuccess = function() {
+ getRequest.onsuccess = function getRequest_onsuccess() {
if (FS.analyzePath(path).exists) {
FS.unlink(path);
}
@@ -1574,7 +1606,7 @@ mergeInto(LibraryManager.library, {
ok++;
if (ok + fail == total) finish();
};
- getRequest.onerror = function() { fail++; if (ok + fail == total) finish() };
+ getRequest.onerror = function getRequest_onerror() { fail++; if (ok + fail == total) finish() };
});
transaction.onerror = onerror;
};
diff --git a/src/library_gl.js b/src/library_gl.js
index cfdd800d..7074f844 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -242,7 +242,9 @@ var LibraryGL = {
sizePerPixel = 2;
break;
case 0x1406 /* GL_FLOAT */:
+#if ASSERTIONS
assert(GL.floatExt, 'Must have OES_texture_float to use float textures');
+#endif
switch (format) {
case 0x1907 /* GL_RGB */:
sizePerPixel = 3*4;
@@ -506,6 +508,7 @@ var LibraryGL = {
case 0x1F01 /* GL_RENDERER */:
case 0x1F02 /* GL_VERSION */:
ret = allocate(intArrayFromString(Module.ctx.getParameter(name_)), 'i8', ALLOC_NORMAL);
+ break;
case 0x1F03 /* GL_EXTENSIONS */:
var exts = Module.ctx.getSupportedExtensions();
var gl_exts = [];
@@ -514,8 +517,10 @@ var LibraryGL = {
gl_exts.push("GL_" + exts[i]);
}
ret = allocate(intArrayFromString(gl_exts.join(' ')), 'i8', ALLOC_NORMAL);
+ break;
case 0x8B8C /* GL_SHADING_LANGUAGE_VERSION */:
ret = allocate(intArrayFromString('OpenGL ES GLSL 1.00 (WebGL)'), 'i8', ALLOC_NORMAL);
+ break;
default:
throw 'Failure: Invalid glGetString value: ' + name_;
}
@@ -686,7 +691,9 @@ var LibraryGL = {
glCompressedTexImage2D__sig: 'viiiiiiii',
glCompressedTexImage2D: function(target, level, internalFormat, width, height, border, imageSize, data) {
+#if ASSERTIONS
assert(GL.compressionExt);
+#endif
if (data) {
data = {{{ makeHEAPView('U8', 'data', 'data+imageSize') }}};
} else {
@@ -697,7 +704,9 @@ var LibraryGL = {
glCompressedTexSubImage2D__sig: 'viiiiiiiii',
glCompressedTexSubImage2D: function(target, level, xoffset, yoffset, width, height, format, imageSize, data) {
+#if ASSERTIONS
assert(GL.compressionExt);
+#endif
if (data) {
data = {{{ makeHEAPView('U8', 'data', 'data+imageSize') }}};
} else {
@@ -731,7 +740,9 @@ var LibraryGL = {
glReadPixels__sig: 'viiiiiii',
glReadPixels: function(x, y, width, height, format, type, pixels) {
+#if ASSERTIONS
assert(type == 0x1401 /* GL_UNSIGNED_BYTE */);
+#endif
var sizePerPixel;
switch (format) {
case 0x1907 /* GL_RGB */:
@@ -1363,7 +1374,9 @@ var LibraryGL = {
{{{ makeSetValue('count', '0', 'len', 'i32') }}};
for (var i = 0; i < len; ++i) {
var id = GL.shaders.indexOf(result[i]);
+#if ASSERTIONS
assert(id !== -1, 'shader not bound to local id');
+#endif
{{{ makeSetValue('shaders', 'i*4', 'id', 'i32') }}};
}
},
@@ -1669,7 +1682,7 @@ var LibraryGL = {
};
var glEnable = _glEnable;
- _glEnable = function(cap) {
+ _glEnable = function _glEnable(cap) {
// Clean up the renderer on any change to the rendering state. The optimization of
// skipping renderer setup is aimed at the case of multiple glDraw* right after each other
if (GL.immediate.lastRenderer) GL.immediate.lastRenderer.cleanup();
@@ -1691,7 +1704,7 @@ var LibraryGL = {
};
var glDisable = _glDisable;
- _glDisable = function(cap) {
+ _glDisable = function _glDisable(cap) {
if (GL.immediate.lastRenderer) GL.immediate.lastRenderer.cleanup();
if (cap == 0x0B60 /* GL_FOG */) {
GLEmulation.fogEnabled = false;
@@ -1709,7 +1722,7 @@ var LibraryGL = {
}
glDisable(cap);
};
- _glIsEnabled = function(cap) {
+ _glIsEnabled = function _glIsEnabled(cap) {
if (cap == 0x0B60 /* GL_FOG */) {
return GLEmulation.fogEnabled ? 1 : 0;
} else if (!(cap in validCapabilities)) {
@@ -1719,7 +1732,7 @@ var LibraryGL = {
};
var glGetBooleanv = _glGetBooleanv;
- _glGetBooleanv = function(pname, p) {
+ _glGetBooleanv = function _glGetBooleanv(pname, p) {
var attrib = GLEmulation.getAttributeFromCapability(pname);
if (attrib !== null) {
var result = GL.immediate.enabledClientAttributes[attrib];
@@ -1730,7 +1743,7 @@ var LibraryGL = {
};
var glGetIntegerv = _glGetIntegerv;
- _glGetIntegerv = function(pname, params) {
+ _glGetIntegerv = function _glGetIntegerv(pname, params) {
switch (pname) {
case 0x84E2: pname = Module.ctx.MAX_TEXTURE_IMAGE_UNITS /* fake it */; break; // GL_MAX_TEXTURE_UNITS
case 0x8B4A: { // GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB
@@ -1780,17 +1793,17 @@ var LibraryGL = {
return;
}
case 0x8088: { // GL_TEXTURE_COORD_ARRAY_SIZE
- var attribute = GLImmediate.clientAttributes[GLImmediate.TEXTURE0];
+ var attribute = GLImmediate.clientAttributes[GLImmediate.TEXTURE0 + GLImmediate.clientActiveTexture];
{{{ makeSetValue('params', '0', 'attribute ? attribute.size : 0', 'i32') }}};
return;
}
case 0x8089: { // GL_TEXTURE_COORD_ARRAY_TYPE
- var attribute = GLImmediate.clientAttributes[GLImmediate.TEXTURE0];
+ var attribute = GLImmediate.clientAttributes[GLImmediate.TEXTURE0 + GLImmediate.clientActiveTexture];
{{{ makeSetValue('params', '0', 'attribute ? attribute.type : 0', 'i32') }}};
return;
}
case 0x808A: { // GL_TEXTURE_COORD_ARRAY_STRIDE
- var attribute = GLImmediate.clientAttributes[GLImmediate.TEXTURE0];
+ var attribute = GLImmediate.clientAttributes[GLImmediate.TEXTURE0 + GLImmediate.clientActiveTexture];
{{{ makeSetValue('params', '0', 'attribute ? attribute.stride : 0', 'i32') }}};
return;
}
@@ -1799,14 +1812,17 @@ var LibraryGL = {
};
var glGetString = _glGetString;
- _glGetString = function(name_) {
+ _glGetString = function _glGetString(name_) {
+ if (GL.stringCache[name_]) return GL.stringCache[name_];
switch(name_) {
case 0x1F03 /* GL_EXTENSIONS */: // Add various extensions that we can support
- return allocate(intArrayFromString(Module.ctx.getSupportedExtensions().join(' ') +
+ var ret = allocate(intArrayFromString(Module.ctx.getSupportedExtensions().join(' ') +
' GL_EXT_texture_env_combine GL_ARB_texture_env_crossbar GL_ATI_texture_env_combine3 GL_NV_texture_env_combine4 GL_EXT_texture_env_dot3 GL_ARB_multitexture GL_ARB_vertex_buffer_object GL_EXT_framebuffer_object GL_ARB_vertex_program GL_ARB_fragment_program GL_ARB_shading_language_100 GL_ARB_shader_objects GL_ARB_vertex_shader GL_ARB_fragment_shader GL_ARB_texture_cube_map GL_EXT_draw_range_elements' +
(GL.compressionExt ? ' GL_ARB_texture_compression GL_EXT_texture_compression_s3tc' : '') +
(GL.anisotropicExt ? ' GL_EXT_texture_filter_anisotropic' : '')
), 'i8', ALLOC_NORMAL);
+ GL.stringCache[name_] = ret;
+ return ret;
}
return glGetString(name_);
};
@@ -1820,7 +1836,7 @@ var LibraryGL = {
GL.shaderOriginalSources = {};
#endif
var glCreateShader = _glCreateShader;
- _glCreateShader = function(shaderType) {
+ _glCreateShader = function _glCreateShader(shaderType) {
var id = glCreateShader(shaderType);
GL.shaderInfos[id] = {
type: shaderType,
@@ -1830,7 +1846,7 @@ var LibraryGL = {
};
var glShaderSource = _glShaderSource;
- _glShaderSource = function(shader, count, string, length) {
+ _glShaderSource = function _glShaderSource(shader, count, string, length) {
var source = GL.getSource(shader, count, string, length);
#if GL_DEBUG
console.log("glShaderSource: Input: \n" + source);
@@ -1943,7 +1959,7 @@ var LibraryGL = {
};
var glCompileShader = _glCompileShader;
- _glCompileShader = function(shader) {
+ _glCompileShader = function _glCompileShader(shader) {
Module.ctx.compileShader(GL.shaders[shader]);
#if GL_DEBUG
if (!Module.ctx.getShaderParameter(GL.shaders[shader], Module.ctx.COMPILE_STATUS)) {
@@ -1958,14 +1974,14 @@ var LibraryGL = {
GL.programShaders = {};
var glAttachShader = _glAttachShader;
- _glAttachShader = function(program, shader) {
+ _glAttachShader = function _glAttachShader(program, shader) {
if (!GL.programShaders[program]) GL.programShaders[program] = [];
GL.programShaders[program].push(shader);
glAttachShader(program, shader);
};
var glDetachShader = _glDetachShader;
- _glDetachShader = function(program, shader) {
+ _glDetachShader = function _glDetachShader(program, shader) {
var programShader = GL.programShaders[program];
if (!programShader) {
Module.printErr('WARNING: _glDetachShader received invalid program: ' + program);
@@ -1977,7 +1993,7 @@ var LibraryGL = {
};
var glUseProgram = _glUseProgram;
- _glUseProgram = function(program) {
+ _glUseProgram = function _glUseProgram(program) {
#if GL_DEBUG
if (GL.debug) {
Module.printErr('[using program with shaders]');
@@ -1994,7 +2010,7 @@ var LibraryGL = {
}
var glDeleteProgram = _glDeleteProgram;
- _glDeleteProgram = function(program) {
+ _glDeleteProgram = function _glDeleteProgram(program) {
glDeleteProgram(program);
if (program == GL.currProgram) GL.currProgram = 0;
};
@@ -2002,12 +2018,12 @@ var LibraryGL = {
// If attribute 0 was not bound, bind it to 0 for WebGL performance reasons. Track if 0 is free for that.
var zeroUsedPrograms = {};
var glBindAttribLocation = _glBindAttribLocation;
- _glBindAttribLocation = function(program, index, name) {
+ _glBindAttribLocation = function _glBindAttribLocation(program, index, name) {
if (index == 0) zeroUsedPrograms[program] = true;
glBindAttribLocation(program, index, name);
};
var glLinkProgram = _glLinkProgram;
- _glLinkProgram = function(program) {
+ _glLinkProgram = function _glLinkProgram(program) {
if (!(program in zeroUsedPrograms)) {
Module.ctx.bindAttribLocation(GL.programs[program], 0, 'a_position');
}
@@ -2015,11 +2031,13 @@ var LibraryGL = {
};
var glBindBuffer = _glBindBuffer;
- _glBindBuffer = function(target, buffer) {
+ _glBindBuffer = function _glBindBuffer(target, buffer) {
glBindBuffer(target, buffer);
if (target == Module.ctx.ARRAY_BUFFER) {
if (GLEmulation.currentVao) {
+#if ASSERTIONS
assert(GLEmulation.currentVao.arrayBuffer == buffer || GLEmulation.currentVao.arrayBuffer == 0 || buffer == 0, 'TODO: support for multiple array buffers in vao');
+#endif
GLEmulation.currentVao.arrayBuffer = buffer;
}
} else if (target == Module.ctx.ELEMENT_ARRAY_BUFFER) {
@@ -2028,7 +2046,7 @@ var LibraryGL = {
};
var glGetFloatv = _glGetFloatv;
- _glGetFloatv = function(pname, params) {
+ _glGetFloatv = function _glGetFloatv(pname, params) {
if (pname == 0x0BA6) { // GL_MODELVIEW_MATRIX
HEAPF32.set(GL.immediate.matrix['m'], params >> 2);
} else if (pname == 0x0BA7) { // GL_PROJECTION_MATRIX
@@ -2051,7 +2069,7 @@ var LibraryGL = {
};
var glHint = _glHint;
- _glHint = function(target, mode) {
+ _glHint = function _glHint(target, mode) {
if (target == 0x84EF) { // GL_TEXTURE_COMPRESSION_HINT
return;
}
@@ -2059,21 +2077,21 @@ var LibraryGL = {
};
var glEnableVertexAttribArray = _glEnableVertexAttribArray;
- _glEnableVertexAttribArray = function(index) {
+ _glEnableVertexAttribArray = function _glEnableVertexAttribArray(index) {
glEnableVertexAttribArray(index);
GLEmulation.enabledVertexAttribArrays[index] = 1;
if (GLEmulation.currentVao) GLEmulation.currentVao.enabledVertexAttribArrays[index] = 1;
};
var glDisableVertexAttribArray = _glDisableVertexAttribArray;
- _glDisableVertexAttribArray = function(index) {
+ _glDisableVertexAttribArray = function _glDisableVertexAttribArray(index) {
glDisableVertexAttribArray(index);
delete GLEmulation.enabledVertexAttribArrays[index];
if (GLEmulation.currentVao) delete GLEmulation.currentVao.enabledVertexAttribArrays[index];
};
var glVertexAttribPointer = _glVertexAttribPointer;
- _glVertexAttribPointer = function(index, size, type, normalized, stride, pointer) {
+ _glVertexAttribPointer = function _glVertexAttribPointer(index, size, type, normalized, stride, pointer) {
glVertexAttribPointer(index, size, type, normalized, stride, pointer);
if (GLEmulation.currentVao) { // TODO: avoid object creation here? likely not hot though
GLEmulation.currentVao.vertexAttribPointers[index] = [index, size, type, normalized, stride, pointer];
@@ -2159,7 +2177,9 @@ var LibraryGL = {
glBindProgram__sig: 'vii',
glBindProgram: function(type, id) {
+#if ASSERTIONS
assert(id == 0);
+#endif
},
glGetPointerv: function(name, p) {
@@ -2170,7 +2190,7 @@ var LibraryGL = {
case 0x8090: // GL_COLOR_ARRAY_POINTER
attribute = GLImmediate.clientAttributes[GLImmediate.COLOR]; break;
case 0x8092: // GL_TEXTURE_COORD_ARRAY_POINTER
- attribute = GLImmediate.clientAttributes[GLImmediate.TEXTURE0]; break;
+ attribute = GLImmediate.clientAttributes[GLImmediate.TEXTURE0 + GLImmediate.clientActiveTexture]; break;
default: throw 'TODO: glGetPointerv for ' + name;
}
{{{ makeSetValue('p', '0', 'attribute ? attribute.pointer : 0', 'i32') }}};
@@ -2192,14 +2212,14 @@ var LibraryGL = {
function CNaiveListMap() {
var list = [];
- this.insert = function(key, val) {
+ this.insert = function CNaiveListMap_insert(key, val) {
if (this.contains(key|0)) return false;
list.push([key, val]);
return true;
};
var __contains_i;
- this.contains = function(key) {
+ this.contains = function CNaiveListMap_contains(key) {
for (__contains_i = 0; __contains_i < list.length; ++__contains_i) {
if (list[__contains_i][0] === key) return true;
}
@@ -2207,7 +2227,7 @@ var LibraryGL = {
};
var __get_i;
- this.get = function(key) {
+ this.get = function CNaiveListMap_get(key) {
for (__get_i = 0; __get_i < list.length; ++__get_i) {
if (list[__get_i][0] === key) return list[__get_i][1];
}
@@ -2241,7 +2261,7 @@ var LibraryGL = {
function CNLNode() {
var map = new CNaiveListMap();
- this.child = function(keyFrag) {
+ this.child = function CNLNode_child(keyFrag) {
if (!map.contains(keyFrag|0)) {
map.insert(keyFrag|0, new CNLNode());
}
@@ -2249,11 +2269,11 @@ var LibraryGL = {
};
this.value = undefined;
- this.get = function() {
+ this.get = function CNLNode_get() {
return this.value;
};
- this.set = function(val) {
+ this.set = function CNLNode_set(val) {
this.value = val;
};
}
@@ -2261,22 +2281,22 @@ var LibraryGL = {
function CKeyView(root) {
var cur;
- this.reset = function() {
+ this.reset = function CKeyView_reset() {
cur = root;
return this;
};
this.reset();
- this.next = function(keyFrag) {
+ this.next = function CKeyView_next(keyFrag) {
cur = cur.child(keyFrag);
return this;
};
- this.get = function() {
+ this.get = function CKeyView_get() {
return cur.get();
};
- this.set = function(val) {
+ this.set = function CKeyView_set(val) {
cur.set(val);
};
};
@@ -2284,17 +2304,17 @@ var LibraryGL = {
var root;
var staticKeyView;
- this.createKeyView = function() {
+ this.createKeyView = function CNLNode_createKeyView() {
return new CKeyView(root);
}
- this.clear = function() {
+ this.clear = function CNLNode_clear() {
root = new CNLNode();
staticKeyView = this.createKeyView();
};
this.clear();
- this.getStaticKeyView = function() {
+ this.getStaticKeyView = function CNLNode_getStaticKeyView() {
staticKeyView.reset();
return staticKeyView;
};
@@ -2528,7 +2548,7 @@ var LibraryGL = {
GL_SRC_ALPHA
];
- this.traverseState = function(keyView) {
+ this.traverseState = function CTexEnv_traverseState(keyView) {
keyView.next(this.mode);
keyView.next(this.colorCombiner);
keyView.next(this.alphaCombiner);
@@ -2564,7 +2584,7 @@ var LibraryGL = {
this.enabled_tex3D = false;
this.enabled_texCube = false;
- this.traverseState = function(keyView) {
+ this.traverseState = function CTexUnit_traverseState(keyView) {
var texUnitType = this.getTexType();
keyView.next(texUnitType);
if (!texUnitType) return;
@@ -2573,11 +2593,11 @@ var LibraryGL = {
};
// Class impls:
- CTexUnit.prototype.enabled = function() {
+ CTexUnit.prototype.enabled = function CTexUnit_enabled() {
return this.getTexType() != 0;
}
- CTexUnit.prototype.genPassLines = function(passOutputVar, passInputVar, texUnitID) {
+ CTexUnit.prototype.genPassLines = function CTexUnit_genPassLines(passOutputVar, passInputVar, texUnitID) {
if (!this.enabled()) {
return ["vec4 " + passOutputVar + " = " + passInputVar + ";"];
}
@@ -2585,7 +2605,7 @@ var LibraryGL = {
return this.env.genPassLines(passOutputVar, passInputVar, texUnitID);
}
- CTexUnit.prototype.getTexType = function() {
+ CTexUnit.prototype.getTexType = function CTexUnit_getTexType() {
if (this.enabled_texCube) {
return GL_TEXTURE_CUBE_MAP;
} else if (this.enabled_tex3D) {
@@ -2598,7 +2618,7 @@ var LibraryGL = {
return 0;
}
- CTexEnv.prototype.genPassLines = function(passOutputVar, passInputVar, texUnitID) {
+ CTexEnv.prototype.genPassLines = function CTexEnv_genPassLines(passOutputVar, passInputVar, texUnitID) {
switch (this.mode) {
case GL_REPLACE: {
/* RGB:
@@ -2720,9 +2740,9 @@ var LibraryGL = {
return Abort_NoSupport("Unsupported TexEnv mode: 0x" + this.mode.toString(16));
}
- CTexEnv.prototype.genCombinerLines = function(isColor, outputVar,
- passInputVar, texUnitID,
- combiner, srcArr, opArr)
+ CTexEnv.prototype.genCombinerLines = function CTexEnv_getCombinerLines(isColor, outputVar,
+ passInputVar, texUnitID,
+ combiner, srcArr, opArr)
{
var argsNeeded = null;
switch (combiner) {
@@ -2838,9 +2858,9 @@ var LibraryGL = {
} else if (gl) {
maxTexUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
}
-
+#if ASSERTIONS
assert(maxTexUnits > 0);
-
+#endif
s_texUnits = [];
for (var i = 0; i < maxTexUnits; i++) {
s_texUnits.push(new CTexUnit());
@@ -2899,9 +2919,10 @@ var LibraryGL = {
},
getTexUnitType: function(texUnitID) {
+#if ASSERTIONS
assert(texUnitID >= 0 &&
texUnitID < s_texUnits.length);
-
+#endif
return s_texUnits[texUnitID].getTexType();
},
@@ -3204,9 +3225,13 @@ var LibraryGL = {
if (!GL.immediate.enabledClientAttributes[texAttribName])
continue;
+#if ASSERTIONS
if (!useCurrProgram) {
- assert(GL.immediate.TexEnvJIT.getTexUnitType(i) != 0, "GL_TEXTURE" + i + " coords are supplied, but that texture unit is disabled in the fixed-function pipeline.");
+ if (GL.immediate.TexEnvJIT.getTexUnitType(i) == 0) {
+ Runtime.warnOnce("GL_TEXTURE" + i + " coords are supplied, but that texture unit is disabled in the fixed-function pipeline.");
+ }
}
+#endif
textureSizes[i] = GL.immediate.clientAttributes[texAttribName].size;
textureTypes[i] = GL.immediate.clientAttributes[texAttribName].type;
@@ -3423,7 +3448,9 @@ var LibraryGL = {
if (!GL.currArrayBuffer) {
var start = GL.immediate.firstVertex*GL.immediate.stride;
var end = GL.immediate.lastVertex*GL.immediate.stride;
+#if ASSERTIONS
assert(end <= GL.MAX_TEMP_BUFFER_SIZE, 'too much vertex data');
+#endif
arrayBuffer = GL.tempVertexBuffers[GL.tempBufferIndexLookup[end]];
// TODO: consider using the last buffer we bound, if it was larger. downside is larger buffer, but we might avoid rebinding and preparing
} else {
@@ -3571,7 +3598,7 @@ var LibraryGL = {
// Replace some functions with immediate-mode aware versions. If there are no client
// attributes enabled, and we use webgl-friendly modes (no GL_QUADS), then no need
// for emulation
- _glDrawArrays = function(mode, first, count) {
+ _glDrawArrays = function _glDrawArrays(mode, first, count) {
if (GL.immediate.totalEnabledClientAttributes == 0 && mode <= 6) {
Module.ctx.drawArrays(mode, first, count);
return;
@@ -3587,15 +3614,15 @@ var LibraryGL = {
GL.immediate.mode = -1;
};
- _glDrawElements = function(mode, count, type, indices, start, end) { // start, end are given if we come from glDrawRangeElements
+ _glDrawElements = function _glDrawElements(mode, count, type, indices, start, end) { // start, end are given if we come from glDrawRangeElements
if (GL.immediate.totalEnabledClientAttributes == 0 && mode <= 6 && GL.currElementArrayBuffer) {
Module.ctx.drawElements(mode, count, type, indices);
return;
}
+#if ASSERTIONS
if (!GL.currElementArrayBuffer) {
assert(type == Module.ctx.UNSIGNED_SHORT); // We can only emulate buffers of this kind, for now
}
-#if ASSERTIONS
console.log("DrawElements doesn't actually prepareClientAttributes properly.");
#endif
GL.immediate.prepareClientAttributes(count, false);
@@ -3627,43 +3654,43 @@ var LibraryGL = {
}
var glActiveTexture = _glActiveTexture;
- _glActiveTexture = function(texture) {
+ _glActiveTexture = function _glActiveTexture(texture) {
GL.immediate.TexEnvJIT.hook_activeTexture(texture);
glActiveTexture(texture);
};
var glEnable = _glEnable;
- _glEnable = function(cap) {
+ _glEnable = function _glEnable(cap) {
GL.immediate.TexEnvJIT.hook_enable(cap);
glEnable(cap);
};
var glDisable = _glDisable;
- _glDisable = function(cap) {
+ _glDisable = function _glDisable(cap) {
GL.immediate.TexEnvJIT.hook_disable(cap);
glDisable(cap);
};
var glTexEnvf = (typeof(_glTexEnvf) != 'undefined') ? _glTexEnvf : function(){};
- _glTexEnvf = function(target, pname, param) {
+ _glTexEnvf = function _glTexEnvf(target, pname, param) {
GL.immediate.TexEnvJIT.hook_texEnvf(target, pname, param);
// Don't call old func, since we are the implementor.
//glTexEnvf(target, pname, param);
};
var glTexEnvi = (typeof(_glTexEnvi) != 'undefined') ? _glTexEnvi : function(){};
- _glTexEnvi = function(target, pname, param) {
+ _glTexEnvi = function _glTexEnvi(target, pname, param) {
GL.immediate.TexEnvJIT.hook_texEnvi(target, pname, param);
// Don't call old func, since we are the implementor.
//glTexEnvi(target, pname, param);
};
var glTexEnvfv = (typeof(_glTexEnvfv) != 'undefined') ? _glTexEnvfv : function(){};
- _glTexEnvfv = function(target, pname, param) {
+ _glTexEnvfv = function _glTexEnvfv(target, pname, param) {
GL.immediate.TexEnvJIT.hook_texEnvfv(target, pname, param);
// Don't call old func, since we are the implementor.
//glTexEnvfv(target, pname, param);
};
var glGetIntegerv = _glGetIntegerv;
- _glGetIntegerv = function(pname, params) {
+ _glGetIntegerv = function _glGetIntegerv(pname, params) {
switch (pname) {
case 0x8B8D: { // GL_CURRENT_PROGRAM
// Just query directly so we're working with WebGL objects.
@@ -3803,13 +3830,17 @@ var LibraryGL = {
if (!attribute) break;
attribute.offset = attribute.pointer - start;
if (attribute.offset > bytes) { // ensure we start where we should
+#if ASSERTIONS
assert((attribute.offset - bytes)%4 == 0); // XXX assuming 4-alignment
+#endif
bytes += attribute.offset - bytes;
}
bytes += attribute.size * GL.byteSizeByType[attribute.type - GL.byteSizeByTypeRoot];
if (bytes % 4 != 0) bytes += 4 - (bytes % 4); // XXX assuming 4-alignment
}
+#if ASSERTIONS
assert(beginEnd || bytes <= stride); // if not begin-end, explicit stride should make sense with total byte size
+#endif
if (bytes < stride) { // ensure the size is that of the stride
bytes = stride;
}
@@ -3836,18 +3867,21 @@ var LibraryGL = {
// Generate index data in a format suitable for GLES 2.0/WebGL
var numVertexes = 4 * this.vertexCounter / GL.immediate.stride;
+#if ASSERTIONS
assert(numVertexes % 1 == 0, "`numVertexes` must be an integer.");
-
+#endif
var emulatedElementArrayBuffer = false;
var numIndexes = 0;
if (numProvidedIndexes) {
numIndexes = numProvidedIndexes;
if (!GL.currArrayBuffer && GL.immediate.firstVertex > GL.immediate.lastVertex) {
// Figure out the first and last vertex from the index data
+#if ASSERTIONS
assert(!GL.currElementArrayBuffer); // If we are going to upload array buffer data, we need to find which range to
// upload based on the indices. If they are in a buffer on the GPU, that is very
// inconvenient! So if you do not have an array buffer, you should also not have
// an element array buffer. But best is to use both buffers!
+#endif
for (var i = 0; i < numProvidedIndexes; i++) {
var currIndex = {{{ makeGetValue('ptr', 'i*2', 'i16', null, 1) }}};
GL.immediate.firstVertex = Math.min(GL.immediate.firstVertex, currIndex);
@@ -3856,7 +3890,9 @@ var LibraryGL = {
}
if (!GL.currElementArrayBuffer) {
// If no element array buffer is bound, then indices is a literal pointer to clientside data
+#if ASSERTIONS
assert(numProvidedIndexes << 1 <= GL.MAX_TEMP_BUFFER_SIZE, 'too many immediate mode indexes (a)');
+#endif
var indexBuffer = GL.tempIndexBuffers[GL.tempBufferIndexLookup[numProvidedIndexes << 1]];
Module.ctx.bindBuffer(Module.ctx.ELEMENT_ARRAY_BUFFER, indexBuffer);
Module.ctx.bufferSubData(Module.ctx.ELEMENT_ARRAY_BUFFER, 0, {{{ makeHEAPView('U16', 'ptr', 'ptr + (numProvidedIndexes << 1)') }}});
@@ -3868,11 +3904,15 @@ var LibraryGL = {
// GL.immediate.firstVertex is the first vertex we want. Quad indexes are in the pattern
// 0 1 2, 0 2 3, 4 5 6, 4 6 7, so we need to look at index firstVertex * 1.5 to see it.
// Then since indexes are 2 bytes each, that means 3
+#if ASSERTIONS
assert(GL.immediate.firstVertex % 4 == 0);
+#endif
ptr = GL.immediate.firstVertex*3;
var numQuads = numVertexes / 4;
numIndexes = numQuads * 6; // 0 1 2, 0 2 3 pattern
+#if ASSERTIONS
assert(ptr + (numIndexes << 1) <= GL.MAX_TEMP_BUFFER_SIZE, 'too many immediate mode indexes (b)');
+#endif
Module.ctx.bindBuffer(Module.ctx.ELEMENT_ARRAY_BUFFER, GL.tempQuadIndexBuffer);
emulatedElementArrayBuffer = true;
}
@@ -4693,7 +4733,7 @@ LibraryGL.emscripten_GetProcAddress__deps = [function() {
tableImpl += '}\nreturn 0;';
LibraryManager.library.emscripten_procAddressTable = new Function('name', tableImpl);
}, 'emscripten_procAddressTable'];
-LibraryGL.emscripten_GetProcAddress = function(name) {
+LibraryGL.emscripten_GetProcAddress = function _LibraryGL_emscripten_GetProcAddress(name) {
name = name.replace('EXT', '').replace('ARB', '');
switch(name) { // misc renamings
case 'glCreateProgramObject': name = 'glCreateProgram'; break;
diff --git a/src/library_glfw.js b/src/library_glfw.js
index b0519e39..647d4bb6 100644
--- a/src/library_glfw.js
+++ b/src/library_glfw.js
@@ -355,7 +355,9 @@ var LibraryGLFW = {
}
var contextAttributes = {
- antialias: (GLFW.params[0x00020013] > 1) //GLFW_FSAA_SAMPLES
+ antialias: (GLFW.params[0x00020013] > 1), //GLFW_FSAA_SAMPLES
+ depth: (GLFW.params[0x00020009] > 0), //GLFW_DEPTH_BITS
+ stencil: (GLFW.params[0x0002000A] > 0) //GLFW_STENCIL_BITS
}
Module.ctx = Browser.createContext(Module['canvas'], true, true, contextAttributes);
return 1; //GL_TRUE
diff --git a/src/library_glut.js b/src/library_glut.js
index 722ea85c..5e303fd2 100644
--- a/src/library_glut.js
+++ b/src/library_glut.js
@@ -372,7 +372,7 @@ var LibraryGLUT = {
},
glutIdleFunc: function(func) {
- var callback = function() {
+ function callback() {
if (GLUT.idleFunc) {
Runtime.dynCall('v', GLUT.idleFunc);
Browser.safeSetTimeout(callback, 0);
@@ -427,7 +427,9 @@ var LibraryGLUT = {
glutCreateWindow__deps: ['$Browser'],
glutCreateWindow: function(name) {
var contextAttributes = {
- antialias: ((GLUT.initDisplayMode & 0x0080 /*GLUT_MULTISAMPLE*/) != 0)
+ antialias: ((GLUT.initDisplayMode & 0x0080 /*GLUT_MULTISAMPLE*/) != 0),
+ depth: ((GLUT.initDisplayMode & 0x0010 /*GLUT_DEPTH*/) != 0),
+ stencil: ((GLUT.initDisplayMode & 0x0020 /*GLUT_STENCIL*/) != 0)
};
Module.ctx = Browser.createContext(Module['canvas'], true, true, contextAttributes);
return Module.ctx ? 1 /* a new GLUT window ID for the created context */ : 0 /* failure */;
diff --git a/src/library_idbfs.js b/src/library_idbfs.js
index 9031bad8..7f50f17e 100644
--- a/src/library_idbfs.js
+++ b/src/library_idbfs.js
@@ -58,7 +58,7 @@ mergeInto(LibraryManager.library, {
}
var completed = 0;
- var done = function(err) {
+ function done(err) {
if (err) return callback(err);
if (++completed >= total) {
return callback(null);
@@ -68,7 +68,7 @@ mergeInto(LibraryManager.library, {
// create a single transaction to handle and IDB reads / writes we'll need to do
var db = src.type === 'remote' ? src.db : dst.db;
var transaction = db.transaction([IDBFS.DB_STORE_NAME], 'readwrite');
- transaction.onerror = function() { callback(this.error); };
+ transaction.onerror = function transaction_onerror() { callback(this.error); };
var store = transaction.objectStore(IDBFS.DB_STORE_NAME);
for (var path in create) {
@@ -92,8 +92,8 @@ mergeInto(LibraryManager.library, {
} else {
// save file to IDB
var req = store.put(entry, path);
- req.onsuccess = function() { done(null); };
- req.onerror = function() { done(this.error); };
+ req.onsuccess = function req_onsuccess() { done(null); };
+ req.onerror = function req_onerror() { done(this.error); };
}
}
@@ -117,20 +117,20 @@ mergeInto(LibraryManager.library, {
} else {
// delete file from IDB
var req = store.delete(path);
- req.onsuccess = function() { done(null); };
- req.onerror = function() { done(this.error); };
+ req.onsuccess = function req_onsuccess() { done(null); };
+ req.onerror = function req_onerror() { done(this.error); };
}
}
},
getLocalSet: function(mount, callback) {
var files = {};
- var isRealDir = function(p) {
+ function isRealDir(p) {
return p !== '.' && p !== '..';
};
- var toAbsolute = function(root) {
+ function toAbsolute(root) {
return function(p) {
- return PATH.join(root, p);
+ return PATH.join2(root, p);
}
};
@@ -177,17 +177,17 @@ mergeInto(LibraryManager.library, {
} catch (e) {
return onerror(e);
}
- req.onupgradeneeded = function() {
+ req.onupgradeneeded = function req_onupgradeneeded() {
db = req.result;
db.createObjectStore(IDBFS.DB_STORE_NAME);
};
- req.onsuccess = function() {
+ req.onsuccess = function req_onsuccess() {
db = req.result;
// add to the cache
IDBFS.dbs[name] = db;
callback(null, db);
};
- req.onerror = function() {
+ req.onerror = function req_onerror() {
callback(this.error);
};
},
@@ -198,10 +198,10 @@ mergeInto(LibraryManager.library, {
if (err) return callback(err);
var transaction = db.transaction([IDBFS.DB_STORE_NAME], 'readonly');
- transaction.onerror = function() { callback(this.error); };
+ transaction.onerror = function transaction_onerror() { callback(this.error); };
var store = transaction.objectStore(IDBFS.DB_STORE_NAME);
- store.openCursor().onsuccess = function(event) {
+ store.openCursor().onsuccess = function store_openCursor_onsuccess(event) {
var cursor = event.target.result;
if (!cursor) {
return callback(null, { type: 'remote', db: db, files: files });
diff --git a/src/library_memfs.js b/src/library_memfs.js
index 94fd767e..d3148d8b 100644
--- a/src/library_memfs.js
+++ b/src/library_memfs.js
@@ -1,6 +1,8 @@
mergeInto(LibraryManager.library, {
$MEMFS__deps: ['$FS'],
$MEMFS: {
+ ops_table: null,
+
// content modes
CONTENT_OWNING: 1, // contains a subarray into the heap, and we own it, without copying (note: someone else needs to free() it, if that is necessary)
CONTENT_FLEXIBLE: 2, // has been modified or never set to anything, and is a flexible js array that can grow/shrink
@@ -13,51 +15,71 @@ mergeInto(LibraryManager.library, {
// no supported
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
}
+ if (!MEMFS.ops_table) {
+ MEMFS.ops_table = {
+ dir: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr,
+ lookup: MEMFS.node_ops.lookup,
+ mknod: MEMFS.node_ops.mknod,
+ mknod: MEMFS.node_ops.mknod,
+ rename: MEMFS.node_ops.rename,
+ unlink: MEMFS.node_ops.unlink,
+ rmdir: MEMFS.node_ops.rmdir,
+ readdir: MEMFS.node_ops.readdir,
+ symlink: MEMFS.node_ops.symlink
+ },
+ stream: {
+ llseek: MEMFS.stream_ops.llseek
+ }
+ },
+ file: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr
+ },
+ stream: {
+ llseek: MEMFS.stream_ops.llseek,
+ read: MEMFS.stream_ops.read,
+ write: MEMFS.stream_ops.write,
+ allocate: MEMFS.stream_ops.allocate,
+ mmap: MEMFS.stream_ops.mmap
+ }
+ },
+ link: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr,
+ readlink: MEMFS.node_ops.readlink
+ },
+ stream: {}
+ },
+ chrdev: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr
+ },
+ stream: FS.chrdev_stream_ops
+ },
+ };
+ }
var node = FS.createNode(parent, name, mode, dev);
if (FS.isDir(node.mode)) {
- node.node_ops = {
- getattr: MEMFS.node_ops.getattr,
- setattr: MEMFS.node_ops.setattr,
- lookup: MEMFS.node_ops.lookup,
- mknod: MEMFS.node_ops.mknod,
- mknod: MEMFS.node_ops.mknod,
- rename: MEMFS.node_ops.rename,
- unlink: MEMFS.node_ops.unlink,
- rmdir: MEMFS.node_ops.rmdir,
- readdir: MEMFS.node_ops.readdir,
- symlink: MEMFS.node_ops.symlink
- };
- node.stream_ops = {
- llseek: MEMFS.stream_ops.llseek
- };
+ node.node_ops = MEMFS.ops_table.dir.node;
+ node.stream_ops = MEMFS.ops_table.dir.stream;
node.contents = {};
} else if (FS.isFile(node.mode)) {
- node.node_ops = {
- getattr: MEMFS.node_ops.getattr,
- setattr: MEMFS.node_ops.setattr
- };
- node.stream_ops = {
- llseek: MEMFS.stream_ops.llseek,
- read: MEMFS.stream_ops.read,
- write: MEMFS.stream_ops.write,
- allocate: MEMFS.stream_ops.allocate,
- mmap: MEMFS.stream_ops.mmap
- };
+ node.node_ops = MEMFS.ops_table.file.node;
+ node.stream_ops = MEMFS.ops_table.file.stream;
node.contents = [];
node.contentMode = MEMFS.CONTENT_FLEXIBLE;
} else if (FS.isLink(node.mode)) {
- node.node_ops = {
- getattr: MEMFS.node_ops.getattr,
- setattr: MEMFS.node_ops.setattr,
- readlink: MEMFS.node_ops.readlink
- };
- node.stream_ops = {};
+ node.node_ops = MEMFS.ops_table.link.node;
+ node.stream_ops = MEMFS.ops_table.link.stream;
} else if (FS.isChrdev(node.mode)) {
- node.node_ops = {
- getattr: MEMFS.node_ops.getattr,
- setattr: MEMFS.node_ops.setattr
- };
- node.stream_ops = FS.chrdev_stream_ops;
+ node.node_ops = MEMFS.ops_table.chrdev.node;
+ node.stream_ops = MEMFS.ops_table.chrdev.stream;
}
node.timestamp = Date.now();
// add the new node to the parent
@@ -117,7 +139,7 @@ mergeInto(LibraryManager.library, {
}
},
lookup: function(parent, name) {
- throw new FS.ErrnoError(ERRNO_CODES.ENOENT);
+ throw FS.genericErrors[ERRNO_CODES.ENOENT];
},
mknod: function(parent, name, mode, dev) {
return MEMFS.createNode(parent, name, mode, dev);
@@ -200,10 +222,12 @@ mergeInto(LibraryManager.library, {
#if USE_TYPED_ARRAYS == 2
if (length && contents.length === 0 && position === 0 && buffer.subarray) {
// just replace it with the new data
+#if ASSERTIONS
assert(buffer.length);
- if (canOwn && buffer.buffer === HEAP8.buffer && offset === 0) {
- node.contents = buffer; // this is a subarray of the heap, and we can own it
- node.contentMode = MEMFS.CONTENT_OWNING;
+#endif
+ if (canOwn && offset === 0) {
+ node.contents = buffer; // this could be a subarray of Emscripten HEAP, or allocated from some other source.
+ node.contentMode = (buffer.buffer === HEAP8.buffer) ? MEMFS.CONTENT_OWNING : MEMFS.CONTENT_FIXED;
} else {
node.contents = new Uint8Array(buffer.subarray(offset, offset+length));
node.contentMode = MEMFS.CONTENT_FIXED;
diff --git a/src/library_nodefs.js b/src/library_nodefs.js
index 2be54076..7686f3f2 100644
--- a/src/library_nodefs.js
+++ b/src/library_nodefs.js
@@ -134,7 +134,7 @@ mergeInto(LibraryManager.library, {
}
},
lookup: function (parent, name) {
- var path = PATH.join(NODEFS.realPath(parent), name);
+ var path = PATH.join2(NODEFS.realPath(parent), name);
var mode = NODEFS.getMode(path);
return NODEFS.createNode(parent, name, mode);
},
@@ -156,7 +156,7 @@ mergeInto(LibraryManager.library, {
},
rename: function (oldNode, newDir, newName) {
var oldPath = NODEFS.realPath(oldNode);
- var newPath = PATH.join(NODEFS.realPath(newDir), newName);
+ var newPath = PATH.join2(NODEFS.realPath(newDir), newName);
try {
fs.renameSync(oldPath, newPath);
} catch (e) {
@@ -165,7 +165,7 @@ mergeInto(LibraryManager.library, {
}
},
unlink: function(parent, name) {
- var path = PATH.join(NODEFS.realPath(parent), name);
+ var path = PATH.join2(NODEFS.realPath(parent), name);
try {
fs.unlinkSync(path);
} catch (e) {
@@ -174,7 +174,7 @@ mergeInto(LibraryManager.library, {
}
},
rmdir: function(parent, name) {
- var path = PATH.join(NODEFS.realPath(parent), name);
+ var path = PATH.join2(NODEFS.realPath(parent), name);
try {
fs.rmdirSync(path);
} catch (e) {
@@ -192,7 +192,7 @@ mergeInto(LibraryManager.library, {
}
},
symlink: function(parent, newName, oldPath) {
- var newPath = PATH.join(NODEFS.realPath(parent), newName);
+ var newPath = PATH.join2(NODEFS.realPath(parent), newName);
try {
fs.symlinkSync(oldPath, newPath);
} catch (e) {
@@ -283,4 +283,4 @@ mergeInto(LibraryManager.library, {
}
}
}
-}); \ No newline at end of file
+});
diff --git a/src/library_path.js b/src/library_path.js
index 09808acd..f00a7586 100644
--- a/src/library_path.js
+++ b/src/library_path.js
@@ -59,26 +59,22 @@ mergeInto(LibraryManager.library, {
}
return root + dir;
},
- basename: function(path, ext) {
+ basename: function(path) {
// EMSCRIPTEN return '/'' for '/', not an empty string
if (path === '/') return '/';
- var f = PATH.splitPath(path)[2];
- if (ext && f.substr(-1 * ext.length) === ext) {
- f = f.substr(0, f.length - ext.length);
- }
- return f;
+ var lastSlash = path.lastIndexOf('/');
+ if (lastSlash === -1) return path;
+ return path.substr(lastSlash+1);
},
extname: function(path) {
return PATH.splitPath(path)[3];
},
join: function() {
var paths = Array.prototype.slice.call(arguments, 0);
- return PATH.normalize(paths.filter(function(p, index) {
- if (typeof p !== 'string') {
- throw new TypeError('Arguments to path.join must be strings');
- }
- return p;
- }).join('/'));
+ return PATH.normalize(paths.join('/'));
+ },
+ join2: function(l, r) {
+ return PATH.normalize(l + '/' + r);
},
resolve: function() {
var resolvedPath = '',
@@ -134,4 +130,4 @@ mergeInto(LibraryManager.library, {
return outputParts.join('/');
}
}
-}); \ No newline at end of file
+});
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 857ab7d4..0cf6c97a 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -153,24 +153,30 @@ var LibrarySDL = {
120: 27,
121: 28,
122: 29, // Z
- 44: 54, // comma
- 46: 55, // period
- 47: 56, // slash
- 49: 30, // 1
- 50: 31,
- 51: 32,
- 52: 33,
- 53: 34,
- 54: 35,
- 55: 36,
- 56: 37,
- 57: 38, // 9
- 48: 39, // 0
- 13: 40, // return
- 9: 43, // tab
- 27: 41, // escape
- 32: 44, // space
- 92: 49, // backslash
+ 49: 30, // 1
+ 50: 31,
+ 51: 32,
+ 52: 33,
+ 53: 34,
+ 54: 35,
+ 55: 36,
+ 56: 37,
+ 57: 38, // 9
+ 48: 39, // 0
+ 13: 40, // return
+ 27: 41, // escape
+ 8: 42, // backspace
+ 9: 43, // tab
+ 32: 44, // space
+ 61: 46, // equals
+ 91: 47, // left bracket
+ 93: 48, // right bracket
+ 92: 49, // backslash
+ 59: 51, // ;
+ 96: 52, // apostrophe
+ 44: 54, // comma
+ 46: 55, // period
+ 47: 56, // slash
305: 224, // ctrl
308: 226, // alt
},
@@ -254,9 +260,13 @@ var LibrarySDL = {
}
var webGLContextAttributes = {
- antialias: ((SDL.glAttributes[13 /*SDL_GL_MULTISAMPLEBUFFERS*/] != 0) && (SDL.glAttributes[14 /*SDL_GL_MULTISAMPLESAMPLES*/] > 1))
+ antialias: ((SDL.glAttributes[13 /*SDL_GL_MULTISAMPLEBUFFERS*/] != 0) && (SDL.glAttributes[14 /*SDL_GL_MULTISAMPLESAMPLES*/] > 1)),
+ depth: (SDL.glAttributes[6 /*SDL_GL_DEPTH_SIZE*/] > 0),
+ stencil: (SDL.glAttributes[7 /*SDL_GL_STENCIL_SIZE*/] > 0)
};
+
var ctx = Browser.createContext(canvas, useWebGL, usePageCanvas, webGLContextAttributes);
+
SDL.surfaces[surf] = {
width: width,
height: height,
@@ -1291,12 +1301,12 @@ var LibrarySDL = {
IMG_Load_RW: function(rwopsID, freeSrc) {
try {
// stb_image integration support
- var cleanup = function() {
+ function cleanup() {
if (rwops && freeSrc) _SDL_FreeRW(rwopsID);
};
function addCleanup(func) {
var old = cleanup;
- cleanup = function() {
+ cleanup = function added_cleanup() {
old();
func();
}
@@ -1471,7 +1481,7 @@ var LibrarySDL = {
SDL.audio.buffer = _malloc(SDL.audio.bufferSize);
// Create a callback function that will be routinely called to ask more audio data from the user application.
- SDL.audio.caller = function() {
+ SDL.audio.caller = function SDL_audio_caller() {
if (!SDL.audio) {
return;
}
@@ -1485,7 +1495,7 @@ var LibrarySDL = {
SDL.audio.audioOutput['mozSetup'](SDL.audio.channels, SDL.audio.freq); // use string attributes on mozOutput for closure compiler
SDL.audio.mozBuffer = new Float32Array(totalSamples);
SDL.audio.nextPlayTime = 0;
- SDL.audio.pushAudio = function(ptr, size) {
+ SDL.audio.pushAudio = function SDL_audio_pushAudio(ptr, size) {
var mozBuffer = SDL.audio.mozBuffer;
// The input audio data for SDL audio is either 8-bit or 16-bit interleaved across channels, output for Mozilla Audio Data API
// needs to be Float32 interleaved, so perform a sample conversion.
@@ -1852,7 +1862,7 @@ var LibrarySDL = {
audio.frequency = info.audio.frequency;
// TODO: handle N loops. Behavior matches Mix_PlayMusic
audio.loop = loops != 0;
- audio['onended'] = function() { // TODO: cache these
+ audio['onended'] = function SDL_audio_onended() { // TODO: cache these
channelInfo.audio = null;
if (SDL.channelFinished) {
Runtime.getFuncWrapper(SDL.channelFinished, 'vi')(channel);
@@ -1879,7 +1889,7 @@ var LibrarySDL = {
source.loop = false;
source.buffer = context.createBuffer(numChannels, 1, audio.frequency);
var jsNode = context.createJavaScriptNode(2048, numChannels, numChannels);
- jsNode.onaudioprocess = function(event) {
+ jsNode.onaudioprocess = function jsNode_onaudioprocess(event) {
var buffers = new Array(numChannels);
for (var i = 0; i < numChannels; ++i) {
buffers[i] = event.outputBuffer.getChannelData(i);
diff --git a/src/library_sockfs.js b/src/library_sockfs.js
index 78fc382f..bc3aa997 100644
--- a/src/library_sockfs.js
+++ b/src/library_sockfs.js
@@ -210,7 +210,7 @@ mergeInto(LibraryManager.library, {
}
};
- var handleMessage = function(data) {
+ function handleMessage(data) {
assert(typeof data !== 'string' && data.byteLength !== undefined); // must receive an ArrayBuffer
data = new Uint8Array(data); // make a typed array view on the array buffer
@@ -249,7 +249,7 @@ mergeInto(LibraryManager.library, {
});
} else {
peer.socket.onopen = handleOpen;
- peer.socket.onmessage = function(event) {
+ peer.socket.onmessage = function peer_socket_onmessage(event) {
handleMessage(event.data);
};
}
diff --git a/src/parseTools.js b/src/parseTools.js
index dae386f1..c4f28184 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -157,6 +157,10 @@ function isStructType(type) {
return type[0] == '%';
}
+function isVectorType(type) {
+ return type[type.length-1] === '>';
+}
+
function isStructuralType(type) {
return /^{ ?[^}]* ?}$/.test(type); // { i32, i8 } etc. - anonymous struct types
}
@@ -215,8 +219,22 @@ function isIdenticallyImplemented(type1, type2) {
}
function isIllegalType(type) {
- var bits = getBits(type);
- return bits > 0 && (bits >= 64 || !isPowerOfTwo(bits));
+ switch (type) {
+ case 'i1':
+ case 'i8':
+ case 'i16':
+ case 'i32':
+ case 'float':
+ case 'double':
+ case 'rawJS':
+ case '<2 x float>':
+ case '<4 x float>':
+ case '<2 x i32>':
+ case '<4 x i32>':
+ case 'void': return false;
+ }
+ if (!type || type[type.length-1] === '*') return false;
+ return true;
}
function isVoidType(type) {
@@ -287,6 +305,9 @@ function getReturnType(type) {
if (pointingLevels(type) > 1) return '*'; // the type of a call can be either the return value, or the entire function. ** or more means it is a return value
var lastOpen = type.lastIndexOf('(');
if (lastOpen > 0) {
+ // handle things like void (i32)* (i32, void (i32)*)*
+ var closeStar = type.indexOf(')*');
+ if (closeStar > 0 && closeStar < type.length-2) lastOpen = closeStar+3;
return type.substr(0, lastOpen-1);
}
return type;
@@ -328,28 +349,29 @@ function getVectorSize(type) {
return parseInt(type.substring(1, type.indexOf(' ')));
}
-function getVectorBaseType(type) {
+function getVectorNativeType(type) {
Types.usesSIMD = true;
switch (type) {
case '<2 x float>':
case '<4 x float>': return 'float';
case '<2 x i32>':
- case '<4 x i32>': return 'uint';
+ case '<4 x i32>': return 'i32';
default: throw 'unknown vector type ' + type;
}
}
-function getVectorNativeType(type) {
- Types.usesSIMD = true;
+function getSIMDName(type) {
switch (type) {
- case '<2 x float>':
- case '<4 x float>': return 'float';
- case '<2 x i32>':
- case '<4 x i32>': return 'i32';
- default: throw 'unknown vector type ' + type;
+ case 'i32': return 'uint';
+ case 'float': return 'float';
+ default: throw 'getSIMDName ' + type;
}
}
+function getVectorBaseType(type) {
+ return getSIMDName(getVectorNativeType(type));
+}
+
function addIdent(token) {
token.ident = token.text;
return token;
@@ -465,26 +487,13 @@ function parseParamTokens(params) {
Types.needAnalysis[ret[ret.length-1].type] = 0;
anonymousIndex ++;
}
- } else if (segment[1].text in PARSABLE_LLVM_FUNCTIONS) {
- ret.push(parseLLVMFunctionCall(segment));
- } else if (segment[1].text === 'blockaddress') {
- ret.push(parseBlockAddress(segment));
- } else if (segment[1].type && segment[1].type == '{') {
- ret.push(parseLLVMSegment(segment));
} else {
if (segment[2] && segment[2].text == 'to') { // part of bitcast params
segment = segment.slice(0, 2);
}
- while (segment.length > 2) {
- segment[0].text += segment[1].text;
- segment.splice(1, 1); // TODO: merge tokens nicely
- }
- ret.push({
- intertype: 'value',
- type: segment[0].text,
- ident: toNiceIdent(parseNumerical(segment[1].text, segment[0].text))
- });
- Types.needAnalysis[removeAllPointing(ret[ret.length-1].type)] = 0;
+ var parsed = parseLLVMSegment(segment);
+ if (parsed.intertype === 'value' && !isIllegalType(parsed.type)) parsed.ident = parseNumerical(parsed.ident, parsed.type);
+ ret.push(parsed);
}
ret[ret.length-1].byVal = byVal;
}
@@ -558,25 +567,6 @@ function sortGlobals(globals) {
});
}
-function finalizeParam(param) {
- if (param.intertype in PARSABLE_LLVM_FUNCTIONS) {
- return finalizeLLVMFunctionCall(param);
- } else if (param.intertype === 'blockaddress') {
- return finalizeBlockAddress(param);
- } else if (param.intertype === 'jsvalue') {
- return param.ident;
- } else {
- if (param.type == 'i64' && USE_TYPED_ARRAYS == 2) {
- return parseI64Constant(param.ident);
- }
- var ret = toNiceIdent(param.ident);
- if (ret in Variables.globals) {
- ret = makeGlobalUse(ret);
- }
- return ret;
- }
-}
-
// Segment ==> Parameter
function parseLLVMSegment(segment) {
var type;
@@ -1009,11 +999,9 @@ function getOldLabel(label) {
}
function calcAllocatedSize(type) {
- if (pointingLevels(type) == 0 && isStructType(type)) {
- return Types.types[type].flatSize; // makeEmptyStruct(item.allocatedType).length;
- } else {
- return Runtime.getNativeTypeSize(type); // We can really get away with '1', though, at least on the stack...
- }
+ var ret = Runtime.getNativeTypeSize(type);
+ if (ret) return ret;
+ return Types.types[type].flatSize; // known type
}
// Generates the type signature for a structure, for each byte, the type that is there.
@@ -1809,7 +1797,7 @@ function makeGetSlabs(ptr, type, allowMultiple, unsigned) {
switch(type) {
case 'i1': case 'i8': return [unsigned ? 'HEAPU8' : 'HEAP8']; break;
case 'i16': return [unsigned ? 'HEAPU16' : 'HEAP16']; break;
- case '<4 x i32>': case 'uint':
+ case '<4 x i32>':
case 'i32': case 'i64': return [unsigned ? 'HEAPU32' : 'HEAP32']; break;
case 'double': {
if (TARGET_LE32) return ['HEAPF64']; // in le32, we do have the ability to assume 64-bit alignment
@@ -2002,6 +1990,8 @@ function finalizeLLVMParameter(param, noIndexizeFunctions) {
} else if (param.ident == 'zeroinitializer') {
if (isStructType(param.type)) {
return makeLLVMStruct(zeros(Types.types[param.type].fields.length));
+ } else if (isVectorType(param.type)) {
+ return ensureVector(0, getVectorBaseType(param.type));
} else {
return '0';
}
@@ -2024,7 +2014,7 @@ function finalizeLLVMParameter(param, noIndexizeFunctions) {
} else if (param.intertype == 'mathop') {
return processMathop(param);
} else if (param.intertype === 'vector') {
- return 'float32x4(' + param.idents.join(',') + ')';
+ return getVectorBaseType(param.type) + '32x4(' + param.idents.join(',') + ')';
} else {
throw 'invalid llvm parameter: ' + param.intertype;
}
@@ -2287,7 +2277,7 @@ function processMathop(item) {
case 'trunc': {
return '((' + idents[0] + '[0]) & ' + (Math.pow(2, bitsLeft)-1) + ')';
}
- case 'select': return idents[0] + ' ? ' + makeCopyI64(idents[1]) + ' : ' + makeCopyI64(idents[2]);
+ case 'select': return '(' + idents[0] + ' ? ' + makeCopyI64(idents[1]) + ' : ' + makeCopyI64(idents[2]) + ')';;
case 'ptrtoint': return makeI64(idents[0], 0);
case 'inttoptr': {
var m = /\(?\[(\d+),\d+\]\)?/.exec(idents[0]);
@@ -2384,6 +2374,9 @@ function processMathop(item) {
return 'SIMD.uint32x4BitsToFloat32x4(' + idents[0] + ')';
}
}
+ case 'and': return 'SIMD.and(' + idents[0] + ',' + idents[1] + ')';
+ case 'or': return 'SIMD.or(' + idents[0] + ',' + idents[1] + ')';
+ case 'xor': return 'SIMD.xor(' + idents[0] + ',' + idents[1] + ')';
default: throw 'vector op todo: ' + dump(item);
}
}
@@ -2488,7 +2481,7 @@ function processMathop(item) {
}
case 'fpext': case 'sext': return idents[0];
case 'fptrunc': return idents[0];
- case 'select': return idents[0] + '?' + asmEnsureFloat(idents[1], item.type) + ':' + asmEnsureFloat(idents[2], item.type);
+ case 'select': return '(' + idents[0] + '?' + asmEnsureFloat(idents[1], item.type) + ':' + asmEnsureFloat(idents[2], item.type) + ')';
case 'ptrtoint': case 'inttoptr': {
var ret = '';
if (QUANTUM_SIZE == 1) {
diff --git a/src/preamble.js b/src/preamble.js
index ee273f6a..c88e4052 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -1060,7 +1060,7 @@ Module['writeAsciiToMemory'] = writeAsciiToMemory;
{{{ reSign }}}
#if PRECISE_I32_MUL
-if (!Math['imul']) Math['imul'] = function(a, b) {
+if (!Math['imul']) Math['imul'] = function imul(a, b) {
var ah = a >>> 16;
var al = a & 0xffff;
var bh = b >>> 16;
@@ -1068,14 +1068,14 @@ if (!Math['imul']) Math['imul'] = function(a, b) {
return (al*bl + ((ah*bl + al*bh) << 16))|0;
};
#else
-Math['imul'] = function(a, b) {
+Math['imul'] = function imul(a, b) {
return (a*b)|0; // fast but imprecise
};
#endif
Math.imul = Math['imul'];
#if TO_FLOAT32
-if (!Math['toFloat32']) Math['toFloat32'] = function(x) {
+if (!Math['toFloat32']) Math['toFloat32'] = function toFloat32(x) {
return x;
};
Math.toFloat32 = Math['toFloat32'];
@@ -1107,19 +1107,21 @@ var Math_min = Math.min;
// it happens right before run - run will be postponed until
// the dependencies are met.
var runDependencies = 0;
-var runDependencyTracking = {};
var runDependencyWatcher = null;
var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
+#if ASSERTIONS
+var runDependencyTracking = {};
+#endif
function addRunDependency(id) {
runDependencies++;
if (Module['monitorRunDependencies']) {
Module['monitorRunDependencies'](runDependencies);
}
+#if ASSERTIONS
if (id) {
assert(!runDependencyTracking[id]);
runDependencyTracking[id] = 1;
-#if ASSERTIONS
if (runDependencyWatcher === null && typeof setInterval !== 'undefined') {
// Check for missing dependencies every few seconds
runDependencyWatcher = setInterval(function() {
@@ -1136,10 +1138,10 @@ function addRunDependency(id) {
}
}, 10000);
}
-#endif
} else {
Module.printErr('warning: run dependency added without ID');
}
+#endif
}
Module['addRunDependency'] = addRunDependency;
function removeRunDependency(id) {
@@ -1147,12 +1149,14 @@ function removeRunDependency(id) {
if (Module['monitorRunDependencies']) {
Module['monitorRunDependencies'](runDependencies);
}
+#if ASSERTIONS
if (id) {
assert(runDependencyTracking[id]);
delete runDependencyTracking[id];
} else {
Module.printErr('warning: run dependency removed without ID');
}
+#endif
if (runDependencies == 0) {
if (runDependencyWatcher !== null) {
clearInterval(runDependencyWatcher);
diff --git a/src/proxyClient.js b/src/proxyClient.js
index 38ea5771..8f4ad7a6 100644
--- a/src/proxyClient.js
+++ b/src/proxyClient.js
@@ -5,7 +5,7 @@ Module.ctx = Module.canvas.getContext('2d');
var worker = new Worker('{{{ filename }}}.js');
-worker.onmessage = function(event) {
+worker.onmessage = function worker_onmessage(event) {
var data = event.data;
switch (data.target) {
case 'stdout': {
diff --git a/src/proxyWorker.js b/src/proxyWorker.js
index 29b2528d..5d34b900 100644
--- a/src/proxyWorker.js
+++ b/src/proxyWorker.js
@@ -2,12 +2,12 @@
function EventListener() {
this.listeners = {};
- this.addEventListener = function(event, func) {
+ this.addEventListener = function addEventListener(event, func) {
if (!this.listeners[event]) this.listeners[event] = [];
this.listeners[event].push(func);
};
- this.fireEvent = function(event) {
+ this.fireEvent = function fireEvent(event) {
event.preventDefault = function(){};
if (event.type in this.listeners) {
@@ -22,17 +22,17 @@ var window = this;
var windowExtra = new EventListener();
for (var x in windowExtra) window[x] = windowExtra[x];
-window.close = function() {
+window.close = function window_close() {
postMessage({ target: 'window', method: 'close' });
};
var document = new EventListener();
-document.createElement = function(what) {
+document.createElement = function document_createElement(what) {
switch(what) {
case 'canvas': {
var canvas = new EventListener();
- canvas.ensureData = function() {
+ canvas.ensureData = function canvas_ensureData() {
if (!canvas.data || canvas.data.width !== canvas.width || canvas.data.height !== canvas.height) {
canvas.data = {
width: canvas.width,
@@ -42,7 +42,7 @@ document.createElement = function(what) {
postMessage({ target: 'canvas', op: 'resize', width: canvas.width, height: canvas.height });
}
};
- canvas.getContext = function(type) {
+ canvas.getContext = function canvas_getContext(type) {
assert(type == '2d');
return {
getImageData: function(x, y, w, h) {
@@ -63,7 +63,7 @@ document.createElement = function(what) {
};
};
canvas.boundingClientRect = {};
- canvas.getBoundingClientRect = function() {
+ canvas.getBoundingClientRect = function canvas_getBoundingClientRect() {
return {
width: canvas.boundingClientRect.width,
height: canvas.boundingClientRect.height,
@@ -89,10 +89,10 @@ Module.canvas = document.createElement('canvas');
Module.setStatus = function(){};
-Module.print = function(x) {
+Module.print = function Module_print(x) {
postMessage({ target: 'stdout', content: x });
};
-Module.printErr = function(x) {
+Module.printErr = function Module_printErr(x) {
postMessage({ target: 'stderr', content: x });
};
@@ -112,7 +112,7 @@ function messageResender() {
}
}
-onmessage = function(message) {
+onmessage = function onmessage(message) {
if (!calledMain) {
if (!messageBuffer) {
messageBuffer = [];
diff --git a/src/runtime.js b/src/runtime.js
index 5d5cb43b..3f89dc84 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -145,7 +145,7 @@ var Runtime = {
//! @param type The type, by name.
getNativeTypeSize: function(type) {
#if QUANTUM_SIZE == 1
- return 1;
+ return 1;
#else
switch (type) {
case 'i1': case 'i8': return 1;
@@ -161,6 +161,8 @@ var Runtime = {
var bits = parseInt(type.substr(1));
assert(bits % 8 === 0);
return bits/8;
+ } else {
+ return 0;
}
}
}
@@ -392,7 +394,7 @@ var Runtime = {
getFuncWrapper: function(func, sig) {
assert(sig);
if (!Runtime.funcWrappers[func]) {
- Runtime.funcWrappers[func] = function() {
+ Runtime.funcWrappers[func] = function dynCall_wrapper() {
return Runtime.dynCall(sig, func, arguments);
};
}
@@ -450,7 +452,7 @@ var Runtime = {
buffer.length = 0;
return ret;
}
- this.processJSString = function(string) {
+ this.processJSString = function processJSString(string) {
string = unescape(encodeURIComponent(string));
var ret = [];
for (var i = 0; i < string.length; i++) {
diff --git a/src/settings.js b/src/settings.js
index d2b47dc8..42e31b3a 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -410,7 +410,8 @@ var HEADLESS = 0; // If 1, will include shim code that tries to 'fake' a browser
var BENCHMARK = 0; // If 1, will just time how long main() takes to execute, and not
// print out anything at all whatsoever. This is useful for benchmarking.
-var ASM_JS = 0; // If 1, generate code in asm.js format.
+var ASM_JS = 0; // If 1, generate code in asm.js format. If 2, emits the same code except
+ // for omitting 'use asm'
var PGO = 0; // Enables profile-guided optimization in the form of runtime checks for
// which functions are actually called. Emits a list during shutdown that you
diff --git a/src/shell.html b/src/shell.html
index a33735d9..53a4fffb 100644
--- a/src/shell.html
+++ b/src/shell.html
@@ -63,8 +63,11 @@
},
canvas: document.getElementById('canvas'),
setStatus: function(text) {
- if (Module.setStatus.interval) clearInterval(Module.setStatus.interval);
+ if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
+ if (text === Module.setStatus.text) return;
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
+ var now = Date.now();
+ if (m && now - Date.now() < 30) return; // if this is a progress update, skip it if too soon
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
if (m) {
diff --git a/src/shell.js b/src/shell.js
index be23b3c1..b68e16d9 100644
--- a/src/shell.js
+++ b/src/shell.js
@@ -38,17 +38,17 @@ var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIR
if (ENVIRONMENT_IS_NODE) {
// Expose functionality in the same simple way that the shells work
// Note that we pollute the global namespace here, otherwise we break in node
- Module['print'] = function(x) {
+ Module['print'] = function print(x) {
process['stdout'].write(x + '\n');
};
- Module['printErr'] = function(x) {
+ Module['printErr'] = function printErr(x) {
process['stderr'].write(x + '\n');
};
var nodeFS = require('fs');
var nodePath = require('path');
- Module['read'] = function(filename, binary) {
+ Module['read'] = function read(filename, binary) {
filename = nodePath['normalize'](filename);
var ret = nodeFS['readFileSync'](filename);
// The path is absolute if the normalized version is the same as the resolved.
@@ -60,9 +60,9 @@ if (ENVIRONMENT_IS_NODE) {
return ret;
};
- Module['readBinary'] = function(filename) { return Module['read'](filename, true) };
+ Module['readBinary'] = function readBinary(filename) { return Module['read'](filename, true) };
- Module['load'] = function(f) {
+ Module['load'] = function load(f) {
globalEval(read(f));
};
@@ -77,10 +77,10 @@ else if (ENVIRONMENT_IS_SHELL) {
if (typeof read != 'undefined') {
Module['read'] = read;
} else {
- Module['read'] = function() { throw 'no read() available (jsc?)' };
+ Module['read'] = function read() { throw 'no read() available (jsc?)' };
}
- Module['readBinary'] = function(f) {
+ Module['readBinary'] = function readBinary(f) {
return read(f, 'binary');
};
@@ -93,7 +93,7 @@ else if (ENVIRONMENT_IS_SHELL) {
this['{{{ EXPORT_NAME }}}'] = Module;
}
else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
- Module['read'] = function(url) {
+ Module['read'] = function read(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
xhr.send(null);
@@ -105,10 +105,10 @@ else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
}
if (typeof console !== 'undefined') {
- Module['print'] = function(x) {
+ Module['print'] = function print(x) {
console.log(x);
};
- Module['printErr'] = function(x) {
+ Module['printErr'] = function printErr(x) {
console.log(x);
};
} else {
@@ -136,7 +136,7 @@ function globalEval(x) {
eval.call(null, x);
}
if (!Module['load'] == 'undefined' && Module['read']) {
- Module['load'] = function(f) {
+ Module['load'] = function load(f) {
globalEval(Module['read'](f));
};
}
diff --git a/system/include/compat/ctype.h b/system/include/compat/ctype.h
index 891006d9..3f504946 100644
--- a/system/include/compat/ctype.h
+++ b/system/include/compat/ctype.h
@@ -14,4 +14,21 @@
#include_next <ctype.h>
+/* We undef these until libcxx is fixed. Without this,
+ some things can fail to compile correctly, like
+ Boost. Issue #1716. */
+
+#undef isalpha
+#undef isblank
+#undef iscntrl
+#undef isdigit
+#undef isgraph
+#undef islower
+#undef isprint
+#undef ispunct
+#undef isspace
+#undef isupper
+#undef isxdigit
+#undef isctype
+
#endif /* _COMPAT_CTYPE_H_ */
diff --git a/system/include/compat/wchar.h b/system/include/compat/wchar.h
new file mode 100644
index 00000000..42f0bcee
--- /dev/null
+++ b/system/include/compat/wchar.h
@@ -0,0 +1,23 @@
+#ifndef _COMPAT_WCHAR_H_
+#define _COMPAT_WCHAR_H_
+
+#include_next <wchar.h>
+
+/* We undef these until libcxx is fixed. Without this,
+ some things can fail to compile correctly, like
+ Boost. Issue #1716. */
+
+#undef iswalpha
+#undef iswblank
+#undef iswcntrl
+#undef iswdigit
+#undef iswgraph
+#undef iswlower
+#undef iswprint
+#undef iswpunct
+#undef iswspace
+#undef iswupper
+#undef iswxdigit
+#undef iswctype
+
+#endif /* _COMPAT_WCHAR_H_ */
diff --git a/system/include/compat/wctype.h b/system/include/compat/wctype.h
new file mode 100644
index 00000000..0eeaab8b
--- /dev/null
+++ b/system/include/compat/wctype.h
@@ -0,0 +1,23 @@
+#ifndef _COMPAT_WCTYPE_H_
+#define _COMPAT_WCTYPE_H_
+
+#include_next <wctype.h>
+
+/* We undef these until libcxx is fixed. Without this,
+ some things can fail to compile correctly, like
+ Boost. Issue #1716. */
+
+#undef iswalpha
+#undef iswblank
+#undef iswcntrl
+#undef iswdigit
+#undef iswgraph
+#undef iswlower
+#undef iswprint
+#undef iswpunct
+#undef iswspace
+#undef iswupper
+#undef iswxdigit
+#undef iswctype
+
+#endif /* _COMPAT_WCTYPE_H_ */
diff --git a/system/include/emscripten/vector.h b/system/include/emscripten/vector.h
index ea148f0d..938f2369 100644
--- a/system/include/emscripten/vector.h
+++ b/system/include/emscripten/vector.h
@@ -4,3 +4,13 @@
typedef float float32x4 __attribute__((__vector_size__(16)));
typedef unsigned int uint32x4 __attribute__((__vector_size__(16)));
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+unsigned int emscripten_float32x4_signmask(float32x4 x);
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/tests/aniso.c b/tests/aniso.c
index e8d7bd3f..f1674cad 100644
--- a/tests/aniso.c
+++ b/tests/aniso.c
@@ -66,6 +66,9 @@ int main(int argc, char *argv[])
const char *exts = (const char *)glGetString(GL_EXTENSIONS);
assert(hasext(exts, "GL_EXT_texture_filter_anisotropic"));
+ const char *vendor = (const char *)glGetString(GL_VENDOR);
+ printf("vendor: %s\n", vendor);
+
GLint aniso;
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso);
printf("Max anisotropy: %d (using that)\n", aniso);
diff --git a/tests/cases/caall.ll b/tests/cases/caall.ll
index 313116e6..5b8f7f29 100644
--- a/tests/cases/caall.ll
+++ b/tests/cases/caall.ll
@@ -18,7 +18,7 @@ entry:
define (i32*)** @_ZNSt3__13mapINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEPFvP6ObjectENS_4lessIS6_EENS4_INS_4pairIKS6_SA_EEEEEixERSE_(i32 %x) {
entry:
%ret = inttoptr i32 0 to (i32*)**
- ret %ret
+ ret (i32*)** %ret
}
; [#uses=1]
diff --git a/tests/cases/selectadd.ll b/tests/cases/selectadd.ll
new file mode 100644
index 00000000..093032b8
--- /dev/null
+++ b/tests/cases/selectadd.ll
@@ -0,0 +1,29 @@
+
+; ModuleID = 'tests/hello_world.bc'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
+target triple = "i386-pc-linux-gnu"
+
+@.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*]
+
+; [#uses=0]
+define i32 @main() {
+entry:
+ br label %zero
+
+zero:
+ %.3.ph.i757 = phi i8* [ getelementptr ([15 x i8]* @.str, i32 0, i32 add (i32 xor (i32 ptrtoint (i8* getelementptr ([15 x i8]* @.str, i32 0, i32 select (i1 icmp ugt (i32 sub (i32 0, i32 add (i32 ptrtoint ([15 x i8]* @.str to i32), i32 25)), i32 xor (i32 ptrtoint ([15 x i8]* @.str to i32), i32 -1)), i32 sub (i32 0, i32 add (i32 ptrtoint ([15 x i8]* @.str to i32), i32 25)), i32 xor (i32 ptrtoint ([15 x i8]* @.str to i32), i32 -1))) to i32), i32 -1), i32 25)), %entry ], [ getelementptr ([15 x i8]* @.str, i32 0, i32 ptrtoint (i8* getelementptr ([15 x i8]* @.str, i32 0, i32 add (i32 sub (i32 0, i32 ptrtoint ([15 x i8]* @.str to i32)), i32 25)) to i32)), %other ]
+
+ %retval = alloca i32, align 4 ; [#uses=1 type=i32*]
+ store i32 0, i32* %retval
+ %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32]
+ br label %other
+
+other:
+ br i1 0, label %zero, label %last
+
+last:
+ ret i32 1
+}
+
+declare i32 @printf(i8*, ...)
+
diff --git a/tests/cubegeom.c b/tests/cubegeom.c
index fac0da2b..96d56339 100644
--- a/tests/cubegeom.c
+++ b/tests/cubegeom.c
@@ -194,8 +194,14 @@ int main(int argc, char *argv[])
// sauer vertex data is apparently 0-12: V3F, 12: N1B, 16-24: T2F, 24-28: T2S, 28-32: C4B
glVertexPointer(3, GL_FLOAT, 32, (void*)0); // all these apply to the ARRAY_BUFFER that is bound
glTexCoordPointer(2, GL_FLOAT, 32, (void*)16);
+
glClientActiveTexture(GL_TEXTURE1); // XXX seems to be ignored in native build
glTexCoordPointer(2, GL_SHORT, 32, (void*)24);
+ glGetIntegerv(GL_TEXTURE_COORD_ARRAY_SIZE, &tempInt); assert(tempInt == 2);
+ glGetIntegerv(GL_TEXTURE_COORD_ARRAY_TYPE, &tempInt); assert(tempInt == GL_SHORT);
+ glGetIntegerv(GL_TEXTURE_COORD_ARRAY_STRIDE, &tempInt); assert(tempInt == 32);
+ glGetPointerv(GL_TEXTURE_COORD_ARRAY_POINTER, &tempPtr); assert(tempPtr == (void *)24);
+
glClientActiveTexture(GL_TEXTURE0); // likely not needed, it is a cleanup
glNormalPointer(GL_BYTE, 32, (void*)12);
glColorPointer(4, GL_UNSIGNED_BYTE, 32, (void*)28);
diff --git a/tests/mmap_file.c b/tests/mmap_file.c
new file mode 100644
index 00000000..6eed95e0
--- /dev/null
+++ b/tests/mmap_file.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <sys/mman.h>
+#include <emscripten.h>
+#include <string.h>
+#include <assert.h>
+
+int main() {
+ printf("*\n");
+ FILE *f = fopen("data.dat", "r");
+ char *m;
+ m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 0);
+ for (int i = 0; i < 20; i++) putchar(m[i]);
+ assert(!strncmp(m, "data from the file .", 20));
+ munmap(m, 9000);
+ printf("\n");
+ m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 5);
+ for (int i = 0; i < 20; i++) putchar(m[i]);
+ assert(!strncmp(m, "from the file ......", 20));
+ munmap(m, 9000);
+ printf("\n*\n");
+
+#ifdef REPORT_RESULT
+ int result = 1;
+ REPORT_RESULT();
+#endif
+ return 0;
+}
diff --git a/tests/test_browser.py b/tests/test_browser.py
index be23074a..d52f109f 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -338,7 +338,7 @@ If manually bisecting:
("somefile.txt@/directory/file.txt", "/directory/file.txt"),
("somefile.txt@/directory/file.txt", "directory/file.txt"),
(absolute_src_path + "@/directory/file.txt", "directory/file.txt")]
-
+
for test in test_cases:
(srcpath, dstpath) = test
print 'Testing', srcpath, dstpath
@@ -346,6 +346,11 @@ If manually bisecting:
Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', srcpath, '-o', 'page.html']).communicate()
self.run_browser('page.html', 'You should see |load me right before|.', '/report_result?1')
+ # Test that '--no-heap-copy' works.
+ make_main('somefile.txt')
+ Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', 'somefile.txt', '--no-heap-copy', '-o', 'page.html']).communicate()
+ self.run_browser('page.html', 'You should see |load me right before|.', '/report_result?1')
+
# By absolute path
make_main('somefile.txt') # absolute becomes relative
@@ -869,6 +874,48 @@ keydown(100);keyup(100); // trigger the end
def test_glut_wheelevents(self):
self.btest('glut_wheelevents.c', '1')
+ def test_webgl_context_attributes(self):
+ # Javascript code to check the attributes support we want to test in the WebGL implementation
+ # (request the attribute, create a context and check its value afterwards in the context attributes).
+ # Tests will succeed when an attribute is not supported.
+ open(os.path.join(self.get_dir(), 'check_webgl_attributes_support.js'), 'w').write('''
+ mergeInto(LibraryManager.library, {
+ webglAntialiasSupported: function() {
+ canvas = document.createElement('canvas');
+ context = canvas.getContext('experimental-webgl', {antialias: true});
+ attributes = context.getContextAttributes();
+ return attributes.antialias;
+ },
+ webglDepthSupported: function() {
+ canvas = document.createElement('canvas');
+ context = canvas.getContext('experimental-webgl', {depth: true});
+ attributes = context.getContextAttributes();
+ return attributes.depth;
+ },
+ webglStencilSupported: function() {
+ canvas = document.createElement('canvas');
+ context = canvas.getContext('experimental-webgl', {stencil: true});
+ attributes = context.getContextAttributes();
+ return attributes.stencil;
+ }
+ });
+ ''')
+
+ # Copy common code file to temporary directory
+ filepath = path_from_root('tests/test_webgl_context_attributes_common.c')
+ temp_filepath = os.path.join(self.get_dir(), os.path.basename(filepath))
+ shutil.copyfile(filepath, temp_filepath)
+
+ # perform tests with attributes activated
+ self.btest('test_webgl_context_attributes_glut.c', '1', args=['--js-library', 'check_webgl_attributes_support.js', '-DAA_ACTIVATED', '-DDEPTH_ACTIVATED', '-DSTENCIL_ACTIVATED'])
+ self.btest('test_webgl_context_attributes_sdl.c', '1', args=['--js-library', 'check_webgl_attributes_support.js', '-DAA_ACTIVATED', '-DDEPTH_ACTIVATED', '-DSTENCIL_ACTIVATED'])
+ self.btest('test_webgl_context_attributes_glfw.c', '1', args=['--js-library', 'check_webgl_attributes_support.js', '-DAA_ACTIVATED', '-DDEPTH_ACTIVATED', '-DSTENCIL_ACTIVATED'])
+
+ # perform tests with attributes desactivated
+ self.btest('test_webgl_context_attributes_glut.c', '1', args=['--js-library', 'check_webgl_attributes_support.js'])
+ self.btest('test_webgl_context_attributes_sdl.c', '1', args=['--js-library', 'check_webgl_attributes_support.js'])
+ self.btest('test_webgl_context_attributes_glfw.c', '1', args=['--js-library', 'check_webgl_attributes_support.js'])
+
def test_emscripten_get_now(self):
self.btest('emscripten_get_now.cpp', '1')
@@ -1524,3 +1571,7 @@ keydown(100);keyup(100); // trigger the end
Popen([PYTHON, EMCC, path_from_root('tests', 'browser_module.cpp'), '-o', 'module.js', '-O2', '-s', 'SIDE_MODULE=1', '-s', 'DLOPEN_SUPPORT=1', '-s', 'EXPORTED_FUNCTIONS=["_one", "_two"]']).communicate()
self.btest('browser_main.cpp', args=['-O2', '-s', 'MAIN_MODULE=1', '-s', 'DLOPEN_SUPPORT=1'], expected='8')
+ def test_mmap_file(self):
+ open(self.in_dir('data.dat'), 'w').write('data from the file ' + ('.' * 9000))
+ for extra_args in [[], ['--no-heap-copy']]:
+ self.btest(path_from_root('tests', 'mmap_file.c'), expected='1', args=['--preload-file', 'data.dat'] + extra_args)
diff --git a/tests/test_core.py b/tests/test_core.py
index dd5b1e39..b2147d49 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -2949,6 +2949,23 @@ Exiting setjmp function, level: 0, prev_jmp: -1
'''
self.do_run(src, '3.14159')
+ def test_iswdigit(self):
+ if self.emcc_args is None: return self.skip('no libcxx inclusion without emcc')
+
+ src = '''
+ #include <stdio.h>
+ #include <cctype>
+ #include <cwctype>
+
+ int main() {
+ using namespace std;
+ printf("%d ", isdigit('0'));
+ printf("%d ", iswdigit(L'0'));
+ return 0;
+ }
+ '''
+ self.do_run(src, '1 1')
+
def test_polymorph(self):
if self.emcc_args is None: return self.skip('requires emcc')
src = '''
@@ -3797,7 +3814,6 @@ def process(filename):
self.do_run(open(path_from_root('tests', 'emscripten_get_now.cpp')).read(), 'Timer resolution is good.')
def test_inlinejs(self):
- if Settings.ASM_JS: Settings.ASM_JS = 2 # skip validation, asm does not support random code
if not self.is_le32(): return self.skip('le32 needed for inline js')
src = r'''
#include <stdio.h>
@@ -3825,7 +3841,6 @@ def process(filename):
self.do_run(src, 'Inline JS is very cool\n3.64\n') # TODO 1\n2\n3\n1\n2\n3\n')
def test_inlinejs2(self):
- if Settings.ASM_JS: Settings.ASM_JS = 2 # skip validation, asm does not support random code
if not self.is_le32(): return self.skip('le32 needed for inline js')
src = r'''
#include <stdio.h>
@@ -7268,6 +7283,18 @@ date: 18.07.2013w; day 18, month 7, year 2013, extra: 201, 3
'''
self.do_run(src, '4779 4779')
+ def test_sscanf_float(self):
+ src = r'''
+ #include "stdio.h"
+
+ int main(){
+ float f1, f2, f3, f4, f5, f6, f7, f8, f9;
+ sscanf("0.512 0.250x5.129_-9.98 1.12*+54.32E3 +54.32E3^87.5E-3 87.5E-3$", "%f %fx%f_%f %f*%f %f^%f %f$", &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, &f9);
+ printf("\n%f, %f, %f, %f, %f, %f, %f, %f, %f\n", f1, f2, f3, f4, f5, f6, f7, f8, f9);
+ }
+ '''
+ self.do_run(src, '\n0.512000, 0.250000, 5.129000, -9.980000, 1.120000, 54320.000000, 54320.000000, 0.087500, 0.087500\n')
+
def test_langinfo(self):
src = open(path_from_root('tests', 'langinfo', 'test.c'), 'r').read()
expected = open(path_from_root('tests', 'langinfo', 'output.txt'), 'r').read()
@@ -8565,30 +8592,13 @@ void*:16
def test_mmap_file(self):
if self.emcc_args is None: return self.skip('requires emcc')
- self.emcc_args += ['--embed-file', 'data.dat']
+ for extra_args in [[], ['--no-heap-copy']]:
+ self.emcc_args += ['--embed-file', 'data.dat'] + extra_args
- open(self.in_dir('data.dat'), 'w').write('data from the file ' + ('.' * 9000))
+ open(self.in_dir('data.dat'), 'w').write('data from the file ' + ('.' * 9000))
- src = r'''
- #include <stdio.h>
- #include <sys/mman.h>
-
- int main() {
- printf("*\n");
- FILE *f = fopen("data.dat", "r");
- char *m;
- m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 0);
- for (int i = 0; i < 20; i++) putchar(m[i]);
- munmap(m, 9000);
- printf("\n");
- m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 5);
- for (int i = 0; i < 20; i++) putchar(m[i]);
- munmap(m, 9000);
- printf("\n*\n");
- return 0;
- }
- '''
- self.do_run(src, '*\ndata from the file .\nfrom the file ......\n*\n')
+ src = open(path_from_root('tests', 'mmap_file.c')).read()
+ self.do_run(src, '*\ndata from the file .\nfrom the file ......\n*\n')
def test_cubescript(self):
if self.emcc_args is None: return self.skip('requires emcc')
@@ -8631,6 +8641,128 @@ void*:16
main = main[:main.find('\n}')]
assert main.count('\n') == 7, 'must not emit too many postSets: %d' % main.count('\n')
+ def test_simd(self):
+ if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2')
+ if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate
+ src = r'''
+#include <stdio.h>
+
+#include <emscripten/vector.h>
+
+static inline float32x4 __attribute__((always_inline))
+_mm_set_ps(const float __Z, const float __Y, const float __X, const float __W)
+{
+ return (float32x4){ __W, __X, __Y, __Z };
+}
+
+static __inline__ float32x4 __attribute__((__always_inline__))
+_mm_setzero_ps(void)
+{
+ return (float32x4){ 0.0, 0.0, 0.0, 0.0 };
+}
+
+int main(int argc, char **argv) {
+ float data[8];
+ for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc); // confuse optimizer
+ {
+ float32x4 *a = (float32x4*)&data[0];
+ float32x4 *b = (float32x4*)&data[4];
+ float32x4 c, d;
+ c = *a;
+ d = *b;
+ printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ c = c+d;
+ printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ d = c*d;
+ printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ c = _mm_setzero_ps();
+ printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3]);
+ }
+ {
+ uint32x4 *a = (uint32x4*)&data[0];
+ uint32x4 *b = (uint32x4*)&data[4];
+ uint32x4 c, d, e, f;
+ c = *a;
+ d = *b;
+ printf("4uints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]);
+ e = c+d;
+ f = c-d;
+ printf("5uints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
+ e = c&d;
+ f = c|d;
+ e = ~c&d;
+ f = c^d;
+ printf("5uintops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
+ }
+ {
+ float32x4 c, d, e, f;
+ c = _mm_set_ps(9.0, 4.0, 0, -9.0);
+ d = _mm_set_ps(10.0, 14.0, -12, -2.0);
+ printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ printf("7calcs: %d\n", emscripten_float32x4_signmask(c)); // TODO: just not just compilation but output as well
+ }
+
+ return 0;
+}
+ '''
+
+ self.do_run(src, '''1floats! 6, 12, 20, 30 42, 56, 72, 90
+2floats! 48, 68, 92, 120 42, 56, 72, 90
+3floats! 48, 68, 92, 120 2016, 3808, 6624, 10800
+zeros 0, 0, 0, 0
+4uints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736
+5uints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056
+5uintops! 36175872, 35651584, 34603008, 33816576 48758784, 52428800, 53477376, 54788096
+6floats! -9, 0, 4, 9 -2, -12, 14, 10
+''')
+
+ def test_simd2(self):
+ if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate
+
+ self.do_run(r'''
+ #include <stdio.h>
+
+ typedef float __m128 __attribute__ ((__vector_size__ (16)));
+
+ static inline __m128 __attribute__((always_inline))
+ _mm_set_ps(const float __Z, const float __Y, const float __X, const float __W)
+ {
+ return (__m128){ __W, __X, __Y, __Z };
+ }
+
+ static inline void __attribute__((always_inline))
+ _mm_store_ps(float *__P, __m128 __A)
+ {
+ *(__m128 *)__P = __A;
+ }
+
+ static inline __m128 __attribute__((always_inline))
+ _mm_add_ps(__m128 __A, __m128 __B)
+ {
+ return __A + __B;
+ }
+
+ using namespace std;
+
+ int main(int argc, char ** argv) {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(9.0, 4.0, 0, -9.0);
+ __m128 v2 = _mm_set_ps(7.0, 3.0, 2.5, 1.0);
+ __m128 v3 = _mm_add_ps(v1, v2);
+ _mm_store_ps(ar, v3);
+
+ for (int i = 0; i < 4; i++) {
+ printf("%f\n", ar[i]);
+ }
+
+ return 0;
+ }
+ ''', '''-8.000000
+2.500000
+7.000000
+16.000000
+''')
+
def test_gcc_unmangler(self):
Settings.NAMED_GLOBALS = 1 # test coverage for this
diff --git a/tests/test_other.py b/tests/test_other.py
index e251da5d..584f6714 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2010,52 +2010,51 @@ a(int [32], char [5]*)
try_delete(path_from_root('tests', 'Module-exports', 'test.js'))
try_delete(path_from_root('tests', 'Module-exports', 'test.js.map'))
- def test_simd(self):
- self.clear()
- Popen([PYTHON, EMCC, path_from_root('tests', 'linpack.c'), '-O2', '-DSP', '--llvm-opts', '''['-O3', '-vectorize', '-vectorize-loops', '-bb-vectorize-vector-bits=128', '-force-vector-width=4']''']).communicate()
- self.assertContained('Unrolled Single Precision', run_js('a.out.js'))
-
- def test_simd2(self):
- self.clear()
+ def test_fs_stream_proto(self):
open('src.cpp', 'w').write(r'''
#include <stdio.h>
-
-#include <emscripten/vector.h>
-
-int main(int argc, char **argv) {
- float data[8];
- for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc);
- {
- float32x4 *a = (float32x4*)&data[0];
- float32x4 *b = (float32x4*)&data[4];
- float32x4 c, d;
- c = *a;
- d = *b;
- printf("floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- c = c+d;
- printf("floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- d = c*d;
- printf("floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- }
- {
- uint32x4 *a = (uint32x4*)&data[0];
- uint32x4 *b = (uint32x4*)&data[4];
- uint32x4 c, d, e, f;
- c = *a;
- d = *b;
- printf("uints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]);
- e = c+d;
- f = c-d;
- printf("uints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
- }
- return 0;
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+
+int main()
+{
+ int file_size = 0;
+ int h = open("src.cpp", O_RDONLY, 0666);
+ if (0 != h)
+ {
+ FILE* file = fdopen(h, "rb");
+ if (0 != file)
+ {
+ fseek(file, 0, SEEK_END);
+ file_size = ftell(file);
+ fseek(file, 0, SEEK_SET);
+ }
+ else
+ {
+ printf("fdopen() failed: %s\n", strerror(errno));
+ return 10;
+ }
+ close(h);
+ printf("File size: %d\n", file_size);
+ }
+ else
+ {
+ printf("open() failed: %s\n", strerror(errno));
+ return 10;
+ }
+ return 0;
}
''')
- Popen([PYTHON, EMCC, 'src.cpp', '-O2']).communicate()
- self.assertContained('''floats! 6, 12, 20, 30 42, 56, 72, 90
-floats! 48, 68, 92, 120 42, 56, 72, 90
-floats! 48, 68, 92, 120 2016, 3808, 6624, 10800
-uints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736
-uints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056
-''', run_js('a.out.js'))
+ Popen([PYTHON, EMCC, 'src.cpp', '--embed-file', 'src.cpp']).communicate()
+ for engine in JS_ENGINES:
+ out = run_js('a.out.js', engine=engine, stderr=PIPE, full_output=True)
+ self.assertContained('File size: 722', out)
+
+ def test_simd(self):
+ self.clear()
+ Popen([PYTHON, EMCC, path_from_root('tests', 'linpack.c'), '-O2', '-DSP', '--llvm-opts', '''['-O3', '-vectorize', '-vectorize-loops', '-bb-vectorize-vector-bits=128', '-force-vector-width=4']''']).communicate()
+ self.assertContained('Unrolled Single Precision', run_js('a.out.js'))
diff --git a/tests/test_sanity.py b/tests/test_sanity.py
index a0fff252..a405c3a3 100644
--- a/tests/test_sanity.py
+++ b/tests/test_sanity.py
@@ -217,7 +217,11 @@ class sanity(RunnerCore):
try:
os.environ['EM_IGNORE_SANITY'] = '1'
- for version, succeed in [('v0.7.9', False), ('v0.8.0', True), ('v0.8.1', True), ('cheez', False)]:
+ for version, succeed in [('v0.7.9', False),
+ ('v0.8.0', True),
+ ('v0.8.1', True),
+ ('v0.10.21-pre', True),
+ ('cheez', False)]:
f = open(path_from_root('tests', 'fake', 'nodejs'), 'w')
f.write('#!/bin/sh\n')
f.write('''if [ $1 = "--version" ]; then
diff --git a/tests/test_webgl_context_attributes_common.c b/tests/test_webgl_context_attributes_common.c
new file mode 100644
index 00000000..7131203b
--- /dev/null
+++ b/tests/test_webgl_context_attributes_common.c
@@ -0,0 +1,262 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include <emscripten.h>
+
+#define BUFFER_OFFSET(i) ((char *)NULL + (i))
+
+static const int WINDOWS_SIZE = 500;
+
+static GLfloat vertices[] = { 0.0f, 250.f, 0.0f,
+ -250.f, -250.f, 0.0f,
+ 250.f, -250.f, 0.0f };
+
+static GLfloat vertices2[] = { 0.0f, 250.f, -1.0f,
+ -250.f, -250.f, -1.0f,
+ 250.f, -250.f, -1.0f };
+
+static GLuint shaderProgram = 0;
+static GLuint verticesVBO = 0;
+static GLuint verticesVBO2 = 0;
+
+static unsigned char backgroundColor[4] = {255, 255, 255, 255};
+static unsigned char triangleColor[4] = {255, 0, 0, 255};
+static unsigned char triangleColor2[4] = {0, 255, 0, 255};
+
+static char vertexShaderSrc[] =
+ "precision highp float;"
+ "precision highp int;"
+
+ "uniform mat4 u_mvpMatrix;"
+ "uniform vec4 u_color;"
+
+ "attribute vec3 a_position;"
+
+ "varying vec4 v_color;"
+
+ "void main() {"
+ " gl_Position = u_mvpMatrix * vec4(a_position, 1.0);"
+ " v_color = u_color;"
+ "}"
+ ;
+
+static char fragmentShaderSrc[] =
+ "precision highp float;"
+ "precision highp int;"
+
+ "varying vec4 v_color;"
+
+ "void main() {"
+ " gl_FragColor = v_color;"
+ "}"
+ ;
+
+static GLuint createShader(const char *source, int type) {
+ GLuint shader = glCreateShader(type);
+ glShaderSource(shader, 1, (const GLchar**)(&source), NULL);
+ glCompileShader(shader);
+ return shader;
+}
+
+static GLuint createShaderProgram(const char *vertexShaderSrc, const char *fragmentShaderSrc) {
+ GLuint program = glCreateProgram();
+ glAttachShader(program, createShader(vertexShaderSrc, GL_VERTEX_SHADER));
+ glAttachShader(program, createShader(fragmentShaderSrc, GL_FRAGMENT_SHADER));
+ glLinkProgram(program);
+ return program;
+}
+
+void ortho(float left, float right, float bottom, float top, float nearVal, float farVal, GLfloat *projMatrix) {
+ float tx = -(right+left)/(right-left);
+ float ty = -(top+bottom)/(top-bottom);
+ float tz = -(farVal+nearVal)/(farVal-nearVal);
+ memset(projMatrix, 0, 16 * sizeof(GLfloat));
+ projMatrix[0] = 2.0f / (right-left);
+ projMatrix[3] = tx;
+ projMatrix[1*4+1] = 2.0f / (top-bottom);
+ projMatrix[1*4+3] = ty;
+ projMatrix[2*4+2] = -2.0f / (farVal-nearVal);
+ projMatrix[2*4+3] = tz;
+ projMatrix[3*4+3] = 1.0f;
+}
+
+static void initGlObjects() {
+ glGenBuffers(1, &verticesVBO);
+ glBindBuffer(GL_ARRAY_BUFFER, verticesVBO);
+ glBufferData(GL_ARRAY_BUFFER, 9*sizeof(float), vertices, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+ glGenBuffers(1, &verticesVBO2);
+ glBindBuffer(GL_ARRAY_BUFFER, verticesVBO2);
+ glBufferData(GL_ARRAY_BUFFER, 9*sizeof(float), vertices2, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+ shaderProgram = createShaderProgram(vertexShaderSrc, fragmentShaderSrc);
+}
+
+static void drawTriangle(GLuint verticesVBO, unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
+ glUseProgram(shaderProgram);
+ GLuint posLoc = glGetAttribLocation(shaderProgram, "a_position");
+ GLuint mvpLoc = glGetUniformLocation(shaderProgram, "u_mvpMatrix");
+ GLuint colorLoc = glGetUniformLocation(shaderProgram, "u_color");
+
+ GLfloat mvpMat[16];
+ ortho(-WINDOWS_SIZE/2, WINDOWS_SIZE/2, -WINDOWS_SIZE/2, WINDOWS_SIZE/2, -100, 100, mvpMat);
+
+ glUniformMatrix4fv(mvpLoc, 1, GL_FALSE, mvpMat);
+ glUniform4f(colorLoc, r/255.f, g/255.f, b/255.f, a/255.f);
+
+ glBindBuffer(GL_ARRAY_BUFFER, verticesVBO);
+ glEnableVertexAttribArray(posLoc);
+ glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), BUFFER_OFFSET(0));
+
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glUseProgram(0);
+}
+
+// Draw a red triangle on a white background. If antialiasing is disabled, resulting pixels
+// will only have white and red colors. If antialiasing is enabled, there will be pixels
+// whose color is different from red and white.
+static int testAntiAliasing(bool activated) {
+ glViewport(0, 0, WINDOWS_SIZE, WINDOWS_SIZE);
+ glClearColor(backgroundColor[0]/255.f, backgroundColor[1]/255.f, backgroundColor[2]/255.f, backgroundColor[3]/255.f);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ drawTriangle(verticesVBO, triangleColor[0], triangleColor[1], triangleColor[2], triangleColor[3]);
+
+ bool antialiased = false;
+
+ unsigned char buffer[(WINDOWS_SIZE*WINDOWS_SIZE)*4];
+ glReadPixels(0, 0, WINDOWS_SIZE, WINDOWS_SIZE, GL_RGBA, GL_UNSIGNED_BYTE, &buffer[0]);
+ glFinish();
+ for (unsigned int i = 0 ; i < WINDOWS_SIZE ; ++i) {
+ for (unsigned int j = 0 ; j < WINDOWS_SIZE ; ++j) {
+ unsigned char r = buffer[4*(i*WINDOWS_SIZE+j)];
+ unsigned char g = buffer[4*(i*WINDOWS_SIZE+j)+1];
+ unsigned char b = buffer[4*(i*WINDOWS_SIZE+j)+2];
+ unsigned char a = buffer[4*(i*WINDOWS_SIZE+j)+3];
+ if ((r == backgroundColor[0] && g == backgroundColor[1] && b == backgroundColor[2] && a == backgroundColor[3]) ||
+ (r == triangleColor[0] && g == triangleColor[1] && b == triangleColor[2] && a == triangleColor[3])) {
+ continue;
+ } else {
+ antialiased = true;
+ break;
+ }
+ }
+ }
+
+ return (activated && antialiased) || (!activated && !antialiased);
+}
+
+// Draw a red triangle with depth equals to 0 then a green triangle whose depth equals -1.
+// If there is an attached depth buffer, the resulting image will be a red triangle. If not,
+// the resulting image will be a green triangle.
+static int testDepth(bool activated) {
+ glViewport(0, 0, WINDOWS_SIZE, WINDOWS_SIZE);
+ glClearColor(backgroundColor[0]/255.f, backgroundColor[1]/255.f, backgroundColor[2]/255.f, backgroundColor[3]/255.f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LEQUAL);
+
+ drawTriangle(verticesVBO, triangleColor[0], triangleColor[1], triangleColor[2], triangleColor[3]);
+ drawTriangle(verticesVBO2, triangleColor2[0], triangleColor2[1], triangleColor2[2], triangleColor2[3]);
+
+ glDisable(GL_DEPTH_TEST);
+
+ // read the pixel at the center of the resulting image.
+ unsigned char buffer[4];
+ glReadPixels(WINDOWS_SIZE/2, WINDOWS_SIZE/2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &buffer[0]);
+
+ bool frontTriangleColor = (buffer[0] == triangleColor[0] && buffer[1] == triangleColor[1] &&
+ buffer[2] == triangleColor[2] && buffer[3] == triangleColor[3]);
+
+ bool backTriangleColor = (buffer[0] == triangleColor2[0] && buffer[1] == triangleColor2[1] &&
+ buffer[2] == triangleColor2[2] && buffer[3] == triangleColor2[3]);
+
+ return (activated && frontTriangleColor) || (!activated && backTriangleColor);
+}
+
+// The stencil function is set to GL_LEQUAL so fragments will be written to the
+// back buffer only if the ref value is less or equal than the one in the stencil buffer.
+// The content of the stencil buffer is initialized to 0xFF.
+// First draw a red triangle whose stencil ref value is 0x1.
+// Then draw a green triangle whose stencil ref value is 0xFF.
+// If there is an attached stencil buffer, the resulting image will be a red triangle. If not,
+// the resulting image will be a green triangle.
+static int testStencil(bool activated) {
+ glViewport(0, 0, WINDOWS_SIZE, WINDOWS_SIZE);
+ glClearColor(backgroundColor[0]/255.f, backgroundColor[1]/255.f, backgroundColor[2]/255.f, backgroundColor[3]/255.f);
+ glClearStencil(0xFF);
+ glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
+ glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+
+ glEnable(GL_STENCIL_TEST);
+
+ glStencilFunc(GL_LEQUAL, 0x1, 0xFF);
+ drawTriangle(verticesVBO, triangleColor[0], triangleColor[1], triangleColor[2], triangleColor[3]);
+
+ glStencilFunc(GL_LEQUAL, 0xFF, 0xFF);
+ drawTriangle(verticesVBO, triangleColor2[0], triangleColor2[1], triangleColor2[2], triangleColor2[3]);
+
+ glDisable(GL_STENCIL_TEST);
+
+ unsigned char buffer[4];
+ glReadPixels(WINDOWS_SIZE/2, WINDOWS_SIZE/2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &buffer[0]);
+
+ bool firstTriangleColor = (buffer[0] == triangleColor[0] && buffer[1] == triangleColor[1] &&
+ buffer[2] == triangleColor[2] && buffer[3] == triangleColor[3]);
+
+ bool secondTriangleColor = (buffer[0] == triangleColor2[0] && buffer[1] == triangleColor2[1] &&
+ buffer[2] == triangleColor2[2] && buffer[3] == triangleColor2[3]);
+
+ return (activated && firstTriangleColor) || (!activated && secondTriangleColor);
+}
+
+static bool antiAliasingActivated = false;
+static bool depthActivated = false;
+static bool stencilActivated = false;
+
+static int result = 0;
+static int resultAA = 0;
+static int resultDepth = 0;
+static int resultStencil = 0;
+
+static void draw() {
+
+ if (!resultAA) resultAA = testAntiAliasing(antiAliasingActivated);
+
+ if (!resultDepth) resultDepth = testDepth(depthActivated);
+
+ if (!resultStencil) resultStencil = testStencil(stencilActivated);
+
+ result = resultAA && resultDepth && resultStencil;
+
+}
+
+extern int webglAntialiasSupported();
+extern int webglDepthSupported();
+extern int webglStencilSupported();
+
+// Check attributes support in the WebGL implementation (see test_webgl_context_attributes function in test_browser.py)
+// Tests will succeed if they are not.
+static void checkContextAttributesSupport() {
+ if (!webglAntialiasSupported()) {
+ resultAA = 1;
+ EM_ASM(alert('warning: no antialiasing\n'));
+ }
+ if (!webglDepthSupported()) {
+ resultDepth = 1;
+ EM_ASM(alert('warning: no depth\n'));
+ }
+ if (!webglStencilSupported()) {
+ resultStencil = 1;
+ EM_ASM(alert('warning: no stencil\n'));
+ }
+}
+
+
diff --git a/tests/test_webgl_context_attributes_glfw.c b/tests/test_webgl_context_attributes_glfw.c
new file mode 100644
index 00000000..694236d0
--- /dev/null
+++ b/tests/test_webgl_context_attributes_glfw.c
@@ -0,0 +1,47 @@
+#include <GL/glew.h>
+#include <GL/glfw.h>
+#include <emscripten.h>
+
+#include "test_webgl_context_attributes_common.c"
+
+int nbSamples = 0;
+int nbDepthBits = 0;
+int nbStencilBits = 0;
+
+int main() {
+
+ checkContextAttributesSupport();
+
+ glfwInit();
+
+#ifdef AA_ACTIVATED
+ antiAliasingActivated = true;
+ nbSamples = 4;
+#endif
+
+#ifdef DEPTH_ACTIVATED
+ depthActivated = true;
+ nbDepthBits = 16;
+#endif
+
+#ifdef STENCIL_ACTIVATED
+ stencilActivated = true;
+ nbStencilBits = 8;
+#endif
+
+ glfwOpenWindowHint(GLFW_FSAA_SAMPLES, nbSamples);
+ glfwOpenWindow(WINDOWS_SIZE, WINDOWS_SIZE, 8, 8, 8, 8, nbDepthBits, nbStencilBits, GLFW_WINDOW);
+
+ glewInit();
+ initGlObjects();
+
+ draw();
+
+ glfwTerminate();
+
+ REPORT_RESULT();
+
+ return 0;
+
+}
+ \ No newline at end of file
diff --git a/tests/test_webgl_context_attributes_glut.c b/tests/test_webgl_context_attributes_glut.c
new file mode 100644
index 00000000..3255fc9a
--- /dev/null
+++ b/tests/test_webgl_context_attributes_glut.c
@@ -0,0 +1,42 @@
+#include <GL/glew.h>
+#include <GL/glut.h>
+#include <emscripten.h>
+
+#include "test_webgl_context_attributes_common.c"
+
+int main(int argc, char *argv[]) {
+
+ checkContextAttributesSupport();
+
+ unsigned int glutDisplayMode = GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA;
+
+#ifdef AA_ACTIVATED
+ antiAliasingActivated = true;
+ glutDisplayMode |= GLUT_MULTISAMPLE;
+#endif
+
+#ifdef DEPTH_ACTIVATED
+ depthActivated = true;
+ glutDisplayMode |= GLUT_DEPTH;
+#endif
+
+#ifdef STENCIL_ACTIVATED
+ stencilActivated = true;
+ glutDisplayMode |= GLUT_STENCIL;
+#endif
+
+ glutInit(&argc, argv);
+ glutInitWindowSize(WINDOWS_SIZE, WINDOWS_SIZE);
+ glutInitDisplayMode(glutDisplayMode);
+ glutCreateWindow("WebGL");
+ glutDisplayFunc(draw);
+
+ glewInit();
+ initGlObjects();
+
+ draw();
+
+ REPORT_RESULT();
+
+ return 0;
+}
diff --git a/tests/test_webgl_context_attributes_sdl.c b/tests/test_webgl_context_attributes_sdl.c
new file mode 100644
index 00000000..23ad4378
--- /dev/null
+++ b/tests/test_webgl_context_attributes_sdl.c
@@ -0,0 +1,50 @@
+#include <GL/glew.h>
+#define NO_SDL_GLEXT
+#include <SDL/SDL.h>
+#include <SDL/SDL_opengl.h>
+#include <emscripten.h>
+
+#include "test_webgl_context_attributes_common.c"
+
+int main(int argc, char *argv[]) {
+
+ checkContextAttributesSupport();
+
+ SDL_Init(SDL_INIT_VIDEO);
+
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+
+#ifdef AA_ACTIVATED
+ antiAliasingActivated = true;
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
+#else
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
+#endif
+
+#ifdef DEPTH_ACTIVATED
+ depthActivated = true;
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
+#else
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
+#endif
+
+#ifdef STENCIL_ACTIVATED
+ stencilActivated = true;
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
+#else
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
+#endif
+
+ SDL_Surface *screen = SDL_SetVideoMode(WINDOWS_SIZE, WINDOWS_SIZE, 32, SDL_OPENGL);
+
+ glewInit();
+ initGlObjects();
+
+ draw();
+
+ REPORT_RESULT();
+
+ return 0;
+}
diff --git a/tools/file_packager.py b/tools/file_packager.py
index a2349a57..3ba5b23f 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -11,7 +11,7 @@ data downloads.
Usage:
- file_packager.py TARGET [--preload A [B..]] [--embed C [D..]] [--compress COMPRESSION_DATA] [--crunch[=X]] [--js-output=OUTPUT.js] [--no-force]
+ file_packager.py TARGET [--preload A [B..]] [--embed C [D..]] [--compress COMPRESSION_DATA] [--crunch[=X]] [--js-output=OUTPUT.js] [--no-force] [--use-preload-cache] [--no-heap-copy]
--crunch=X Will compress dxt files to crn with quality level X. The crunch commandline tool must be present
and CRUNCH should be defined in ~/.emscripten that points to it. JS crunch decompressing code will
@@ -27,6 +27,10 @@ Usage:
--use-preload-cache Stores package in IndexedDB so that subsequent loads don't need to do XHR. Checks package version.
+ --no-heap-copy If specified, the preloaded filesystem is not copied inside the Emscripten HEAP, but kept in a separate typed array outside it.
+ The default, if this is not specified, is to embed the VFS inside the HEAP, so that mmap()ing files in it is a no-op.
+ Passing this flag optimizes for fread() usage, omitting it optimizes for mmap() usage.
+
Notes:
* The file packager generates unix-style file paths. So if you are on windows and a file is accessed at
@@ -43,7 +47,7 @@ from shared import Compression, execute, suffix, unsuffixed
from subprocess import Popen, PIPE, STDOUT
if len(sys.argv) == 1:
- print '''Usage: file_packager.py TARGET [--preload A...] [--embed B...] [--compress COMPRESSION_DATA] [--crunch[=X]] [--js-output=OUTPUT.js] [--no-force] [--use-preload-cache]
+ print '''Usage: file_packager.py TARGET [--preload A...] [--embed B...] [--compress COMPRESSION_DATA] [--crunch[=X]] [--js-output=OUTPUT.js] [--no-force] [--use-preload-cache] [--no-heap-copy]
See the source for more details.'''
sys.exit(0)
@@ -70,7 +74,12 @@ crunch = 0
plugins = []
jsoutput = None
force = True
+# If set to True, IndexedDB (IDBFS in library_idbfs.js) is used to locally cache VFS XHR so that subsequent
+# page loads can read the data from the offline cache instead.
use_preload_cache = False
+# If set to True, the blob received from XHR is moved to the Emscripten HEAP, optimizing for mmap() performance.
+# If set to False, the XHR blob is kept intact, and fread()s etc. are performed directly to that data. This optimizes for minimal memory usage and fread() performance.
+no_heap_copy = True
for arg in sys.argv[1:]:
if arg == '--preload':
@@ -91,6 +100,8 @@ for arg in sys.argv[1:]:
force = False
elif arg == '--use-preload-cache':
use_preload_cache = True
+ elif arg == '--no-heap-copy':
+ no_heap_copy = False
elif arg.startswith('--js-output'):
jsoutput = arg.split('=')[1] if '=' in arg else None
elif arg.startswith('--crunch'):
@@ -134,6 +145,11 @@ if (not force) and len(data_files) == 0:
ret = '''
var Module;
if (typeof Module === 'undefined') Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()');
+if (!Module.expectedDataFileDownloads) {
+ Module.expectedDataFileDownloads = 0;
+ Module.finishedDataFileDownloads = 0;
+}
+Module.expectedDataFileDownloads++;
(function() {
'''
@@ -338,18 +354,9 @@ if has_preloaded:
send: function() {},
onload: function() {
var byteArray = this.byteArray.subarray(this.start, this.end);
- if (this.crunched) {
- var ddsHeader = byteArray.subarray(0, 128);
- var that = this;
- requestDecrunch(this.name, byteArray.subarray(128), function(ddsData) {
- byteArray = new Uint8Array(ddsHeader.length + ddsData.length);
- byteArray.set(ddsHeader, 0);
- byteArray.set(ddsData, 128);
- that.finish(byteArray);
- });
- } else {
+%s
this.finish(byteArray);
- }
+%s
},
finish: function(byteArray) {
var that = this;
@@ -365,7 +372,20 @@ if has_preloaded:
this.requests[this.name] = null;
},
};
- '''
+ ''' % ('' if not crunch else '''
+ if (this.crunched) {
+ var ddsHeader = byteArray.subarray(0, 128);
+ var that = this;
+ requestDecrunch(this.name, byteArray.subarray(128), function(ddsData) {
+ byteArray = new Uint8Array(ddsHeader.length + ddsData.length);
+ byteArray.set(ddsHeader, 0);
+ byteArray.set(ddsData, 128);
+ that.finish(byteArray);
+ });
+ } else {
+''', '' if not crunch else '''
+ }
+''')
counter = 0
for file_ in data_files:
@@ -405,12 +425,18 @@ for file_ in data_files:
if has_preloaded:
# Get the big archive and split it up
- use_data = '''
+ if no_heap_copy:
+ use_data = '''
// copy the entire loaded file into a spot in the heap. Files will refer to slices in that. They cannot be freed though.
var ptr = Module['_malloc'](byteArray.length);
Module['HEAPU8'].set(byteArray, ptr);
DataRequest.prototype.byteArray = Module['HEAPU8'].subarray(ptr, ptr+byteArray.length);
'''
+ else:
+ use_data = '''
+ // Reuse the bytearray from the XHR as the source for file reads.
+ DataRequest.prototype.byteArray = byteArray;
+'''
for file_ in data_files:
if file_['mode'] == 'preload':
use_data += ' DataRequest.prototype.requests["%s"].onload();\n' % (file_['dstpath'])
@@ -427,12 +453,6 @@ if has_preloaded:
package_uuid = uuid.uuid4();
remote_package_name = os.path.basename(Compression.compressed_name(data_target) if Compression.on else data_target)
code += r'''
- if (!Module.expectedDataFileDownloads) {
- Module.expectedDataFileDownloads = 0;
- Module.finishedDataFileDownloads = 0;
- }
- Module.expectedDataFileDownloads++;
-
var PACKAGE_PATH = window['encodeURIComponent'](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf('/')) + '/');
var PACKAGE_NAME = '%s';
var REMOTE_PACKAGE_NAME = '%s';
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index d6f8921c..dcc9cd5f 100644
--- a/tools/js_optimizer.py
+++ b/tools/js_optimizer.py
@@ -29,13 +29,13 @@ class Minifier:
during registerize perform minification of locals.
'''
- def __init__(self, js, js_engine):
+ def __init__(self, js, js_engine, MAX_NAMES):
self.js = js
self.js_engine = js_engine
+ MAX_NAMES = min(MAX_NAMES, 120000)
# Create list of valid short names
- MAX_NAMES = 80000
INVALID_2 = set(['do', 'if', 'in'])
INVALID_3 = set(['for', 'new', 'try', 'var', 'env', 'let'])
@@ -56,7 +56,6 @@ class Minifier:
if len(self.names) >= MAX_NAMES: break
curr = a + b + c
if curr not in INVALID_3: self.names.append(curr)
- #print >> sys.stderr, self.names
def minify_shell(self, shell, minify_whitespace, source_map=False):
#print >> sys.stderr, "MINIFY SHELL 1111111111", shell, "\n222222222222222"
@@ -187,7 +186,8 @@ EMSCRIPTEN_FUNCS();
''' + js[end_funcs + len(end_funcs_marker):end_asm + len(end_asm_marker)]
js = js[start_funcs + len(start_funcs_marker):end_funcs]
- minifier = Minifier(js, js_engine)
+ # we assume there is a maximum of one new name per line
+ minifier = Minifier(js, js_engine, js.count('\n') + asm_shell.count('\n'))
asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'minifyWhitespace' in passes, source_map).split('EMSCRIPTEN_FUNCS();');
asm_shell_post = asm_shell_post.replace('});', '})');
pre += asm_shell_pre + '\n' + start_funcs_marker
diff --git a/tools/shared.py b/tools/shared.py
index 108a48a4..f6c0cc95 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -284,7 +284,7 @@ def check_node_version():
try:
node = listify(NODE_JS)
actual = Popen(node + ['--version'], stdout=PIPE).communicate()[0].strip()
- version = tuple(map(int, actual.replace('v', '').split('.')))
+ version = tuple(map(int, actual.replace('v', '').replace('-pre', '').split('.')))
if version >= EXPECTED_NODE_VERSION:
return True
logging.warning('node version appears too old (seeing "%s", expected "%s")' % (actual, 'v' + ('.'.join(map(str, EXPECTED_NODE_VERSION)))))