JSFiddle - React, Tailwind, and code Playground
by davidmurdoch
HTML
<script src="http://modernizr.com/downloads/modernizr.js"></script>
<script src="https://raw.github.com/jtobey/javascript-bignum/master/biginteger.js"></script>
<script src="https://raw.github.com/jtobey/javascript-bignum/master/schemeNumber.js"></script>
<p>This test could crash your browser. You've been warned.</p>
<button id="start">Start</button>
<span id="counter"></span>
<ul id="log">
</ul>
JavaScript
if (!Modernizr.inputtypes.number) {
alert("Your browser doesn't support input[type=number]. Go away.");
return;
}
var log = $("#log"),
// javascript's max value
max = BigInteger(Number.MAX_VALUE),
// arbitrary test number that should work everywhere.
start = BigInteger(9007199254000000),
i = BigInteger(start),
input = $('<input type="number" value="0" min="0" max="0">')[0],
btn = $("#start"),
running = false,
counter = document.getElementById("counter");
if (!input.validity) {
alert("Your browser does not provide and API to check the input element's validity.");
return;
}
//log.append("<li>Max Value: " + max.toString() + "</li>");
//log.append("<li>i: " + i.toString() + "</li>");
btn.click(function(e) {
e.preventDefault();
if (!running) {
running = true;
this.innerHTML = "Pause";
setTimeout(test, 10);
}
else {
running = false;
this.innerHTML = "Resume";
}
});
function test() {
var count = 0;
// loop while i is less than max
while (running && i.compare(max) === -1) {
count++;
i = i.next();
input.max = i.toString(10);
input.value = i.next().toString(10);
// Use the input element's "validity" property to check if the engine thinks the value we just set is valid (it isn't).
if (input.validity.valid) {
if (i.prev().compare(start) === 0) {
log.append("<li>Start value is too high for testing. Lower value and try again. " + start + "</li>");
}
else {
log.append("<li><code>input.value</code> is greater than <code>input.max</code> and <code>valid</code> when input.max is <b>" + input.max + "</b></li>");
i = max;
}
break;
}
// give the user a chance to cancel
if (count >= 100000) {
counter.innerHTML = i.toString();
setTimeout(test, 10);
...