emscripten-core / emscripten-core/emscripten
In threadprofiler.js, need type checking in updateUi function
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
When the flag `--threadprofiler` is used during compilation of the C++ source code, error occurs at runtime in the glue code (the Javascript file, generated by the Emscripten compiler). Emscripten version 2.0.7 is used to compile the code. Following is the stacks-trace.
```
point.js:9794 Uncaught TypeError: Cannot read property 'toString' of undefined
at Object.updateUi (point.js:9794)
at point.js:9780
at wrappedSetInterval (point.js:9743)
```
In v 2.0.7, `threadprofiler.js` has following code snippet.
```
updateUi: function updateUi() {
if (typeof PThread === 'undefined') return; // Likely running threadprofiler on a singlethreaded build, or not initialized yet, ignore updating.
var str = '';
var mainThread = PThread.mainThreadBlock;
var threads = [PThread.mainThreadBlock];
for(var t in PThread.pthreads) threads.push(PThread.pthreads[t].threadInfoStruct);
for(var i = 0; i < threads.length; ++i) {
var threadPtr = threads[i];//(t == PThread.mainThreadBlock ? PThread.mainThreadBlock : maiPThread.pthreads[t].threadInfoStruct;
var profilerBlock = Atomics.load(HEAPU32, (threadPtr + 20 /*C_STRUCTS.pthread.profilerBlock*/ ) >> 2);
var threadName = PThread.getThreadName(threadPtr);
if (threadName) threadName = '"' + threadName + '" (0x' + threadPtr.toString(16) + ')';
else threadName = '(0x' + threadPtr.toString(16) + ')';
str += 'Thread ' + threadName + ' now: ' + PThread.threadStatusAsString(threadPtr) + '. ';
var threadTimesInStatus = [];
.....
```
When the error occurs, `threadptr` is undefined.
Can we have a safety check here which will ensure that `threadptr` or maybe ` PThread.mainThreadBlock` is defined similar to that of `PThread` ?
Contributor guide
Assessment
This issue has not been assessed yet.