Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1091)

Unified Diff: src/v8natives.js

Issue 124573002: Upgrade Number constructor to ES6. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/math-floor-part1.js » ('j') | test/mjsunit/parse-int-float.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 96b88c5285c9962d479fa75d0e71031cd0c35b6c..07816aa349d6d0670e43c5f2565de3dd3186585f 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -79,6 +79,21 @@ function InstallGetterSetter(object, name, getter, setter) {
}
+// Helper function for installing constant properties on objects.
+function InstallConstants(object, constants) {
+ if (constants.length >= 4) {
+ %OptimizeObjectForAddingMultipleProperties(object, constants.length);
Michael Starzinger 2014/01/07 16:08:00 I think constants.length should be divided by 2 (i
sof 2014/01/07 21:36:29 Oops, quite right. Done.
+ }
+ var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY;
+ for (var i = 0; i < constants.length; i += 2) {
+ var name = constants[i];
+ var k = constants[i + 1];
+ %SetProperty(object, name, k, attributes);
+ }
+ %ToFastProperties(object);
+}
+
+
// Prevents changes to the prototype of a built-in function.
// The "prototype" property of the function object is made non-configurable,
// and the prototype object is made non-extensible. The latter prevents
@@ -1624,12 +1639,29 @@ function NumberIsFinite(number) {
}
+// Harmony isInteger
+function NumberIsInteger(number) {
+ return NumberIsFinite(number) && TO_INTEGER(number) == number;
+}
+
+
// Harmony isNaN.
function NumberIsNaN(number) {
return IS_NUMBER(number) && NUMBER_IS_NAN(number);
}
+// Harmony isSafeInteger
+function NumberIsSafeInteger(number) {
+ if (NumberIsFinite(number)) {
+ var integral = TO_INTEGER(number);
+ if (integral == number)
+ return $Math.abs(integral) <= $Number.MAX_SAFE_INTEGER;
Michael Starzinger 2014/01/07 16:08:00 Better call "MathAbs" directly here, as "$Math.abs
sof 2014/01/07 21:36:29 Done.
+ }
+ return false;
+}
+
+
// ----------------------------------------------------------------------------
function SetUpNumber() {
@@ -1642,32 +1674,25 @@ function SetUpNumber() {
// Set up the constructor property on the Number prototype object.
%SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM);
- %OptimizeObjectForAddingMultipleProperties($Number, 5);
- // ECMA-262 section 15.7.3.1.
- %SetProperty($Number,
- "MAX_VALUE",
- 1.7976931348623157e+308,
- DONT_ENUM | DONT_DELETE | READ_ONLY);
-
- // ECMA-262 section 15.7.3.2.
- %SetProperty($Number, "MIN_VALUE", 5e-324,
- DONT_ENUM | DONT_DELETE | READ_ONLY);
-
- // ECMA-262 section 15.7.3.3.
- %SetProperty($Number, "NaN", NAN, DONT_ENUM | DONT_DELETE | READ_ONLY);
-
- // ECMA-262 section 15.7.3.4.
- %SetProperty($Number,
- "NEGATIVE_INFINITY",
- -INFINITY,
- DONT_ENUM | DONT_DELETE | READ_ONLY);
-
- // ECMA-262 section 15.7.3.5.
- %SetProperty($Number,
- "POSITIVE_INFINITY",
- INFINITY,
- DONT_ENUM | DONT_DELETE | READ_ONLY);
- %ToFastProperties($Number);
+ var two_pow_53_1 = 9007199254740991;
+ InstallConstants($Number, $Array(
+ // ECMA-262 section 15.7.3.1.
+ "MAX_VALUE", 1.7976931348623157e+308,
+ // ECMA-262 section 15.7.3.2.
+ "MIN_VALUE", 5e-324,
+ // ECMA-262 section 15.7.3.3.
+ "NaN", NAN,
+ // ECMA-262 section 15.7.3.4.
+ "NEGATIVE_INFINITY", -INFINITY,
+ // ECMA-262 section 15.7.3.5.
+ "POSITIVE_INFINITY", INFINITY,
+
+ // --- Harmony constants (no spec refs until settled.)
+
+ "MAX_SAFE_INTEGER", two_pow_53_1,
Michael Starzinger 2014/01/07 16:08:00 I think it is fine to inline "%_MathPow(2, 53) - 1
sof 2014/01/07 21:36:29 Done, fewer magic values.
+ "MIN_SAFE_INTEGER", -two_pow_53_1,
+ "EPSILON", %_MathPow(2, -52)
+ ));
// Set up non-enumerable functions on the Number prototype object.
InstallFunctions($Number.prototype, DONT_ENUM, $Array(
@@ -1678,9 +1703,15 @@ function SetUpNumber() {
"toExponential", NumberToExponential,
"toPrecision", NumberToPrecision
));
+
+ // Harmony Number constructor additions
InstallFunctions($Number, DONT_ENUM, $Array(
"isFinite", NumberIsFinite,
- "isNaN", NumberIsNaN
+ "isInteger", NumberIsInteger,
+ "isNaN", NumberIsNaN,
+ "isSafeInteger", NumberIsSafeInteger,
+ "parseInt", GlobalParseInt,
+ "parseFloat", GlobalParseFloat
));
}
« no previous file with comments | « no previous file | test/mjsunit/math-floor-part1.js » ('j') | test/mjsunit/parse-int-float.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698