From 82d6edcee677d77f3e384f963957ccd76da7f9a7 Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Sat, 23 Aug 2014 20:42:05 +0530 Subject: [PATCH] Bug 1021963 - Self host isNaN and isFinite. r=jwalden --HG-- extra : rebase_source : 263a62a38ddfa782ece8d0217dc973d66a98e92b --- js/src/builtin/Date.js | 6 +++--- js/src/builtin/Intl.js | 2 +- js/src/builtin/Number.js | 10 +++++++++- js/src/builtin/String.js | 2 +- js/src/builtin/Utilities.js | 2 -- js/src/jsnum.cpp | 40 ++----------------------------------- 6 files changed, 16 insertions(+), 46 deletions(-) diff --git a/js/src/builtin/Date.js b/js/src/builtin/Date.js index d14e8509067..5bd8575c21d 100644 --- a/js/src/builtin/Date.js +++ b/js/src/builtin/Date.js @@ -18,7 +18,7 @@ var dateTimeFormatCache = new Record(); function Date_toLocaleString() { // Steps 1-2. Note that valueOf enforces "this time value" restrictions. var x = callFunction(std_Date_valueOf, this); - if (std_isNaN(x)) + if (Number_isNaN(x)) return "Invalid Date"; // Steps 3-4. @@ -55,7 +55,7 @@ function Date_toLocaleString() { function Date_toLocaleDateString() { // Steps 1-2. Note that valueOf enforces "this time value" restrictions. var x = callFunction(std_Date_valueOf, this); - if (std_isNaN(x)) + if (Number_isNaN(x)) return "Invalid Date"; // Steps 3-4. @@ -92,7 +92,7 @@ function Date_toLocaleDateString() { function Date_toLocaleTimeString() { // Steps 1-2. Note that valueOf enforces "this time value" restrictions. var x = callFunction(std_Date_valueOf, this); - if (std_isNaN(x)) + if (Number_isNaN(x)) return "Invalid Date"; // Steps 3-4. diff --git a/js/src/builtin/Intl.js b/js/src/builtin/Intl.js index 87943a239c0..aef7e86973d 100644 --- a/js/src/builtin/Intl.js +++ b/js/src/builtin/Intl.js @@ -878,7 +878,7 @@ function GetNumberOption(options, property, minimum, maximum, fallback) { // Step 2. if (value !== undefined) { value = ToNumber(value); - if (std_isNaN(value) || value < minimum || value > maximum) + if (Number_isNaN(value) || value < minimum || value > maximum) ThrowError(JSMSG_INVALID_DIGITS_VALUE, value); return std_Math_floor(value); } diff --git a/js/src/builtin/Number.js b/js/src/builtin/Number.js index 918e129d319..07b2be57abe 100644 --- a/js/src/builtin/Number.js +++ b/js/src/builtin/Number.js @@ -60,7 +60,7 @@ function Number_isSafeInteger(number) { return false; // Step 2. - if (!std_isFinite(number)) + if (!Number_isFinite(number)) return false; // Step 3. @@ -77,3 +77,11 @@ function Number_isSafeInteger(number) { // Step 6. return false; } + +function Global_isNaN(number) { + return Number_isNaN(ToNumber(number)); +} + +function Global_isFinite(number){ + return Number_isFinite(ToNumber(number)); +} diff --git a/js/src/builtin/String.js b/js/src/builtin/String.js index 3d34308c092..762a4b15352 100644 --- a/js/src/builtin/String.js +++ b/js/src/builtin/String.js @@ -165,7 +165,7 @@ function String_static_fromCodePoint() { var nextCP = ToNumber(next); // Step 5d. - if (nextCP !== ToInteger(nextCP) || std_isNaN(nextCP)) + if (nextCP !== ToInteger(nextCP) || Number_isNaN(nextCP)) ThrowError(JSMSG_NOT_A_CODEPOINT, ToString(nextCP)); // Step 5e. diff --git a/js/src/builtin/Utilities.js b/js/src/builtin/Utilities.js index 22938172d26..fae2a5b6865 100644 --- a/js/src/builtin/Utilities.js +++ b/js/src/builtin/Utilities.js @@ -35,8 +35,6 @@ Object.defineProperty = null; // See bug 988416. // Object) below. Setting `var std_Array = Array;`, for instance, would cause // the entire Array constructor, including its prototype and methods, to be // cloned into content compartments. -var std_isFinite = isFinite; -var std_isNaN = isNaN; var std_Array_indexOf = ArrayIndexOf; var std_Array_iterator = Array.prototype.iterator; var std_Array_join = Array.prototype.join; diff --git a/js/src/jsnum.cpp b/js/src/jsnum.cpp index 2745388de73..0ed1ed09af1 100644 --- a/js/src/jsnum.cpp +++ b/js/src/jsnum.cpp @@ -280,42 +280,6 @@ js::GetDecimalInteger(ExclusiveContext *cx, const jschar *start, const jschar *e return ComputeAccurateDecimalInteger(cx, start, s, dp); } -static bool -num_isNaN(JSContext *cx, unsigned argc, Value *vp) -{ - CallArgs args = CallArgsFromVp(argc, vp); - - if (args.length() == 0) { - args.rval().setBoolean(true); - return true; - } - - double x; - if (!ToNumber(cx, args[0], &x)) - return false; - - args.rval().setBoolean(mozilla::IsNaN(x)); - return true; -} - -static bool -num_isFinite(JSContext *cx, unsigned argc, Value *vp) -{ - CallArgs args = CallArgsFromVp(argc, vp); - - if (args.length() == 0) { - args.rval().setBoolean(false); - return true; - } - - double x; - if (!ToNumber(cx, args[0], &x)) - return false; - - args.rval().setBoolean(mozilla::IsFinite(x)); - return true; -} - static bool num_parseFloat(JSContext *cx, unsigned argc, Value *vp) { @@ -489,8 +453,8 @@ js::num_parseInt(JSContext *cx, unsigned argc, Value *vp) } static const JSFunctionSpec number_functions[] = { - JS_FN(js_isNaN_str, num_isNaN, 1,0), - JS_FN(js_isFinite_str, num_isFinite, 1,0), + JS_SELF_HOSTED_FN(js_isNaN_str, "Global_isNaN", 1,0), + JS_SELF_HOSTED_FN(js_isFinite_str, "Global_isFinite", 1,0), JS_FN(js_parseFloat_str, num_parseFloat, 1,0), JS_FN(js_parseInt_str, num_parseInt, 2,0), JS_FS_END