Reject timeout values that are too large for setTimeout

See #1930
This commit is contained in:
Steve Gravrock
2021-09-25 15:43:31 -07:00
parent 7fc3408051
commit c3fb3e985a
6 changed files with 189 additions and 2 deletions

View File

@@ -142,5 +142,20 @@ getJasmineRequireObj().util = function(j$) {
}
};
util.validateTimeout = function(timeout, msgPrefix) {
// Timeouts are implemented with setTimeout, which only supports a limited
// range of values. The limit is unspecified, as is the behavior when it's
// exceeded. But on all currently supported JS runtimes, setTimeout calls
// the callback immediately when the timeout is greater than 2147483647
// (the maximum value of a signed 32 bit integer).
var max = 2147483647;
if (timeout > max) {
throw new Error(
(msgPrefix || 'Timeout value') + ' cannot be greater than ' + max
);
}
};
return util;
};