aboutsummaryrefslogtreecommitdiff
path: root/src/preamble.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/preamble.js')
-rw-r--r--src/preamble.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/preamble.js b/src/preamble.js
index c895231f..a4e685d0 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -75,6 +75,14 @@ function __Z18UNPROTECT_HEAPADDRPv(dest) {
//==========================================
#endif
+#if CHECK_OVERFLOWS
+function CHECK_OVERFLOW(value, bits) {
+ assert(value !== Infinity && value !== -Infinity, 'Infinity!');
+ assert(Math.abs(value) < Math.pow(2, bits-1), 'Overflow!');
+ return value;
+}
+#endif
+
#if LABEL_DEBUG
var INDENT = '';
#endif
@@ -87,12 +95,15 @@ var ABORT = false;
var undef = 0;
+function abort(text) {
+ print(text + ':\n' + (new Error).stack);
+ ABORT = true;
+ throw "Assertion: " + text;
+}
+
function assert(condition, text) {
if (!condition) {
- var text = "Assertion failed: " + text;
- print(text + ':\n' + (new Error).stack);
- ABORT = true;
- throw "Assertion: " + text;
+ abort('Assertion failed: ' + text);
}
}