diff --git a/public/main.js b/public/main.js index a5f54e5..d136d6d 100644 --- a/public/main.js +++ b/public/main.js @@ -294,10 +294,12 @@ function enter_matrix() { try { entries = JSON.parse(atob(matrix)) - assert(Array.isArray(entries)) - assert(entries.length == 2 * dim * dim) + if (!Array.isArray(entries)) { throw new Error("Bad object") } + if (entries.length != 2 * dim * dim) { throw new Error("Bad length") } for (let i = 0; i < 2 * dim * dim; i++) { - assert(!isNaN(entries[i]) && -3 < entries[i] && entries[i] < 3) + if (isNaN(entries[i]) || -3 > entries[i] || entries[i] > 3) { + throw new Error("Bad entries") + } } matrix_entries = entries @@ -358,10 +360,10 @@ function input_update(e) { const i = row * dim * 2 + col * 2; try { let [real, imag] = input.value.split('+'); - real = Number(real); - imag = Number(imag.replace(/i$/, '')); - assert(!isNaN(real) && -3 < real && real < 3); - assert(!isNaN(imag) && -3 < imag && imag < 3); + real = Number(real) + imag = Number(imag.replace(/i$/, '')) + if (isNaN(real) || -3 > real || real > 3) { throw new Error("Bad real part") } + if (isNaN(imag) || -3 > imag || imag > 3) { throw new Error("Bad imaginary part") } matrix_entries[i] = real; matrix_entries[i+1] = imag; p_draw()