Skip to content

Commit 951464d

Browse files
committed
Print more descriptive error messages on some assert failures
1 parent 1655d72 commit 951464d

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/parseTools.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ function preprocess(text, filenameHint) {
5454
ret += '\n' + preprocess(included, filename) + '\n'
5555
}
5656
} else if (line[2] == 'l') { // else
57-
assert(showStack.length > 0);
57+
assert(showStack.length > 0, 'preprocessing error parsing #else on line ' + i + ': ' + line);
5858
showStack.push(!showStack.pop());
5959
} else if (line[2] == 'n') { // endif
60-
assert(showStack.length > 0);
60+
assert(showStack.length > 0, 'preprocessing error parsing #endif on line ' + i + ': ' + line);
6161
showStack.pop();
6262
} else {
63-
throw "Unclear preprocessor command: " + line;
63+
throw "Unclear preprocessor command on line " + i + ': ' + line;
6464
}
6565
}
6666
} catch(e) {
6767
printErr('parseTools.js preprocessor error in ' + filenameHint + ':' + (i+1) + ': \"' + line + '\"!');
6868
throw e;
6969
}
7070
}
71-
assert(showStack.length == 0);
71+
assert(showStack.length == 0, 'preprocessing error in file '+ filenameHint + ', no matching #endif found (' + showStack.length + ' unmatched preprocessing directives on stack)');
7272
return ret;
7373
}
7474

src/runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function getNativeTypeSize(type) {
3333
return 4; // A pointer
3434
} else if (type[0] === 'i') {
3535
var bits = parseInt(type.substr(1));
36-
assert(bits % 8 === 0);
36+
assert(bits % 8 === 0, 'getNativeTypeSize invalid bits ' + bits + ', type ' + type);
3737
return bits / 8;
3838
} else {
3939
return 0;

src/support.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ function loadWebAssemblyModule(binary, flags) {
359359
tableAlign = Math.pow(2, tableAlign);
360360
// finalize alignments and verify them
361361
memoryAlign = Math.max(memoryAlign, STACK_ALIGN); // we at least need stack alignment
362-
assert(tableAlign === 1);
362+
#if ASSERTIONS
363+
assert(tableAlign === 1, 'invalid tableAlign ' + tableAlign);
364+
#endif
363365
// prepare memory
364366
var memoryBase = alignMemory(getMemory(memorySize + memoryAlign), memoryAlign); // TODO: add to cleanups
365367
// The static area consists of explicitly initialized data, followed by zero-initialized data.

0 commit comments

Comments
 (0)