OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
979 if (digits == 1) return n; | 979 if (digits == 1) return n; |
980 return n < MathPow(10, digits - 1) ? '0' + PadInt(n, digits - 1) : n; | 980 return n < MathPow(10, digits - 1) ? '0' + PadInt(n, digits - 1) : n; |
981 } | 981 } |
982 | 982 |
983 | 983 |
984 function DateToISOString() { | 984 function DateToISOString() { |
985 var t = DATE_VALUE(this); | 985 var t = DATE_VALUE(this); |
986 if (NUMBER_IS_NAN(t)) return kInvalidDate; | 986 if (NUMBER_IS_NAN(t)) return kInvalidDate; |
987 return this.getUTCFullYear() + '-' + PadInt(this.getUTCMonth() + 1, 2) + | 987 return this.getUTCFullYear() + '-' + PadInt(this.getUTCMonth() + 1, 2) + |
988 '-' + PadInt(this.getUTCDate(), 2) + 'T' + PadInt(this.getUTCHours(), 2) + | 988 '-' + PadInt(this.getUTCDate(), 2) + 'T' + PadInt(this.getUTCHours(), 2) + |
989 ':' + PadInt(this.getUTCMinutes(), 2) + ':' + PadInt(this.getUTCSeconds(), 2) + | 989 ':' + PadInt(this.getUTCMinutes(), 2) + ':' + PadInt(this.getUTCSeconds(), 2) + |
Rico
2010/12/15 07:46:10
Not your change, but while we are here, there is a
Lasse Reichstein
2010/12/15 08:59:54
Done.
| |
990 '.' + PadInt(this.getUTCMilliseconds(), 3) + | 990 '.' + PadInt(this.getUTCMilliseconds(), 3) + |
991 'Z'; | 991 'Z'; |
992 } | 992 } |
993 | 993 |
994 | 994 |
995 function CheckJSONPrimitive(val) { | |
996 if (!IsPrimitive(val)) | |
997 throw MakeTypeError('result_not_primitive', ['toJSON', val]); | |
998 return val; | |
999 } | |
1000 | |
1001 | |
995 function DateToJSON(key) { | 1002 function DateToJSON(key) { |
996 return CheckJSONPrimitive(this.toISOString()); | 1003 return CheckJSONPrimitive(this.toISOString()); |
Rico
2010/12/15 07:46:10
Two things;
1. If "this" is a custom object, and i
Lasse Reichstein
2010/12/15 08:59:54
Rewritten completely, CheckJSONPrimitive removed a
| |
997 } | 1004 } |
998 | 1005 |
999 | 1006 |
1000 // ------------------------------------------------------------------- | 1007 // ------------------------------------------------------------------- |
1001 | 1008 |
1002 function SetupDate() { | 1009 function SetupDate() { |
1003 // Setup non-enumerable properties of the Date object itself. | 1010 // Setup non-enumerable properties of the Date object itself. |
1004 InstallFunctions($Date, DONT_ENUM, $Array( | 1011 InstallFunctions($Date, DONT_ENUM, $Array( |
1005 "UTC", DateUTC, | 1012 "UTC", DateUTC, |
1006 "parse", DateParse, | 1013 "parse", DateParse, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1056 "toGMTString", DateToGMTString, | 1063 "toGMTString", DateToGMTString, |
1057 "toUTCString", DateToUTCString, | 1064 "toUTCString", DateToUTCString, |
1058 "getYear", DateGetYear, | 1065 "getYear", DateGetYear, |
1059 "setYear", DateSetYear, | 1066 "setYear", DateSetYear, |
1060 "toISOString", DateToISOString, | 1067 "toISOString", DateToISOString, |
1061 "toJSON", DateToJSON | 1068 "toJSON", DateToJSON |
1062 )); | 1069 )); |
1063 } | 1070 } |
1064 | 1071 |
1065 SetupDate(); | 1072 SetupDate(); |
OLD | NEW |