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

Unified Diff: src/js/json.js

Issue 1579613002: [builtins] Refactor the remaining Date builtins. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: As per offline discussion, remove the weird test, which does not add a lot of value. Created 4 years, 11 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 | « src/js/date.js ('k') | src/js/macros.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/json.js
diff --git a/src/js/json.js b/src/js/json.js
index ee3b9dceea217062f077131c5807b3716352a6e5..b8836eaddd919fb9387c962391f4075e7df8e302 100644
--- a/src/js/json.js
+++ b/src/js/json.js
@@ -11,6 +11,7 @@
// -------------------------------------------------------------------
// Imports
+var GlobalDate = global.Date;
var GlobalJSON = global.JSON;
var GlobalSet = global.Set;
var InternalArray = utils.InternalArray;
@@ -247,6 +248,24 @@ utils.InstallFunctions(GlobalJSON, DONT_ENUM, [
]);
// -------------------------------------------------------------------
+// Date.toJSON
+
+// 20.3.4.37 Date.prototype.toJSON ( key )
+function DateToJSON(key) {
+ var o = TO_OBJECT(this);
+ var tv = TO_PRIMITIVE_NUMBER(o);
+ if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) {
+ return null;
+ }
+ return o.toISOString();
+}
+
+// Set up non-enumerable functions of the Date prototype object.
+utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [
+ "toJSON", DateToJSON
+]);
+
+// -------------------------------------------------------------------
// JSON Builtins
function JsonSerializeAdapter(key, object) {
« no previous file with comments | « src/js/date.js ('k') | src/js/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698