Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminate unterminated statements + fix some type coercion #9019

Merged
merged 11 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -2000,8 +2000,8 @@ def create_asm_start_pre(asm_setup, the_global, sending, metadata):
if shared.Settings.USE_PTHREADS and not shared.Settings.WASM:
shared_array_buffer = "asmGlobalArg['Atomics'] = Atomics;"

module_global = 'var asmGlobalArg = ' + the_global
module_library = 'var asmLibraryArg = ' + sending
module_global = 'var asmGlobalArg = ' + the_global + ';'
module_library = 'var asmLibraryArg = ' + sending + ';'

asm_function_top = ('// EMSCRIPTEN_START_ASM\n'
'var asm = (/** @suppress {uselessCode} */ function(global, env, buffer) {')
Expand Down
14 changes: 7 additions & 7 deletions src/Fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,10 @@ function __emscripten_fetch_xhr(fetch, onsuccess, onerror, onprogress, onreadyst
#endif
if (onerror) onerror(fetch, xhr, e);
}
}
};
xhr.onerror = function(e) {
var status = xhr.status; // XXX TODO: Overwriting xhr.status doesn't work here, so don't override anywhere else either.
if (xhr.readyState == 4 && status == 0) status = 404; // If no error recorded, pretend it was 404 Not Found.
if (xhr.readyState === 4 && status === 0) status = 404; // If no error recorded, pretend it was 404 Not Found.
#if FETCH_DEBUG
console.error('fetch: xhr of URL "' + xhr.url_ + '" / responseURL "' + xhr.responseURL + '" finished with error, readyState ' + xhr.readyState + ' and status ' + status);
#endif
Expand All @@ -410,13 +410,13 @@ function __emscripten_fetch_xhr(fetch, onsuccess, onerror, onprogress, onreadyst
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.readyState }}} >> 1] = xhr.readyState;
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = status;
if (onerror) onerror(fetch, xhr, e);
}
};
xhr.ontimeout = function(e) {
#if FETCH_DEBUG
console.error('fetch: xhr of URL "' + xhr.url_ + '" / responseURL "' + xhr.responseURL + '" timed out, readyState ' + xhr.readyState + ' and status ' + xhr.status);
#endif
if (onerror) onerror(fetch, xhr, e);
}
};
xhr.onprogress = function(e) {
var ptrLen = (fetchAttrLoadToMemory && fetchAttrStreamData && xhr.response) ? xhr.response.byteLength : 0;
var ptr = 0;
Expand All @@ -438,14 +438,14 @@ function __emscripten_fetch_xhr(fetch, onsuccess, onerror, onprogress, onreadyst
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = xhr.status;
if (xhr.statusText) stringToUTF8(xhr.statusText, fetch + {{{ C_STRUCTS.emscripten_fetch_t.statusText }}}, 64);
if (onprogress) onprogress(fetch, xhr, e);
}
};
xhr.onreadystatechange = function(e) {
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.readyState }}} >> 1] = xhr.readyState;
if (xhr.readyState >= 2) {
HEAPU16[fetch + {{{ C_STRUCTS.emscripten_fetch_t.status }}} >> 1] = xhr.status;
}
if (onreadystatechange) onreadystatechange(fetch, xhr, e);
}
};
#if FETCH_DEBUG
console.log('fetch: xhr.send(data=' + data + ')');
#endif
Expand Down Expand Up @@ -505,7 +505,7 @@ function emscripten_start_fetch(fetch, successcb, errorcb, progresscb, readystat
#endif
if (onreadystatechange) {{{ makeDynCall('vi') }}}(onreadystatechange, fetch);
else if (readystatechangecb) readystatechangecb(fetch);
}
};

var performUncachedXhr = function(fetch, xhr, e) {
#if FETCH_DEBUG
Expand Down
12 changes: 6 additions & 6 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2361,16 +2361,16 @@ LibraryManager.library = {
str = character[0]+str;
}
return str;
};
}

