diff --git a/src/runtime_debug.js b/src/runtime_debug.js index a30bf4e92765..7637adbb65e9 100644 --- a/src/runtime_debug.js +++ b/src/runtime_debug.js @@ -142,11 +142,11 @@ var MAX_UINT32 = (2 ** 32) - 1; var MAX_UINT53 = (2 ** 53) - 1; var MAX_UINT64 = (2 ** 64) - 1; -var MIN_INT8 = - (2 ** ( 8 - 1)) + 1; -var MIN_INT16 = - (2 ** (16 - 1)) + 1; -var MIN_INT32 = - (2 ** (32 - 1)) + 1; -var MIN_INT53 = - (2 ** (53 - 1)) + 1; -var MIN_INT64 = - (2 ** (64 - 1)) + 1; +var MIN_INT8 = - (2 ** ( 8 - 1)); +var MIN_INT16 = - (2 ** (16 - 1)); +var MIN_INT32 = - (2 ** (32 - 1)); +var MIN_INT53 = - (2 ** (53 - 1)); +var MIN_INT64 = - (2 ** (64 - 1)); function checkInt(value, bits, min, max) { assert(Number.isInteger(Number(value)), `attempt to write non-integer (${value}) into integer heap`); diff --git a/test/core/test_getValue_setValue.cpp b/test/core/test_getValue_setValue.cpp index 483b000f7ef4..c2d68b520d81 100644 --- a/test/core/test_getValue_setValue.cpp +++ b/test/core/test_getValue_setValue.cpp @@ -4,6 +4,7 @@ // found in the LICENSE file. #include +#include int main() { char buffer_char[8] = { 'x' }; @@ -30,6 +31,28 @@ int main() { ptr = Module['getValue']($1, '*'); out('ptr: 0x' + ptr.toString(16) + ' ' + typeof(ptr)); #endif - }, buffer_char, buffer_ptr); + + /* In ASSERTIONS=2 mode we check the limits of input values */ + var min = $2; + var max = $3; + setValue($1, max, 'i8'); + setValue($1, min, 'i8'); +#ifdef ASSERTIONS_2 + function checkAsserts(f, expected) { + try { + f(); + } catch(e) { + assert(e.message.includes(expected), "expected assertion to include:" + expected); + return; + } + assert(false, "expected assertion"); + } + checkAsserts(() => setValue($1, max + 1, 'i8'), "value (256) too large to write as 8-bit value"); + checkAsserts(() => setValue($1, min - 1, 'i8'), "value (-129) too small to write as 8-bit value"); +#else + setValue($1, max + 1, 'i8'); + setValue($1, min - 1, 'i8'); +#endif + }, buffer_char, buffer_ptr, INT8_MIN, UINT8_MAX); } diff --git a/test/test_core.py b/test/test_core.py index e343a573fe93..e6e14b9936be 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -7068,11 +7068,17 @@ def test(args=None, asserts=False): # see that direct usage (not on module) works. we don't export, but the use # keeps it alive through JSDCE test(args=['-DDIRECT']) + + # Test with ASSERTIONS=2 where we check the limits of value passed to setValue. + self.set_setting('ASSERTIONS', 2) + test(args=['-DDIRECT', '-DASSERTIONS_2']) + # see that with assertions, we get a nice error message self.set_setting('EXPORTED_RUNTIME_METHODS', []) self.set_setting('ASSERTIONS') test(asserts=True) self.set_setting('ASSERTIONS', 0) + # see that when we export them, things work on the module self.set_setting('EXPORTED_RUNTIME_METHODS', ['getValue', 'setValue']) test()