From 7dc42c34c6896195d08c79e562d9233f2d8d01b2 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 27 Feb 2012 23:10:40 -0500 Subject: [PATCH] correcting the typechecks on the fast-path math --- js-assembler/runtime-src/runtime.js | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/js-assembler/runtime-src/runtime.js b/js-assembler/runtime-src/runtime.js index 15ec29d..fcc4c38 100644 --- a/js-assembler/runtime-src/runtime.js +++ b/js-assembler/runtime-src/runtime.js @@ -847,6 +847,12 @@ } return sum; } else { + if (! isNumber(x)) { + raiseArgumentTypeError(M, '+', 'number', 0, x); + } + if (! isNumber(y)) { + raiseArgumentTypeError(M, '+', 'number', 1, y); + } return plt.baselib.numbers.add(x, y); } } @@ -888,6 +894,12 @@ } return prod; } else { + if (! isNumber(x)) { + raiseArgumentTypeError(M, '*', 'number', 0, x); + } + if (! isNumber(y)) { + raiseArgumentTypeError(M, '*', 'number', 1, y); + } return plt.baselib.numbers.multiply(x, y); } } @@ -934,6 +946,12 @@ } return sum; } else { + if (! isNumber(x)) { + raiseArgumentTypeError(M, '-', 'number', 0, x); + } + if (! isNumber(y)) { + raiseArgumentTypeError(M, '-', 'number', 1, y); + } return plt.baselib.numbers.subtract(x, y); } } @@ -961,6 +979,12 @@ if (typeof(x) === 'number' && typeof(y) === 'number') { return x > y; } else { + if (! isNumber(x)) { + raiseArgumentTypeError(M, '>', 'number', 0, x); + } + if (! isNumber(y)) { + raiseArgumentTypeError(M, '>', 'number', 1, y); + } return plt.baselib.numbers.greaterThan(x, y); } } @@ -993,6 +1017,12 @@ if (typeof(x) === 'number' && typeof(y) === 'number') { return x === y; } else { + if (! isNumber(x)) { + raiseArgumentTypeError(M, '=', 'number', 0, x); + } + if (! isNumber(y)) { + raiseArgumentTypeError(M, '=', 'number', 1, y); + } return plt.baselib.numbers.equals(x, y); } }