OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/builtins.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
11 #include "src/bootstrapper.h" | 11 #include "src/bootstrapper.h" |
| 12 #include "src/dateparser-inl.h" |
12 #include "src/elements.h" | 13 #include "src/elements.h" |
13 #include "src/frames-inl.h" | 14 #include "src/frames-inl.h" |
14 #include "src/gdb-jit.h" | 15 #include "src/gdb-jit.h" |
15 #include "src/ic/handler-compiler.h" | 16 #include "src/ic/handler-compiler.h" |
16 #include "src/ic/ic.h" | 17 #include "src/ic/ic.h" |
17 #include "src/isolate-inl.h" | 18 #include "src/isolate-inl.h" |
18 #include "src/messages.h" | 19 #include "src/messages.h" |
19 #include "src/profiler/cpu-profiler.h" | 20 #include "src/profiler/cpu-profiler.h" |
20 #include "src/property-descriptor.h" | 21 #include "src/property-descriptor.h" |
21 #include "src/prototype.h" | 22 #include "src/prototype.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 name##ArgumentsType args(args_length, args_object); \ | 142 name##ArgumentsType args(args_length, args_object); \ |
142 return Builtin_Impl_##name(args, isolate); \ | 143 return Builtin_Impl_##name(args, isolate); \ |
143 } \ | 144 } \ |
144 MUST_USE_RESULT static Object* Builtin_Impl_##name( \ | 145 MUST_USE_RESULT static Object* Builtin_Impl_##name( \ |
145 name##ArgumentsType args, Isolate* isolate) | 146 name##ArgumentsType args, Isolate* isolate) |
146 | 147 |
147 | 148 |
148 // ---------------------------------------------------------------------------- | 149 // ---------------------------------------------------------------------------- |
149 | 150 |
150 | 151 |
| 152 #define CHECK_RECEIVER(Type, name, method) \ |
| 153 if (!args.receiver()->Is##Type()) { \ |
| 154 THROW_NEW_ERROR_RETURN_FAILURE( \ |
| 155 isolate, \ |
| 156 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ |
| 157 isolate->factory()->NewStringFromAsciiChecked(method), \ |
| 158 args.receiver())); \ |
| 159 } \ |
| 160 Handle<Type> name = Handle<Type>::cast(args.receiver()) |
| 161 |
| 162 |
151 inline bool ClampedToInteger(Object* object, int* out) { | 163 inline bool ClampedToInteger(Object* object, int* out) { |
152 // This is an extended version of ECMA-262 7.1.11 handling signed values | 164 // This is an extended version of ECMA-262 7.1.11 handling signed values |
153 // Try to convert object to a number and clamp values to [kMinInt, kMaxInt] | 165 // Try to convert object to a number and clamp values to [kMinInt, kMaxInt] |
154 if (object->IsSmi()) { | 166 if (object->IsSmi()) { |
155 *out = Smi::cast(object)->value(); | 167 *out = Smi::cast(object)->value(); |
156 return true; | 168 return true; |
157 } else if (object->IsHeapNumber()) { | 169 } else if (object->IsHeapNumber()) { |
158 double value = HeapNumber::cast(object)->value(); | 170 double value = HeapNumber::cast(object)->value(); |
159 if (std::isnan(value)) { | 171 if (std::isnan(value)) { |
160 *out = 0; | 172 *out = 0; |
(...skipping 1770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, proto)); | 1943 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, proto)); |
1932 } | 1944 } |
1933 | 1945 |
1934 Maybe<bool> result = JSReceiver::SetPrototype( | 1946 Maybe<bool> result = JSReceiver::SetPrototype( |
1935 Handle<JSReceiver>::cast(target), proto, true, Object::DONT_THROW); | 1947 Handle<JSReceiver>::cast(target), proto, true, Object::DONT_THROW); |
1936 MAYBE_RETURN(result, isolate->heap()->exception()); | 1948 MAYBE_RETURN(result, isolate->heap()->exception()); |
1937 return *isolate->factory()->ToBoolean(result.FromJust()); | 1949 return *isolate->factory()->ToBoolean(result.FromJust()); |
1938 } | 1950 } |
1939 | 1951 |
1940 | 1952 |
| 1953 // ----------------------------------------------------------------------------- |
| 1954 // ES6 section 20.3 Date Objects |
| 1955 |
| 1956 |
| 1957 namespace { |
| 1958 |
| 1959 // ES6 section 20.3.1.1 Time Values and Time Range |
| 1960 const double kMinYear = -1000000.0; |
| 1961 const double kMaxYear = -kMinYear; |
| 1962 const double kMinMonth = -10000000.0; |
| 1963 const double kMaxMonth = -kMinMonth; |
| 1964 |
| 1965 |
| 1966 // 20.3.1.2 Day Number and Time within Day |
| 1967 const double kMsPerDay = 86400000.0; |
| 1968 |
| 1969 |
| 1970 // ES6 section 20.3.1.11 Hours, Minutes, Second, and Milliseconds |
| 1971 const double kMsPerSecond = 1000.0; |
| 1972 const double kMsPerMinute = 60000.0; |
| 1973 const double kMsPerHour = 3600000.0; |
| 1974 |
| 1975 |
| 1976 // ES6 section 20.3.1.14 MakeDate (day, time) |
| 1977 double MakeDate(double day, double time) { |
| 1978 if (std::isfinite(day) && std::isfinite(time)) { |
| 1979 return time + day * kMsPerDay; |
| 1980 } |
| 1981 return std::numeric_limits<double>::quiet_NaN(); |
| 1982 } |
| 1983 |
| 1984 |
| 1985 // ES6 section 20.3.1.13 MakeDay (year, month, date) |
| 1986 double MakeDay(double year, double month, double date) { |
| 1987 if ((kMinYear <= year && year <= kMaxYear) && |
| 1988 (kMinMonth <= month && month <= kMaxMonth) && std::isfinite(date)) { |
| 1989 int y = FastD2I(year); |
| 1990 int m = FastD2I(month); |
| 1991 y += m / 12; |
| 1992 m %= 12; |
| 1993 if (m < 0) { |
| 1994 m += 12; |
| 1995 y -= 1; |
| 1996 } |
| 1997 DCHECK_LE(0, m); |
| 1998 DCHECK_LT(m, 12); |
| 1999 |
| 2000 // kYearDelta is an arbitrary number such that: |
| 2001 // a) kYearDelta = -1 (mod 400) |
| 2002 // b) year + kYearDelta > 0 for years in the range defined by |
| 2003 // ECMA 262 - 15.9.1.1, i.e. upto 100,000,000 days on either side of |
| 2004 // Jan 1 1970. This is required so that we don't run into integer |
| 2005 // division of negative numbers. |
| 2006 // c) there shouldn't be an overflow for 32-bit integers in the following |
| 2007 // operations. |
| 2008 static const int kYearDelta = 399999; |
| 2009 static const int kBaseDay = |
| 2010 365 * (1970 + kYearDelta) + (1970 + kYearDelta) / 4 - |
| 2011 (1970 + kYearDelta) / 100 + (1970 + kYearDelta) / 400; |
| 2012 int day_from_year = 365 * (y + kYearDelta) + (y + kYearDelta) / 4 - |
| 2013 (y + kYearDelta) / 100 + (y + kYearDelta) / 400 - |
| 2014 kBaseDay; |
| 2015 if ((y % 4 != 0) || (y % 100 == 0 && y % 400 != 0)) { |
| 2016 static const int kDayFromMonth[] = {0, 31, 59, 90, 120, 151, |
| 2017 181, 212, 243, 273, 304, 334}; |
| 2018 day_from_year += kDayFromMonth[m]; |
| 2019 } else { |
| 2020 static const int kDayFromMonth[] = {0, 31, 60, 91, 121, 152, |
| 2021 182, 213, 244, 274, 305, 335}; |
| 2022 day_from_year += kDayFromMonth[m]; |
| 2023 } |
| 2024 return static_cast<double>(day_from_year - 1) + date; |
| 2025 } |
| 2026 return std::numeric_limits<double>::quiet_NaN(); |
| 2027 } |
| 2028 |
| 2029 |
| 2030 // ES6 section 20.3.1.12 MakeTime (hour, min, sec, ms) |
| 2031 double MakeTime(double hour, double min, double sec, double ms) { |
| 2032 if (std::isfinite(hour) && std::isfinite(min) && std::isfinite(sec) && |
| 2033 std::isfinite(ms)) { |
| 2034 double const h = DoubleToInteger(hour); |
| 2035 double const m = DoubleToInteger(min); |
| 2036 double const s = DoubleToInteger(sec); |
| 2037 double const milli = DoubleToInteger(ms); |
| 2038 return h * kMsPerHour + m * kMsPerMinute + s * kMsPerSecond + milli; |
| 2039 } |
| 2040 return std::numeric_limits<double>::quiet_NaN(); |
| 2041 } |
| 2042 |
| 2043 |
| 2044 // ES6 section 20.3.1.15 TimeClip (time) |
| 2045 double TimeClip(double time) { |
| 2046 if (-DateCache::kMaxTimeInMs <= time && time <= DateCache::kMaxTimeInMs) { |
| 2047 return DoubleToInteger(time) + 0.0; |
| 2048 } |
| 2049 return std::numeric_limits<double>::quiet_NaN(); |
| 2050 } |
| 2051 |
| 2052 |
| 2053 const char* kShortWeekDays[] = {"Sun", "Mon", "Tue", "Wed", |
| 2054 "Thu", "Fri", "Sat"}; |
| 2055 const char* kShortMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 2056 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
| 2057 |
| 2058 |
| 2059 // ES6 section 20.3.1.16 Date Time String Format |
| 2060 double ParseDateTimeString(Handle<String> str) { |
| 2061 Isolate* const isolate = str->GetIsolate(); |
| 2062 str = String::Flatten(str); |
| 2063 // TODO(bmeurer): Change DateParser to not use the FixedArray. |
| 2064 Handle<FixedArray> tmp = |
| 2065 isolate->factory()->NewFixedArray(DateParser::OUTPUT_SIZE); |
| 2066 DisallowHeapAllocation no_gc; |
| 2067 String::FlatContent str_content = str->GetFlatContent(); |
| 2068 bool result; |
| 2069 if (str_content.IsOneByte()) { |
| 2070 result = DateParser::Parse(str_content.ToOneByteVector(), *tmp, |
| 2071 isolate->unicode_cache()); |
| 2072 } else { |
| 2073 result = DateParser::Parse(str_content.ToUC16Vector(), *tmp, |
| 2074 isolate->unicode_cache()); |
| 2075 } |
| 2076 if (!result) return std::numeric_limits<double>::quiet_NaN(); |
| 2077 double const day = MakeDay(tmp->get(0)->Number(), tmp->get(1)->Number(), |
| 2078 tmp->get(2)->Number()); |
| 2079 double const time = MakeTime(tmp->get(3)->Number(), tmp->get(4)->Number(), |
| 2080 tmp->get(5)->Number(), tmp->get(6)->Number()); |
| 2081 double date = MakeDate(day, time); |
| 2082 if (tmp->get(7)->IsNull()) { |
| 2083 date = isolate->date_cache()->ToUTC(static_cast<int64_t>(date)); |
| 2084 } else { |
| 2085 date -= tmp->get(7)->Number() * 1000.0; |
| 2086 } |
| 2087 return date; |
| 2088 } |
| 2089 |
| 2090 |
| 2091 // ES6 section 20.3.4.41.1 ToDateString(tv) |
| 2092 void ToDateString(double time_val, Vector<char> str, DateCache* date_cache) { |
| 2093 if (std::isnan(time_val)) { |
| 2094 SNPrintF(str, "Invalid Date"); |
| 2095 } else { |
| 2096 int64_t time_ms = static_cast<int64_t>(time_val); |
| 2097 int64_t local_time_ms = date_cache->ToLocal(time_ms); |
| 2098 int year, month, day, weekday, hour, min, sec, ms; |
| 2099 date_cache->BreakDownTime(local_time_ms, &year, &month, &day, &weekday, |
| 2100 &hour, &min, &sec, &ms); |
| 2101 int timezone_offset = -date_cache->TimezoneOffset(time_ms); |
| 2102 int timezone_hour = std::abs(timezone_offset) / 60; |
| 2103 int timezone_min = std::abs(timezone_offset) % 60; |
| 2104 const char* local_timezone = date_cache->LocalTimezone(time_ms); |
| 2105 SNPrintF(str, "%s %s %02d %4d %02d:%02d:%02d GMT%c%02d%02d (%s)", |
| 2106 kShortWeekDays[weekday], kShortMonths[month], day, year, hour, min, |
| 2107 sec, (timezone_offset < 0) ? '-' : '+', timezone_hour, |
| 2108 timezone_min, local_timezone); |
| 2109 } |
| 2110 } |
| 2111 |
| 2112 } // namespace |
| 2113 |
| 2114 |
| 2115 // ES6 section 20.3.2 The Date Constructor for the [[Call]] case. |
| 2116 BUILTIN(DateConstructor) { |
| 2117 HandleScope scope(isolate); |
| 2118 double const time_val = JSDate::CurrentTimeValue(isolate); |
| 2119 char buffer[128]; |
| 2120 Vector<char> str(buffer, arraysize(buffer)); |
| 2121 ToDateString(time_val, str, isolate->date_cache()); |
| 2122 return *isolate->factory()->NewStringFromAsciiChecked(str.start()); |
| 2123 } |
| 2124 |
| 2125 |
| 2126 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. |
| 2127 BUILTIN(DateConstructor_ConstructStub) { |
| 2128 HandleScope scope(isolate); |
| 2129 int const argc = args.length() - 1; |
| 2130 Handle<JSFunction> target = args.target(); |
| 2131 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); |
| 2132 double time_val; |
| 2133 if (argc == 0) { |
| 2134 time_val = JSDate::CurrentTimeValue(isolate); |
| 2135 } else if (argc == 1) { |
| 2136 Handle<Object> value = args.at<Object>(1); |
| 2137 if (value->IsJSDate()) { |
| 2138 time_val = Handle<JSDate>::cast(value)->value()->Number(); |
| 2139 } else { |
| 2140 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
| 2141 Object::ToPrimitive(value)); |
| 2142 if (value->IsString()) { |
| 2143 time_val = ParseDateTimeString(Handle<String>::cast(value)); |
| 2144 } else { |
| 2145 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
| 2146 Object::ToNumber(value)); |
| 2147 time_val = value->Number(); |
| 2148 } |
| 2149 } |
| 2150 } else { |
| 2151 Handle<Object> year_object; |
| 2152 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, |
| 2153 Object::ToNumber(args.at<Object>(1))); |
| 2154 Handle<Object> month_object; |
| 2155 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month_object, |
| 2156 Object::ToNumber(args.at<Object>(2))); |
| 2157 double year = year_object->Number(); |
| 2158 double month = month_object->Number(); |
| 2159 double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; |
| 2160 if (argc >= 3) { |
| 2161 Handle<Object> date_object; |
| 2162 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date_object, |
| 2163 Object::ToNumber(args.at<Object>(3))); |
| 2164 date = date_object->Number(); |
| 2165 if (argc >= 4) { |
| 2166 Handle<Object> hours_object; |
| 2167 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2168 isolate, hours_object, Object::ToNumber(args.at<Object>(4))); |
| 2169 hours = hours_object->Number(); |
| 2170 if (argc >= 5) { |
| 2171 Handle<Object> minutes_object; |
| 2172 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2173 isolate, minutes_object, Object::ToNumber(args.at<Object>(5))); |
| 2174 minutes = minutes_object->Number(); |
| 2175 if (argc >= 6) { |
| 2176 Handle<Object> seconds_object; |
| 2177 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2178 isolate, seconds_object, Object::ToNumber(args.at<Object>(6))); |
| 2179 seconds = seconds_object->Number(); |
| 2180 if (argc >= 7) { |
| 2181 Handle<Object> ms_object; |
| 2182 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2183 isolate, ms_object, Object::ToNumber(args.at<Object>(7))); |
| 2184 ms = ms_object->Number(); |
| 2185 } |
| 2186 } |
| 2187 } |
| 2188 } |
| 2189 } |
| 2190 if (!std::isnan(year)) { |
| 2191 double const y = DoubleToInteger(year); |
| 2192 if (0.0 <= y && y <= 99) year = 1900 + y; |
| 2193 } |
| 2194 double const day = MakeDay(year, month, date); |
| 2195 double const time = MakeTime(hours, minutes, seconds, ms); |
| 2196 time_val = MakeDate(day, time); |
| 2197 if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs && |
| 2198 time_val <= DateCache::kMaxTimeBeforeUTCInMs) { |
| 2199 time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val)); |
| 2200 } else { |
| 2201 time_val = std::numeric_limits<double>::quiet_NaN(); |
| 2202 } |
| 2203 } |
| 2204 Handle<JSDate> result; |
| 2205 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
| 2206 JSDate::New(target, new_target, time_val)); |
| 2207 return *result; |
| 2208 } |
| 2209 |
| 2210 |
| 2211 // ES6 section 20.3.3.1 Date.now ( ) |
| 2212 BUILTIN(DateNow) { |
| 2213 HandleScope scope(isolate); |
| 2214 return *isolate->factory()->NewNumber(JSDate::CurrentTimeValue(isolate)); |
| 2215 } |
| 2216 |
| 2217 |
| 2218 // ES6 section 20.3.3.2 Date.parse ( string ) |
| 2219 BUILTIN(DateParse) { |
| 2220 HandleScope scope(isolate); |
| 2221 Handle<String> string; |
| 2222 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2223 isolate, string, |
| 2224 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); |
| 2225 return *isolate->factory()->NewNumber(ParseDateTimeString(string)); |
| 2226 } |
| 2227 |
| 2228 |
| 2229 // ES6 section 20.3.3.4 Date.UTC (year,month,date,hours,minutes,seconds,ms) |
| 2230 BUILTIN(DateUTC) { |
| 2231 HandleScope scope(isolate); |
| 2232 int const argc = args.length() - 1; |
| 2233 double year = std::numeric_limits<double>::quiet_NaN(); |
| 2234 double month = std::numeric_limits<double>::quiet_NaN(); |
| 2235 double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; |
| 2236 if (argc >= 1) { |
| 2237 Handle<Object> year_object; |
| 2238 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, |
| 2239 Object::ToNumber(args.at<Object>(1))); |
| 2240 year = year_object->Number(); |
| 2241 if (argc >= 2) { |
| 2242 Handle<Object> month_object; |
| 2243 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month_object, |
| 2244 Object::ToNumber(args.at<Object>(2))); |
| 2245 month = month_object->Number(); |
| 2246 if (argc >= 3) { |
| 2247 Handle<Object> date_object; |
| 2248 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2249 isolate, date_object, Object::ToNumber(args.at<Object>(3))); |
| 2250 date = date_object->Number(); |
| 2251 if (argc >= 4) { |
| 2252 Handle<Object> hours_object; |
| 2253 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2254 isolate, hours_object, Object::ToNumber(args.at<Object>(4))); |
| 2255 hours = hours_object->Number(); |
| 2256 if (argc >= 5) { |
| 2257 Handle<Object> minutes_object; |
| 2258 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2259 isolate, minutes_object, Object::ToNumber(args.at<Object>(5))); |
| 2260 minutes = minutes_object->Number(); |
| 2261 if (argc >= 6) { |
| 2262 Handle<Object> seconds_object; |
| 2263 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2264 isolate, seconds_object, |
| 2265 Object::ToNumber(args.at<Object>(6))); |
| 2266 seconds = seconds_object->Number(); |
| 2267 if (argc >= 7) { |
| 2268 Handle<Object> ms_object; |
| 2269 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2270 isolate, ms_object, Object::ToNumber(args.at<Object>(7))); |
| 2271 ms = ms_object->Number(); |
| 2272 } |
| 2273 } |
| 2274 } |
| 2275 } |
| 2276 } |
| 2277 } |
| 2278 } |
| 2279 if (!std::isnan(year)) { |
| 2280 double const y = DoubleToInteger(year); |
| 2281 if (0.0 <= y && y <= 99) year = 1900 + y; |
| 2282 } |
| 2283 double const day = MakeDay(year, month, date); |
| 2284 double const time = MakeTime(hours, minutes, seconds, ms); |
| 2285 return *isolate->factory()->NewNumber(TimeClip(MakeDate(day, time))); |
| 2286 } |
| 2287 |
| 2288 |
| 2289 // ES6 section 20.3.4.36 Date.prototype.toISOString ( ) |
| 2290 BUILTIN(DatePrototypeToISOString) { |
| 2291 HandleScope scope(isolate); |
| 2292 CHECK_RECEIVER(JSDate, date, "Date.prototype.toISOString"); |
| 2293 double const time_val = date->value()->Number(); |
| 2294 if (std::isnan(time_val)) { |
| 2295 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2296 isolate, NewRangeError(MessageTemplate::kInvalidTimeValue)); |
| 2297 } |
| 2298 int64_t const time_ms = static_cast<int64_t>(time_val); |
| 2299 int year, month, day, weekday, hour, min, sec, ms; |
| 2300 isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday, |
| 2301 &hour, &min, &sec, &ms); |
| 2302 char buffer[128]; |
| 2303 Vector<char> str(buffer, arraysize(buffer)); |
| 2304 if (year >= 0 && year <= 9999) { |
| 2305 SNPrintF(str, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, month + 1, day, |
| 2306 hour, min, sec, ms); |
| 2307 } else if (year < 0) { |
| 2308 SNPrintF(str, "-%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", -year, month + 1, day, |
| 2309 hour, min, sec, ms); |
| 2310 } else { |
| 2311 SNPrintF(str, "+%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, month + 1, day, |
| 2312 hour, min, sec, ms); |
| 2313 } |
| 2314 return *isolate->factory()->NewStringFromAsciiChecked(str.start()); |
| 2315 } |
| 2316 |
| 2317 |
| 2318 // ES6 section 20.3.4.44 Date.prototype.valueOf ( ) |
| 2319 BUILTIN(DatePrototypeValueOf) { |
| 2320 HandleScope scope(isolate); |
| 2321 CHECK_RECEIVER(JSDate, date, "Date.prototype.valueOf"); |
| 2322 return date->value(); |
| 2323 } |
| 2324 |
| 2325 |
1941 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) | 2326 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) |
1942 BUILTIN(DateToPrimitive) { | 2327 BUILTIN(DatePrototypeToPrimitive) { |
1943 HandleScope scope(isolate); | 2328 HandleScope scope(isolate); |
1944 DCHECK_EQ(2, args.length()); | 2329 DCHECK_EQ(2, args.length()); |
1945 if (!args.receiver()->IsJSReceiver()) { | 2330 CHECK_RECEIVER(JSReceiver, receiver, "Date.prototype [ @@toPrimitive ]"); |
1946 THROW_NEW_ERROR_RETURN_FAILURE( | |
1947 isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, | |
1948 isolate->factory()->NewStringFromAsciiChecked( | |
1949 "Date.prototype [ @@toPrimitive ]"), | |
1950 args.receiver())); | |
1951 } | |
1952 Handle<JSReceiver> receiver = args.at<JSReceiver>(0); | |
1953 Handle<Object> hint = args.at<Object>(1); | 2331 Handle<Object> hint = args.at<Object>(1); |
1954 Handle<Object> result; | 2332 Handle<Object> result; |
1955 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | 2333 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
1956 JSDate::ToPrimitive(receiver, hint)); | 2334 JSDate::ToPrimitive(receiver, hint)); |
1957 return *result; | 2335 return *result; |
1958 } | 2336 } |
1959 | 2337 |
1960 | 2338 |
1961 namespace { | 2339 namespace { |
1962 | 2340 |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2915 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 3293 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
2916 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 3294 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
2917 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 3295 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
2918 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 3296 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
2919 #undef DEFINE_BUILTIN_ACCESSOR_C | 3297 #undef DEFINE_BUILTIN_ACCESSOR_C |
2920 #undef DEFINE_BUILTIN_ACCESSOR_A | 3298 #undef DEFINE_BUILTIN_ACCESSOR_A |
2921 | 3299 |
2922 | 3300 |
2923 } // namespace internal | 3301 } // namespace internal |
2924 } // namespace v8 | 3302 } // namespace v8 |
OLD | NEW |