diff --git a/js/src/jsnum.cpp b/js/src/jsnum.cpp index 462d7cceb52..b967b44d946 100644 --- a/js/src/jsnum.cpp +++ b/js/src/jsnum.cpp @@ -459,8 +459,6 @@ js::num_parseInt(JSContext *cx, unsigned argc, Value *vp) static const JSFunctionSpec number_functions[] = { 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 }; @@ -1029,8 +1027,6 @@ static const JSFunctionSpec number_static_methods[] = { JS_FN("isInteger", Number_isInteger, 1, 0), JS_SELF_HOSTED_FN("isNaN", "Number_isNaN", 1,0), JS_SELF_HOSTED_FN("isSafeInteger", "Number_isSafeInteger", 1,0), - JS_FN("parseFloat", num_parseFloat, 1, 0), - JS_FN("parseInt", num_parseInt, 2, 0), JS_FS_END }; @@ -1201,6 +1197,24 @@ js_InitNumberClass(JSContext *cx, HandleObject obj) if (!JS_DefineFunctions(cx, global, number_functions)) return nullptr; + /* Number.parseInt should be the same function object as global parseInt. */ + RootedId parseIntId(cx, NameToId(cx->names().parseInt)); + JSFunction *parseInt = DefineFunction(cx, global, parseIntId, num_parseInt, 2, 0); + if(!parseInt) + return nullptr; + RootedValue parseIntValue(cx, ObjectValue(*parseInt)); + if(!DefineProperty(cx, ctor, parseIntId, parseIntValue, nullptr, nullptr, 0)) + return nullptr; + + /* Number.parseFloat should be the same function object as global parseFloat. */ + RootedId parseFloatId(cx, NameToId(cx->names().parseFloat)); + JSFunction *parseFloat = DefineFunction(cx, global, parseFloatId, num_parseFloat, 1, 0); + if(!parseFloat) + return nullptr; + RootedValue parseFloatValue(cx, ObjectValue(*parseFloat)); + if(!DefineProperty(cx, ctor, parseFloatId, parseFloatValue, nullptr, nullptr, 0)) + return nullptr; + RootedValue valueNaN(cx, cx->runtime()->NaNValue); RootedValue valueInfinity(cx, cx->runtime()->positiveInfinityValue); diff --git a/js/src/tests/ecma_6/Number/parseFloat-01.js b/js/src/tests/ecma_6/Number/parseFloat-01.js index b870f93f462..8c57e4e1295 100644 --- a/js/src/tests/ecma_6/Number/parseFloat-01.js +++ b/js/src/tests/ecma_6/Number/parseFloat-01.js @@ -18,6 +18,9 @@ assertEq(Number.parseFloat("infinity"), NaN); assertEq(Number.parseFloat("nan"), NaN); assertEq(Number.parseFloat("NaN"), NaN); +/* Number.parseFloat should be the same function object as global parseFloat. */ +assertEq(Number.parseFloat, parseFloat); + if (typeof reportCompare === "function") reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Number/parseInt-01.js b/js/src/tests/ecma_6/Number/parseInt-01.js index 7ffd26e2d14..20bda187261 100644 --- a/js/src/tests/ecma_6/Number/parseInt-01.js +++ b/js/src/tests/ecma_6/Number/parseInt-01.js @@ -161,6 +161,8 @@ assertEq(Number.parseInt("A", 17), 10); assertEq(Number.parseInt("0A", 17), 10); assertEq(Number.parseInt("00A", 17), 10); +/* Number.parseInt should be the same function object as global parseInt. */ +assertEq(Number.parseInt, parseInt); /******************************************************************************/