OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/builtins-utils.h" | 5 #include "src/builtins/builtins-utils.h" |
6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
8 #include "src/dateparser-inl.h" | 8 #include "src/dateparser-inl.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. | 202 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. |
203 BUILTIN(DateConstructor_ConstructStub) { | 203 BUILTIN(DateConstructor_ConstructStub) { |
204 HandleScope scope(isolate); | 204 HandleScope scope(isolate); |
205 int const argc = args.length() - 1; | 205 int const argc = args.length() - 1; |
206 Handle<JSFunction> target = args.target(); | 206 Handle<JSFunction> target = args.target(); |
207 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); | 207 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); |
208 double time_val; | 208 double time_val; |
209 if (argc == 0) { | 209 if (argc == 0) { |
210 time_val = JSDate::CurrentTimeValue(isolate); | 210 time_val = JSDate::CurrentTimeValue(isolate); |
211 } else if (argc == 1) { | 211 } else if (argc == 1) { |
212 Handle<Object> value = args.at<Object>(1); | 212 Handle<Object> value = args.at(1); |
213 if (value->IsJSDate()) { | 213 if (value->IsJSDate()) { |
214 time_val = Handle<JSDate>::cast(value)->value()->Number(); | 214 time_val = Handle<JSDate>::cast(value)->value()->Number(); |
215 } else { | 215 } else { |
216 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 216 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
217 Object::ToPrimitive(value)); | 217 Object::ToPrimitive(value)); |
218 if (value->IsString()) { | 218 if (value->IsString()) { |
219 time_val = ParseDateTimeString(Handle<String>::cast(value)); | 219 time_val = ParseDateTimeString(Handle<String>::cast(value)); |
220 } else { | 220 } else { |
221 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 221 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
222 Object::ToNumber(value)); | 222 Object::ToNumber(value)); |
223 time_val = value->Number(); | 223 time_val = value->Number(); |
224 } | 224 } |
225 } | 225 } |
226 } else { | 226 } else { |
227 Handle<Object> year_object; | 227 Handle<Object> year_object; |
228 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, | 228 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, |
229 Object::ToNumber(args.at<Object>(1))); | 229 Object::ToNumber(args.at(1))); |
230 Handle<Object> month_object; | 230 Handle<Object> month_object; |
231 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month_object, | 231 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month_object, |
232 Object::ToNumber(args.at<Object>(2))); | 232 Object::ToNumber(args.at(2))); |
233 double year = year_object->Number(); | 233 double year = year_object->Number(); |
234 double month = month_object->Number(); | 234 double month = month_object->Number(); |
235 double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; | 235 double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; |
236 if (argc >= 3) { | 236 if (argc >= 3) { |
237 Handle<Object> date_object; | 237 Handle<Object> date_object; |
238 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date_object, | 238 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date_object, |
239 Object::ToNumber(args.at<Object>(3))); | 239 Object::ToNumber(args.at(3))); |
240 date = date_object->Number(); | 240 date = date_object->Number(); |
241 if (argc >= 4) { | 241 if (argc >= 4) { |
242 Handle<Object> hours_object; | 242 Handle<Object> hours_object; |
243 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 243 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hours_object, |
244 isolate, hours_object, Object::ToNumber(args.at<Object>(4))); | 244 Object::ToNumber(args.at(4))); |
245 hours = hours_object->Number(); | 245 hours = hours_object->Number(); |
246 if (argc >= 5) { | 246 if (argc >= 5) { |
247 Handle<Object> minutes_object; | 247 Handle<Object> minutes_object; |
248 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 248 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, minutes_object, |
249 isolate, minutes_object, Object::ToNumber(args.at<Object>(5))); | 249 Object::ToNumber(args.at(5))); |
250 minutes = minutes_object->Number(); | 250 minutes = minutes_object->Number(); |
251 if (argc >= 6) { | 251 if (argc >= 6) { |
252 Handle<Object> seconds_object; | 252 Handle<Object> seconds_object; |
253 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 253 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, seconds_object, |
254 isolate, seconds_object, Object::ToNumber(args.at<Object>(6))); | 254 Object::ToNumber(args.at(6))); |
255 seconds = seconds_object->Number(); | 255 seconds = seconds_object->Number(); |
256 if (argc >= 7) { | 256 if (argc >= 7) { |
257 Handle<Object> ms_object; | 257 Handle<Object> ms_object; |
258 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 258 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms_object, |
259 isolate, ms_object, Object::ToNumber(args.at<Object>(7))); | 259 Object::ToNumber(args.at(7))); |
260 ms = ms_object->Number(); | 260 ms = ms_object->Number(); |
261 } | 261 } |
262 } | 262 } |
263 } | 263 } |
264 } | 264 } |
265 } | 265 } |
266 if (!std::isnan(year)) { | 266 if (!std::isnan(year)) { |
267 double const y = DoubleToInteger(year); | 267 double const y = DoubleToInteger(year); |
268 if (0.0 <= y && y <= 99) year = 1900 + y; | 268 if (0.0 <= y && y <= 99) year = 1900 + y; |
269 } | 269 } |
(...skipping 29 matching lines...) Expand all Loading... |
299 // ES6 section 20.3.3.4 Date.UTC (year,month,date,hours,minutes,seconds,ms) | 299 // ES6 section 20.3.3.4 Date.UTC (year,month,date,hours,minutes,seconds,ms) |
300 BUILTIN(DateUTC) { | 300 BUILTIN(DateUTC) { |
301 HandleScope scope(isolate); | 301 HandleScope scope(isolate); |
302 int const argc = args.length() - 1; | 302 int const argc = args.length() - 1; |
303 double year = std::numeric_limits<double>::quiet_NaN(); | 303 double year = std::numeric_limits<double>::quiet_NaN(); |
304 double month = std::numeric_limits<double>::quiet_NaN(); | 304 double month = std::numeric_limits<double>::quiet_NaN(); |
305 double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; | 305 double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; |
306 if (argc >= 1) { | 306 if (argc >= 1) { |
307 Handle<Object> year_object; | 307 Handle<Object> year_object; |
308 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, | 308 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, |
309 Object::ToNumber(args.at<Object>(1))); | 309 Object::ToNumber(args.at(1))); |
310 year = year_object->Number(); | 310 year = year_object->Number(); |
311 if (argc >= 2) { | 311 if (argc >= 2) { |
312 Handle<Object> month_object; | 312 Handle<Object> month_object; |
313 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month_object, | 313 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month_object, |
314 Object::ToNumber(args.at<Object>(2))); | 314 Object::ToNumber(args.at(2))); |
315 month = month_object->Number(); | 315 month = month_object->Number(); |
316 if (argc >= 3) { | 316 if (argc >= 3) { |
317 Handle<Object> date_object; | 317 Handle<Object> date_object; |
318 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 318 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date_object, |
319 isolate, date_object, Object::ToNumber(args.at<Object>(3))); | 319 Object::ToNumber(args.at(3))); |
320 date = date_object->Number(); | 320 date = date_object->Number(); |
321 if (argc >= 4) { | 321 if (argc >= 4) { |
322 Handle<Object> hours_object; | 322 Handle<Object> hours_object; |
323 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 323 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hours_object, |
324 isolate, hours_object, Object::ToNumber(args.at<Object>(4))); | 324 Object::ToNumber(args.at(4))); |
325 hours = hours_object->Number(); | 325 hours = hours_object->Number(); |
326 if (argc >= 5) { | 326 if (argc >= 5) { |
327 Handle<Object> minutes_object; | 327 Handle<Object> minutes_object; |
328 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 328 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, minutes_object, |
329 isolate, minutes_object, Object::ToNumber(args.at<Object>(5))); | 329 Object::ToNumber(args.at(5))); |
330 minutes = minutes_object->Number(); | 330 minutes = minutes_object->Number(); |
331 if (argc >= 6) { | 331 if (argc >= 6) { |
332 Handle<Object> seconds_object; | 332 Handle<Object> seconds_object; |
333 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 333 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, seconds_object, |
334 isolate, seconds_object, | 334 Object::ToNumber(args.at(6))); |
335 Object::ToNumber(args.at<Object>(6))); | |
336 seconds = seconds_object->Number(); | 335 seconds = seconds_object->Number(); |
337 if (argc >= 7) { | 336 if (argc >= 7) { |
338 Handle<Object> ms_object; | 337 Handle<Object> ms_object; |
339 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 338 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
340 isolate, ms_object, Object::ToNumber(args.at<Object>(7))); | 339 isolate, ms_object, Object::ToNumber(args.at(7))); |
341 ms = ms_object->Number(); | 340 ms = ms_object->Number(); |
342 } | 341 } |
343 } | 342 } |
344 } | 343 } |
345 } | 344 } |
346 } | 345 } |
347 } | 346 } |
348 } | 347 } |
349 if (!std::isnan(year)) { | 348 if (!std::isnan(year)) { |
350 double const y = DoubleToInteger(year); | 349 double const y = DoubleToInteger(year); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 int64_t const time_ms = static_cast<int64_t>(date->value()->Number()); | 386 int64_t const time_ms = static_cast<int64_t>(date->value()->Number()); |
388 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); | 387 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); |
389 int const days = isolate->date_cache()->DaysFromTime(local_time_ms); | 388 int const days = isolate->date_cache()->DaysFromTime(local_time_ms); |
390 time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, days); | 389 time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, days); |
391 int year, month, day; | 390 int year, month, day; |
392 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); | 391 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); |
393 m = month; | 392 m = month; |
394 dt = day; | 393 dt = day; |
395 } | 394 } |
396 if (argc >= 2) { | 395 if (argc >= 2) { |
397 Handle<Object> month = args.at<Object>(2); | 396 Handle<Object> month = args.at(2); |
398 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); | 397 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); |
399 m = month->Number(); | 398 m = month->Number(); |
400 if (argc >= 3) { | 399 if (argc >= 3) { |
401 Handle<Object> date = args.at<Object>(3); | 400 Handle<Object> date = args.at(3); |
402 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); | 401 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); |
403 dt = date->Number(); | 402 dt = date->Number(); |
404 } | 403 } |
405 } | 404 } |
406 double time_val = MakeDate(MakeDay(y, m, dt), time_within_day); | 405 double time_val = MakeDate(MakeDay(y, m, dt), time_within_day); |
407 return SetLocalDateValue(date, time_val); | 406 return SetLocalDateValue(date, time_val); |
408 } | 407 } |
409 | 408 |
410 // ES6 section 20.3.4.22 Date.prototype.setHours(hour, min, sec, ms) | 409 // ES6 section 20.3.4.22 Date.prototype.setHours(hour, min, sec, ms) |
411 BUILTIN(DatePrototypeSetHours) { | 410 BUILTIN(DatePrototypeSetHours) { |
412 HandleScope scope(isolate); | 411 HandleScope scope(isolate); |
413 CHECK_RECEIVER(JSDate, date, "Date.prototype.setHours"); | 412 CHECK_RECEIVER(JSDate, date, "Date.prototype.setHours"); |
414 int const argc = args.length() - 1; | 413 int const argc = args.length() - 1; |
415 Handle<Object> hour = args.atOrUndefined(isolate, 1); | 414 Handle<Object> hour = args.atOrUndefined(isolate, 1); |
416 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hour, Object::ToNumber(hour)); | 415 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hour, Object::ToNumber(hour)); |
417 double h = hour->Number(); | 416 double h = hour->Number(); |
418 double time_val = date->value()->Number(); | 417 double time_val = date->value()->Number(); |
419 if (!std::isnan(time_val)) { | 418 if (!std::isnan(time_val)) { |
420 int64_t const time_ms = static_cast<int64_t>(time_val); | 419 int64_t const time_ms = static_cast<int64_t>(time_val); |
421 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); | 420 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); |
422 int day = isolate->date_cache()->DaysFromTime(local_time_ms); | 421 int day = isolate->date_cache()->DaysFromTime(local_time_ms); |
423 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, day); | 422 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, day); |
424 double m = (time_within_day / (60 * 1000)) % 60; | 423 double m = (time_within_day / (60 * 1000)) % 60; |
425 double s = (time_within_day / 1000) % 60; | 424 double s = (time_within_day / 1000) % 60; |
426 double milli = time_within_day % 1000; | 425 double milli = time_within_day % 1000; |
427 if (argc >= 2) { | 426 if (argc >= 2) { |
428 Handle<Object> min = args.at<Object>(2); | 427 Handle<Object> min = args.at(2); |
429 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, min, Object::ToNumber(min)); | 428 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, min, Object::ToNumber(min)); |
430 m = min->Number(); | 429 m = min->Number(); |
431 if (argc >= 3) { | 430 if (argc >= 3) { |
432 Handle<Object> sec = args.at<Object>(3); | 431 Handle<Object> sec = args.at(3); |
433 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); | 432 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); |
434 s = sec->Number(); | 433 s = sec->Number(); |
435 if (argc >= 4) { | 434 if (argc >= 4) { |
436 Handle<Object> ms = args.at<Object>(4); | 435 Handle<Object> ms = args.at(4); |
437 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 436 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
438 milli = ms->Number(); | 437 milli = ms->Number(); |
439 } | 438 } |
440 } | 439 } |
441 } | 440 } |
442 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 441 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
443 } | 442 } |
444 return SetLocalDateValue(date, time_val); | 443 return SetLocalDateValue(date, time_val); |
445 } | 444 } |
446 | 445 |
(...skipping 28 matching lines...) Expand all Loading... |
475 if (!std::isnan(time_val)) { | 474 if (!std::isnan(time_val)) { |
476 int64_t const time_ms = static_cast<int64_t>(time_val); | 475 int64_t const time_ms = static_cast<int64_t>(time_val); |
477 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); | 476 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); |
478 int day = isolate->date_cache()->DaysFromTime(local_time_ms); | 477 int day = isolate->date_cache()->DaysFromTime(local_time_ms); |
479 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, day); | 478 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, day); |
480 int h = time_within_day / (60 * 60 * 1000); | 479 int h = time_within_day / (60 * 60 * 1000); |
481 double m = min->Number(); | 480 double m = min->Number(); |
482 double s = (time_within_day / 1000) % 60; | 481 double s = (time_within_day / 1000) % 60; |
483 double milli = time_within_day % 1000; | 482 double milli = time_within_day % 1000; |
484 if (argc >= 2) { | 483 if (argc >= 2) { |
485 Handle<Object> sec = args.at<Object>(2); | 484 Handle<Object> sec = args.at(2); |
486 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); | 485 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); |
487 s = sec->Number(); | 486 s = sec->Number(); |
488 if (argc >= 3) { | 487 if (argc >= 3) { |
489 Handle<Object> ms = args.at<Object>(3); | 488 Handle<Object> ms = args.at(3); |
490 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 489 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
491 milli = ms->Number(); | 490 milli = ms->Number(); |
492 } | 491 } |
493 } | 492 } |
494 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 493 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
495 } | 494 } |
496 return SetLocalDateValue(date, time_val); | 495 return SetLocalDateValue(date, time_val); |
497 } | 496 } |
498 | 497 |
499 // ES6 section 20.3.4.25 Date.prototype.setMonth ( month, date ) | 498 // ES6 section 20.3.4.25 Date.prototype.setMonth ( month, date ) |
500 BUILTIN(DatePrototypeSetMonth) { | 499 BUILTIN(DatePrototypeSetMonth) { |
501 HandleScope scope(isolate); | 500 HandleScope scope(isolate); |
502 CHECK_RECEIVER(JSDate, date, "Date.prototype.setMonth"); | 501 CHECK_RECEIVER(JSDate, date, "Date.prototype.setMonth"); |
503 int const argc = args.length() - 1; | 502 int const argc = args.length() - 1; |
504 Handle<Object> month = args.atOrUndefined(isolate, 1); | 503 Handle<Object> month = args.atOrUndefined(isolate, 1); |
505 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); | 504 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); |
506 double time_val = date->value()->Number(); | 505 double time_val = date->value()->Number(); |
507 if (!std::isnan(time_val)) { | 506 if (!std::isnan(time_val)) { |
508 int64_t const time_ms = static_cast<int64_t>(time_val); | 507 int64_t const time_ms = static_cast<int64_t>(time_val); |
509 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); | 508 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); |
510 int days = isolate->date_cache()->DaysFromTime(local_time_ms); | 509 int days = isolate->date_cache()->DaysFromTime(local_time_ms); |
511 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, days); | 510 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, days); |
512 int year, unused, day; | 511 int year, unused, day; |
513 isolate->date_cache()->YearMonthDayFromDays(days, &year, &unused, &day); | 512 isolate->date_cache()->YearMonthDayFromDays(days, &year, &unused, &day); |
514 double m = month->Number(); | 513 double m = month->Number(); |
515 double dt = day; | 514 double dt = day; |
516 if (argc >= 2) { | 515 if (argc >= 2) { |
517 Handle<Object> date = args.at<Object>(2); | 516 Handle<Object> date = args.at(2); |
518 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); | 517 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); |
519 dt = date->Number(); | 518 dt = date->Number(); |
520 } | 519 } |
521 time_val = MakeDate(MakeDay(year, m, dt), time_within_day); | 520 time_val = MakeDate(MakeDay(year, m, dt), time_within_day); |
522 } | 521 } |
523 return SetLocalDateValue(date, time_val); | 522 return SetLocalDateValue(date, time_val); |
524 } | 523 } |
525 | 524 |
526 // ES6 section 20.3.4.26 Date.prototype.setSeconds ( sec, ms ) | 525 // ES6 section 20.3.4.26 Date.prototype.setSeconds ( sec, ms ) |
527 BUILTIN(DatePrototypeSetSeconds) { | 526 BUILTIN(DatePrototypeSetSeconds) { |
528 HandleScope scope(isolate); | 527 HandleScope scope(isolate); |
529 CHECK_RECEIVER(JSDate, date, "Date.prototype.setSeconds"); | 528 CHECK_RECEIVER(JSDate, date, "Date.prototype.setSeconds"); |
530 int const argc = args.length() - 1; | 529 int const argc = args.length() - 1; |
531 Handle<Object> sec = args.atOrUndefined(isolate, 1); | 530 Handle<Object> sec = args.atOrUndefined(isolate, 1); |
532 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); | 531 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); |
533 double time_val = date->value()->Number(); | 532 double time_val = date->value()->Number(); |
534 if (!std::isnan(time_val)) { | 533 if (!std::isnan(time_val)) { |
535 int64_t const time_ms = static_cast<int64_t>(time_val); | 534 int64_t const time_ms = static_cast<int64_t>(time_val); |
536 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); | 535 int64_t local_time_ms = isolate->date_cache()->ToLocal(time_ms); |
537 int day = isolate->date_cache()->DaysFromTime(local_time_ms); | 536 int day = isolate->date_cache()->DaysFromTime(local_time_ms); |
538 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, day); | 537 int time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, day); |
539 int h = time_within_day / (60 * 60 * 1000); | 538 int h = time_within_day / (60 * 60 * 1000); |
540 double m = (time_within_day / (60 * 1000)) % 60; | 539 double m = (time_within_day / (60 * 1000)) % 60; |
541 double s = sec->Number(); | 540 double s = sec->Number(); |
542 double milli = time_within_day % 1000; | 541 double milli = time_within_day % 1000; |
543 if (argc >= 2) { | 542 if (argc >= 2) { |
544 Handle<Object> ms = args.at<Object>(2); | 543 Handle<Object> ms = args.at(2); |
545 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 544 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
546 milli = ms->Number(); | 545 milli = ms->Number(); |
547 } | 546 } |
548 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 547 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
549 } | 548 } |
550 return SetLocalDateValue(date, time_val); | 549 return SetLocalDateValue(date, time_val); |
551 } | 550 } |
552 | 551 |
553 // ES6 section 20.3.4.27 Date.prototype.setTime ( time ) | 552 // ES6 section 20.3.4.27 Date.prototype.setTime ( time ) |
554 BUILTIN(DatePrototypeSetTime) { | 553 BUILTIN(DatePrototypeSetTime) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 if (!std::isnan(date->value()->Number())) { | 587 if (!std::isnan(date->value()->Number())) { |
589 int64_t const time_ms = static_cast<int64_t>(date->value()->Number()); | 588 int64_t const time_ms = static_cast<int64_t>(date->value()->Number()); |
590 int const days = isolate->date_cache()->DaysFromTime(time_ms); | 589 int const days = isolate->date_cache()->DaysFromTime(time_ms); |
591 time_within_day = isolate->date_cache()->TimeInDay(time_ms, days); | 590 time_within_day = isolate->date_cache()->TimeInDay(time_ms, days); |
592 int year, month, day; | 591 int year, month, day; |
593 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); | 592 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); |
594 m = month; | 593 m = month; |
595 dt = day; | 594 dt = day; |
596 } | 595 } |
597 if (argc >= 2) { | 596 if (argc >= 2) { |
598 Handle<Object> month = args.at<Object>(2); | 597 Handle<Object> month = args.at(2); |
599 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); | 598 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); |
600 m = month->Number(); | 599 m = month->Number(); |
601 if (argc >= 3) { | 600 if (argc >= 3) { |
602 Handle<Object> date = args.at<Object>(3); | 601 Handle<Object> date = args.at(3); |
603 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); | 602 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); |
604 dt = date->Number(); | 603 dt = date->Number(); |
605 } | 604 } |
606 } | 605 } |
607 double const time_val = MakeDate(MakeDay(y, m, dt), time_within_day); | 606 double const time_val = MakeDate(MakeDay(y, m, dt), time_within_day); |
608 return *JSDate::SetValue(date, TimeClip(time_val)); | 607 return *JSDate::SetValue(date, TimeClip(time_val)); |
609 } | 608 } |
610 | 609 |
611 // ES6 section 20.3.4.30 Date.prototype.setUTCHours(hour, min, sec, ms) | 610 // ES6 section 20.3.4.30 Date.prototype.setUTCHours(hour, min, sec, ms) |
612 BUILTIN(DatePrototypeSetUTCHours) { | 611 BUILTIN(DatePrototypeSetUTCHours) { |
613 HandleScope scope(isolate); | 612 HandleScope scope(isolate); |
614 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCHours"); | 613 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCHours"); |
615 int const argc = args.length() - 1; | 614 int const argc = args.length() - 1; |
616 Handle<Object> hour = args.atOrUndefined(isolate, 1); | 615 Handle<Object> hour = args.atOrUndefined(isolate, 1); |
617 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hour, Object::ToNumber(hour)); | 616 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hour, Object::ToNumber(hour)); |
618 double h = hour->Number(); | 617 double h = hour->Number(); |
619 double time_val = date->value()->Number(); | 618 double time_val = date->value()->Number(); |
620 if (!std::isnan(time_val)) { | 619 if (!std::isnan(time_val)) { |
621 int64_t const time_ms = static_cast<int64_t>(time_val); | 620 int64_t const time_ms = static_cast<int64_t>(time_val); |
622 int day = isolate->date_cache()->DaysFromTime(time_ms); | 621 int day = isolate->date_cache()->DaysFromTime(time_ms); |
623 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, day); | 622 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, day); |
624 double m = (time_within_day / (60 * 1000)) % 60; | 623 double m = (time_within_day / (60 * 1000)) % 60; |
625 double s = (time_within_day / 1000) % 60; | 624 double s = (time_within_day / 1000) % 60; |
626 double milli = time_within_day % 1000; | 625 double milli = time_within_day % 1000; |
627 if (argc >= 2) { | 626 if (argc >= 2) { |
628 Handle<Object> min = args.at<Object>(2); | 627 Handle<Object> min = args.at(2); |
629 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, min, Object::ToNumber(min)); | 628 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, min, Object::ToNumber(min)); |
630 m = min->Number(); | 629 m = min->Number(); |
631 if (argc >= 3) { | 630 if (argc >= 3) { |
632 Handle<Object> sec = args.at<Object>(3); | 631 Handle<Object> sec = args.at(3); |
633 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); | 632 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); |
634 s = sec->Number(); | 633 s = sec->Number(); |
635 if (argc >= 4) { | 634 if (argc >= 4) { |
636 Handle<Object> ms = args.at<Object>(4); | 635 Handle<Object> ms = args.at(4); |
637 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 636 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
638 milli = ms->Number(); | 637 milli = ms->Number(); |
639 } | 638 } |
640 } | 639 } |
641 } | 640 } |
642 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 641 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
643 } | 642 } |
644 return *JSDate::SetValue(date, TimeClip(time_val)); | 643 return *JSDate::SetValue(date, TimeClip(time_val)); |
645 } | 644 } |
646 | 645 |
(...skipping 26 matching lines...) Expand all Loading... |
673 double time_val = date->value()->Number(); | 672 double time_val = date->value()->Number(); |
674 if (!std::isnan(time_val)) { | 673 if (!std::isnan(time_val)) { |
675 int64_t const time_ms = static_cast<int64_t>(time_val); | 674 int64_t const time_ms = static_cast<int64_t>(time_val); |
676 int day = isolate->date_cache()->DaysFromTime(time_ms); | 675 int day = isolate->date_cache()->DaysFromTime(time_ms); |
677 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, day); | 676 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, day); |
678 int h = time_within_day / (60 * 60 * 1000); | 677 int h = time_within_day / (60 * 60 * 1000); |
679 double m = min->Number(); | 678 double m = min->Number(); |
680 double s = (time_within_day / 1000) % 60; | 679 double s = (time_within_day / 1000) % 60; |
681 double milli = time_within_day % 1000; | 680 double milli = time_within_day % 1000; |
682 if (argc >= 2) { | 681 if (argc >= 2) { |
683 Handle<Object> sec = args.at<Object>(2); | 682 Handle<Object> sec = args.at(2); |
684 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); | 683 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); |
685 s = sec->Number(); | 684 s = sec->Number(); |
686 if (argc >= 3) { | 685 if (argc >= 3) { |
687 Handle<Object> ms = args.at<Object>(3); | 686 Handle<Object> ms = args.at(3); |
688 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 687 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
689 milli = ms->Number(); | 688 milli = ms->Number(); |
690 } | 689 } |
691 } | 690 } |
692 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 691 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
693 } | 692 } |
694 return *JSDate::SetValue(date, TimeClip(time_val)); | 693 return *JSDate::SetValue(date, TimeClip(time_val)); |
695 } | 694 } |
696 | 695 |
697 // ES6 section 20.3.4.31 Date.prototype.setUTCMonth ( month, date ) | 696 // ES6 section 20.3.4.31 Date.prototype.setUTCMonth ( month, date ) |
698 BUILTIN(DatePrototypeSetUTCMonth) { | 697 BUILTIN(DatePrototypeSetUTCMonth) { |
699 HandleScope scope(isolate); | 698 HandleScope scope(isolate); |
700 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCMonth"); | 699 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCMonth"); |
701 int const argc = args.length() - 1; | 700 int const argc = args.length() - 1; |
702 Handle<Object> month = args.atOrUndefined(isolate, 1); | 701 Handle<Object> month = args.atOrUndefined(isolate, 1); |
703 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); | 702 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month, Object::ToNumber(month)); |
704 double time_val = date->value()->Number(); | 703 double time_val = date->value()->Number(); |
705 if (!std::isnan(time_val)) { | 704 if (!std::isnan(time_val)) { |
706 int64_t const time_ms = static_cast<int64_t>(time_val); | 705 int64_t const time_ms = static_cast<int64_t>(time_val); |
707 int days = isolate->date_cache()->DaysFromTime(time_ms); | 706 int days = isolate->date_cache()->DaysFromTime(time_ms); |
708 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, days); | 707 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, days); |
709 int year, unused, day; | 708 int year, unused, day; |
710 isolate->date_cache()->YearMonthDayFromDays(days, &year, &unused, &day); | 709 isolate->date_cache()->YearMonthDayFromDays(days, &year, &unused, &day); |
711 double m = month->Number(); | 710 double m = month->Number(); |
712 double dt = day; | 711 double dt = day; |
713 if (argc >= 2) { | 712 if (argc >= 2) { |
714 Handle<Object> date = args.at<Object>(2); | 713 Handle<Object> date = args.at(2); |
715 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); | 714 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date, Object::ToNumber(date)); |
716 dt = date->Number(); | 715 dt = date->Number(); |
717 } | 716 } |
718 time_val = MakeDate(MakeDay(year, m, dt), time_within_day); | 717 time_val = MakeDate(MakeDay(year, m, dt), time_within_day); |
719 } | 718 } |
720 return *JSDate::SetValue(date, TimeClip(time_val)); | 719 return *JSDate::SetValue(date, TimeClip(time_val)); |
721 } | 720 } |
722 | 721 |
723 // ES6 section 20.3.4.34 Date.prototype.setUTCSeconds ( sec, ms ) | 722 // ES6 section 20.3.4.34 Date.prototype.setUTCSeconds ( sec, ms ) |
724 BUILTIN(DatePrototypeSetUTCSeconds) { | 723 BUILTIN(DatePrototypeSetUTCSeconds) { |
725 HandleScope scope(isolate); | 724 HandleScope scope(isolate); |
726 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCSeconds"); | 725 CHECK_RECEIVER(JSDate, date, "Date.prototype.setUTCSeconds"); |
727 int const argc = args.length() - 1; | 726 int const argc = args.length() - 1; |
728 Handle<Object> sec = args.atOrUndefined(isolate, 1); | 727 Handle<Object> sec = args.atOrUndefined(isolate, 1); |
729 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); | 728 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, sec, Object::ToNumber(sec)); |
730 double time_val = date->value()->Number(); | 729 double time_val = date->value()->Number(); |
731 if (!std::isnan(time_val)) { | 730 if (!std::isnan(time_val)) { |
732 int64_t const time_ms = static_cast<int64_t>(time_val); | 731 int64_t const time_ms = static_cast<int64_t>(time_val); |
733 int day = isolate->date_cache()->DaysFromTime(time_ms); | 732 int day = isolate->date_cache()->DaysFromTime(time_ms); |
734 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, day); | 733 int time_within_day = isolate->date_cache()->TimeInDay(time_ms, day); |
735 int h = time_within_day / (60 * 60 * 1000); | 734 int h = time_within_day / (60 * 60 * 1000); |
736 double m = (time_within_day / (60 * 1000)) % 60; | 735 double m = (time_within_day / (60 * 1000)) % 60; |
737 double s = sec->Number(); | 736 double s = sec->Number(); |
738 double milli = time_within_day % 1000; | 737 double milli = time_within_day % 1000; |
739 if (argc >= 2) { | 738 if (argc >= 2) { |
740 Handle<Object> ms = args.at<Object>(2); | 739 Handle<Object> ms = args.at(2); |
741 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); | 740 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms, Object::ToNumber(ms)); |
742 milli = ms->Number(); | 741 milli = ms->Number(); |
743 } | 742 } |
744 time_val = MakeDate(day, MakeTime(h, m, s, milli)); | 743 time_val = MakeDate(day, MakeTime(h, m, s, milli)); |
745 } | 744 } |
746 return *JSDate::SetValue(date, TimeClip(time_val)); | 745 return *JSDate::SetValue(date, TimeClip(time_val)); |
747 } | 746 } |
748 | 747 |
749 // ES6 section 20.3.4.35 Date.prototype.toDateString ( ) | 748 // ES6 section 20.3.4.35 Date.prototype.toDateString ( ) |
750 BUILTIN(DatePrototypeToDateString) { | 749 BUILTIN(DatePrototypeToDateString) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 HandleScope scope(isolate); | 829 HandleScope scope(isolate); |
831 CHECK_RECEIVER(JSDate, date, "Date.prototype.valueOf"); | 830 CHECK_RECEIVER(JSDate, date, "Date.prototype.valueOf"); |
832 return date->value(); | 831 return date->value(); |
833 } | 832 } |
834 | 833 |
835 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) | 834 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) |
836 BUILTIN(DatePrototypeToPrimitive) { | 835 BUILTIN(DatePrototypeToPrimitive) { |
837 HandleScope scope(isolate); | 836 HandleScope scope(isolate); |
838 DCHECK_EQ(2, args.length()); | 837 DCHECK_EQ(2, args.length()); |
839 CHECK_RECEIVER(JSReceiver, receiver, "Date.prototype [ @@toPrimitive ]"); | 838 CHECK_RECEIVER(JSReceiver, receiver, "Date.prototype [ @@toPrimitive ]"); |
840 Handle<Object> hint = args.at<Object>(1); | 839 Handle<Object> hint = args.at(1); |
841 RETURN_RESULT_OR_FAILURE(isolate, JSDate::ToPrimitive(receiver, hint)); | 840 RETURN_RESULT_OR_FAILURE(isolate, JSDate::ToPrimitive(receiver, hint)); |
842 } | 841 } |
843 | 842 |
844 // ES6 section B.2.4.1 Date.prototype.getYear ( ) | 843 // ES6 section B.2.4.1 Date.prototype.getYear ( ) |
845 BUILTIN(DatePrototypeGetYear) { | 844 BUILTIN(DatePrototypeGetYear) { |
846 HandleScope scope(isolate); | 845 HandleScope scope(isolate); |
847 CHECK_RECEIVER(JSDate, date, "Date.prototype.getYear"); | 846 CHECK_RECEIVER(JSDate, date, "Date.prototype.getYear"); |
848 double time_val = date->value()->Number(); | 847 double time_val = date->value()->Number(); |
849 if (std::isnan(time_val)) return date->value(); | 848 if (std::isnan(time_val)) return date->value(); |
850 int64_t time_ms = static_cast<int64_t>(time_val); | 849 int64_t time_ms = static_cast<int64_t>(time_val); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 | 1088 |
1090 // static | 1089 // static |
1091 void Builtins::Generate_DatePrototypeGetUTCSeconds( | 1090 void Builtins::Generate_DatePrototypeGetUTCSeconds( |
1092 compiler::CodeAssemblerState* state) { | 1091 compiler::CodeAssemblerState* state) { |
1093 CodeStubAssembler assembler(state); | 1092 CodeStubAssembler assembler(state); |
1094 Generate_DatePrototype_GetField(&assembler, JSDate::kSecondUTC); | 1093 Generate_DatePrototype_GetField(&assembler, JSDate::kSecondUTC); |
1095 } | 1094 } |
1096 | 1095 |
1097 } // namespace internal | 1096 } // namespace internal |
1098 } // namespace v8 | 1097 } // namespace v8 |
OLD | NEW |