function leadingNulls(value, digits) {
return leadingSomething(value, digits, '0');
};
}

function compareByDay(date1, date2) {
function sgn(value) {
return value < 0 ? -1 : (value > 0 ? 1 : 0);
};
}

var compare;
if ((compare = sgn(date1.getFullYear()-date2.getFullYear())) === 0) {
Expand All @@ -2379,7 +2379,7 @@ LibraryManager.library = {
}
}
return compare;
};
}

function getFirstWeekStartDate(janFourth) {
switch (janFourth.getDay()) {
Expand All @@ -2398,7 +2398,7 @@ LibraryManager.library = {
case 6: // Saturday
return new Date(janFourth.getFullYear()-1, 11, 30);
}
};
}

function getWeekBasedYear(date) {
var thisDate = __addDays(new Date(date.tm_year+1900, 0, 1), date.tm_yday);
Expand All @@ -2419,7 +2419,7 @@ LibraryManager.library = {
} else {
return thisDate.getFullYear()-1;
}
};
}

var EXPANSION_RULES_2 = {
'%a': function(date) {
Expand Down
2 changes: 1 addition & 1 deletion src/library_exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var LibraryExceptions = {
ptr = ___exception_deAdjust(ptr);
if (!___exception_infos[ptr].rethrown) {
// Only pop if the corresponding push was through rethrow_primary_exception
___exception_caught.push(ptr)
___exception_caught.push(ptr);
___exception_infos[ptr].rethrown = true;
}
#if EXCEPTION_DEBUG
Expand Down
6 changes: 3 additions & 3 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1700,10 +1700,10 @@ mergeInto(LibraryManager.library, {
var chunkOffset = idx % this.chunkSize;
var chunkNum = (idx / this.chunkSize)|0;
return this.getter(chunkNum)[chunkOffset];
}
};
LazyUint8Array.prototype.setDataGetter = function LazyUint8Array_setDataGetter(getter) {
this.getter = getter;
}
};
LazyUint8Array.prototype.cacheLength = function LazyUint8Array_cacheLength() {
// Find length
var xhr = new XMLHttpRequest();
Expand Down Expand Up @@ -1770,7 +1770,7 @@ mergeInto(LibraryManager.library, {
this._length = datalength;
this._chunkSize = chunkSize;
this.lengthKnown = true;
}
};
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';
var lazyArray = new LazyUint8Array();
Expand Down
2 changes: 1 addition & 1 deletion src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ var LibraryJSEvents = {
JSEvents.runDeferredCalls();
// Out of event handler - restore nesting count.
--JSEvents.inEventHandler;
}
};

if (eventHandler.callbackfunc) {
eventHandler.eventListenerFunc = jsEventHandler;
Expand Down
2 changes: 1 addition & 1 deletion src/library_memfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ mergeInto(LibraryManager.library, {
delete parent.contents[name];
},
readdir: function(node) {
var entries = ['.', '..']
var entries = ['.', '..'];
for (var key in node.contents) {
if (!node.contents.hasOwnProperty(key)) {
continue;
Expand Down
24 changes: 12 additions & 12 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ var LibraryPThread = {

// Synchronously proxy the thread creation to main thread if possible. If we need to transfer ownership of objects, then
// proxy asynchronously via postMessage.
if (ENVIRONMENT_IS_PTHREAD && (transferList.length == 0 || error)) {
if (ENVIRONMENT_IS_PTHREAD && (transferList.length === 0 || error)) {
return _emscripten_sync_run_in_main_thread_4({{{ cDefine('EM_PROXIED_PTHREAD_CREATE') }}}, pthread_ptr, attr, start_routine, arg);
}

Expand All @@ -615,8 +615,8 @@ var LibraryPThread = {
// the pthread API. When reading the structure directly on JS side however, we need to offset the size manually here.
stackSize += 81920 /*DEFAULT_STACK_SIZE*/;
stackBase = {{{ makeGetValue('attr', 8, 'i32') }}};
detached = {{{ makeGetValue('attr', 12/*_a_detach*/, 'i32') }}} != 0/*PTHREAD_CREATE_JOINABLE*/;
var inheritSched = {{{ makeGetValue('attr', 16/*_a_sched*/, 'i32') }}} == 0/*PTHREAD_INHERIT_SCHED*/;
detached = {{{ makeGetValue('attr', 12/*_a_detach*/, 'i32') }}} !== 0/*PTHREAD_CREATE_JOINABLE*/;
var inheritSched = {{{ makeGetValue('attr', 16/*_a_sched*/, 'i32') }}} === 0/*PTHREAD_INHERIT_SCHED*/;
if (inheritSched) {
var prevSchedPolicy = {{{ makeGetValue('attr', 20/*_a_policy*/, 'i32') }}};
var prevSchedPrio = {{{ makeGetValue('attr', 24/*_a_prio*/, 'i32') }}};
Expand Down Expand Up @@ -724,7 +724,7 @@ var LibraryPThread = {
return ERRNO_CODES.EDEADLK;
}
var self = {{{ makeGetValue('thread', C_STRUCTS.pthread.self, 'i32') }}};
if (self != thread) {
if (self !== thread) {
err('pthread_join attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!');
return ERRNO_CODES.ESRCH;
}
Expand Down Expand Up @@ -758,7 +758,7 @@ var LibraryPThread = {
pthread_kill__deps: ['_kill_thread'],
pthread_kill: function(thread, signal) {
if (signal < 0 || signal >= 65/*_NSIG*/) return ERRNO_CODES.EINVAL;
if (thread == PThread.MAIN_THREAD_ID) {
if (thread === PThread.MAIN_THREAD_ID) {
if (signal == 0) return 0; // signal == 0 is a no-op.
err('Main thread (id=' + thread + ') cannot be killed with pthread_kill!');
return ERRNO_CODES.ESRCH;
Expand All @@ -768,7 +768,7 @@ var LibraryPThread = {
return ERRNO_CODES.ESRCH;
}
var self = {{{ makeGetValue('thread', C_STRUCTS.pthread.self, 'i32') }}};
if (self != thread) {
if (self !== thread) {
err('pthread_kill attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!');
return ERRNO_CODES.ESRCH;
}
Expand All @@ -781,7 +781,7 @@ var LibraryPThread = {

pthread_cancel__deps: ['_cancel_thread'],
pthread_cancel: function(thread) {
if (thread == PThread.MAIN_THREAD_ID) {
if (thread === PThread.MAIN_THREAD_ID) {
err('Main thread (id=' + thread + ') cannot be canceled!');
return ERRNO_CODES.ESRCH;
}
Expand All @@ -790,7 +790,7 @@ var LibraryPThread = {
return ERRNO_CODES.ESRCH;
}
var self = {{{ makeGetValue('thread', C_STRUCTS.pthread.self, 'i32') }}};
if (self != thread) {
if (self !== thread) {
err('pthread_cancel attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!');
return ERRNO_CODES.ESRCH;
}
Expand All @@ -806,7 +806,7 @@ var LibraryPThread = {
return ERRNO_CODES.ESRCH;
}
var self = {{{ makeGetValue('thread', C_STRUCTS.pthread.self, 'i32') }}};
if (self != thread) {
if (self !== thread) {
err('pthread_detach attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!');
return ERRNO_CODES.ESRCH;
}
Expand Down Expand Up @@ -873,7 +873,7 @@ var LibraryPThread = {
return ERRNO_CODES.ESRCH;
}
var self = {{{ makeGetValue('thread', C_STRUCTS.pthread.self, 'i32') }}};
if (self != thread) {
if (self !== thread) {
err('pthread_getschedparam attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!');
return ERRNO_CODES.ESRCH;
}
Expand All @@ -892,7 +892,7 @@ var LibraryPThread = {
return ERRNO_CODES.ESRCH;
}
var self = {{{ makeGetValue('thread', C_STRUCTS.pthread.self, 'i32') }}};
if (self != thread) {
if (self !== thread) {
err('pthread_setschedparam attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!');
return ERRNO_CODES.ESRCH;
}
Expand Down Expand Up @@ -944,7 +944,7 @@ var LibraryPThread = {
return ERRNO_CODES.ESRCH;
}
var self = {{{ makeGetValue('thread', C_STRUCTS.pthread.self, 'i32') }}};
if (self != thread) {
if (self !== thread) {
err('pthread_setschedprio attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!');
return ERRNO_CODES.ESRCH;
}
Expand Down
6 changes: 3 additions & 3 deletions src/library_syscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ var SyscallsLibrary = {
#endif
],
_emscripten_syscall_munmap: function(addr, len) {
if (addr == {{{ cDefine('MAP_FAILED') }}} || len == 0) {
if (addr === {{{ cDefine('MAP_FAILED') }}} || len === 0) {
return -{{{ cDefine('EINVAL') }}};
}
// TODO: support unmmap'ing parts of allocations
var info = SYSCALLS.mappings[addr];
if (!info) return 0;
if (len === info.len) {
var stream = FS.getStream(info.fd);
SYSCALLS.doMsync(addr, stream, len, info.flags)
SYSCALLS.doMsync(addr, stream, len, info.flags);
FS.munmap(stream);
SYSCALLS.mappings[addr] = null;
if (info.allocated) {
Expand Down Expand Up @@ -300,7 +300,7 @@ var SyscallsLibrary = {
#endif // SYSCALLS_REQUIRE_FILESYSTEM
},
__syscall5: function(which, varargs) { // open
var pathname = SYSCALLS.getStr(), flags = SYSCALLS.get(), mode = SYSCALLS.get() // optional TODO
var pathname = SYSCALLS.getStr(), flags = SYSCALLS.get(), mode = SYSCALLS.get(); // optional TODO
var stream = FS.open(pathname, flags, mode);
return stream.fd;
},
Expand Down
10 changes: 5 additions & 5 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ if (memoryInitializer) {
// its .status field can still be accessed later.
if (Module['memoryInitializerRequest']) delete Module['memoryInitializerRequest'].response;
removeRunDependency('memory initializer');
}
};
var doBrowserLoad = function() {
Module['readAsync'](memoryInitializer, applyMemoryInitializer, function() {
throw 'could not load memory initializer ' + memoryInitializer;
});
}
};
#if SUPPORT_BASE64_EMBEDDING
var memoryInitializerBytes = tryParseAsDataURI(memoryInitializer);
if (memoryInitializerBytes) {
Expand Down Expand Up @@ -95,7 +95,7 @@ if (memoryInitializer) {
#endif
}
applyMemoryInitializer(response);
}
};
if (Module['memoryInitializerRequest'].response) {
setTimeout(useRequest, 0); // it's already here; but, apply it asynchronously
} else {
Expand Down Expand Up @@ -150,7 +150,7 @@ function ExitStatus(status) {
this.name = "ExitStatus";
this.message = "Program terminated with exit(" + status + ")";
this.status = status;
};
}
ExitStatus.prototype = new Error();
ExitStatus.prototype.constructor = ExitStatus;

Expand All @@ -160,7 +160,7 @@ dependenciesFulfilled = function runCaller() {
// If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
if (!Module['calledRun']) run();
if (!Module['calledRun']) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
}
};

#if HAS_MAIN
Module['callMain'] = function callMain(args) {
Expand Down
4 changes: 2 additions & 2 deletions src/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,11 +922,11 @@ var tempRet0 = 0;

var setTempRet0 = function(value) {
tempRet0 = value;
}
};

var getTempRet0 = function() {
return tempRet0;
}
};

#if RETAIN_COMPILER_SETTINGS
var compilerSettings = {{{ JSON.stringify(makeRetainedCompilerSettings()) }}} ;
Expand Down