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-arguments.h" | 7 #include "src/api-arguments.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 3095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3106 } | 3106 } |
3107 | 3107 |
3108 } // namespace | 3108 } // namespace |
3109 | 3109 |
3110 | 3110 |
3111 // ES6 section 20.3.2 The Date Constructor for the [[Call]] case. | 3111 // ES6 section 20.3.2 The Date Constructor for the [[Call]] case. |
3112 BUILTIN(DateConstructor) { | 3112 BUILTIN(DateConstructor) { |
3113 HandleScope scope(isolate); | 3113 HandleScope scope(isolate); |
3114 double const time_val = JSDate::CurrentTimeValue(isolate); | 3114 double const time_val = JSDate::CurrentTimeValue(isolate); |
3115 char buffer[128]; | 3115 char buffer[128]; |
3116 Vector<char> str(buffer, arraysize(buffer)); | 3116 ToDateString(time_val, ArrayVector(buffer), isolate->date_cache()); |
3117 ToDateString(time_val, str, isolate->date_cache()); | |
3118 Handle<String> result; | 3117 Handle<String> result; |
3119 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3118 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
3120 isolate, result, | 3119 isolate, result, |
3121 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | 3120 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
3122 return *result; | 3121 return *result; |
3123 } | 3122 } |
3124 | 3123 |
3125 | 3124 |
3126 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. | 3125 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. |
3127 BUILTIN(DateConstructor_ConstructStub) { | 3126 BUILTIN(DateConstructor_ConstructStub) { |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3690 } | 3689 } |
3691 return *JSDate::SetValue(date, TimeClip(time_val)); | 3690 return *JSDate::SetValue(date, TimeClip(time_val)); |
3692 } | 3691 } |
3693 | 3692 |
3694 | 3693 |
3695 // ES6 section 20.3.4.35 Date.prototype.toDateString ( ) | 3694 // ES6 section 20.3.4.35 Date.prototype.toDateString ( ) |
3696 BUILTIN(DatePrototypeToDateString) { | 3695 BUILTIN(DatePrototypeToDateString) { |
3697 HandleScope scope(isolate); | 3696 HandleScope scope(isolate); |
3698 CHECK_RECEIVER(JSDate, date, "Date.prototype.toDateString"); | 3697 CHECK_RECEIVER(JSDate, date, "Date.prototype.toDateString"); |
3699 char buffer[128]; | 3698 char buffer[128]; |
3700 Vector<char> str(buffer, arraysize(buffer)); | 3699 ToDateString(date->value()->Number(), ArrayVector(buffer), |
3701 ToDateString(date->value()->Number(), str, isolate->date_cache(), kDateOnly); | 3700 isolate->date_cache(), kDateOnly); |
3702 Handle<String> result; | 3701 Handle<String> result; |
3703 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3702 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
3704 isolate, result, | 3703 isolate, result, |
3705 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | 3704 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
3706 return *result; | 3705 return *result; |
3707 } | 3706 } |
3708 | 3707 |
3709 | 3708 |
3710 // ES6 section 20.3.4.36 Date.prototype.toISOString ( ) | 3709 // ES6 section 20.3.4.36 Date.prototype.toISOString ( ) |
3711 BUILTIN(DatePrototypeToISOString) { | 3710 BUILTIN(DatePrototypeToISOString) { |
3712 HandleScope scope(isolate); | 3711 HandleScope scope(isolate); |
3713 CHECK_RECEIVER(JSDate, date, "Date.prototype.toISOString"); | 3712 CHECK_RECEIVER(JSDate, date, "Date.prototype.toISOString"); |
3714 double const time_val = date->value()->Number(); | 3713 double const time_val = date->value()->Number(); |
3715 if (std::isnan(time_val)) { | 3714 if (std::isnan(time_val)) { |
3716 THROW_NEW_ERROR_RETURN_FAILURE( | 3715 THROW_NEW_ERROR_RETURN_FAILURE( |
3717 isolate, NewRangeError(MessageTemplate::kInvalidTimeValue)); | 3716 isolate, NewRangeError(MessageTemplate::kInvalidTimeValue)); |
3718 } | 3717 } |
3719 int64_t const time_ms = static_cast<int64_t>(time_val); | 3718 int64_t const time_ms = static_cast<int64_t>(time_val); |
3720 int year, month, day, weekday, hour, min, sec, ms; | 3719 int year, month, day, weekday, hour, min, sec, ms; |
3721 isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday, | 3720 isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday, |
3722 &hour, &min, &sec, &ms); | 3721 &hour, &min, &sec, &ms); |
3723 char buffer[128]; | 3722 char buffer[128]; |
3724 Vector<char> str(buffer, arraysize(buffer)); | |
3725 if (year >= 0 && year <= 9999) { | 3723 if (year >= 0 && year <= 9999) { |
3726 SNPrintF(str, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, month + 1, day, | 3724 SNPrintF(ArrayVector(buffer), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, |
3727 hour, min, sec, ms); | 3725 month + 1, day, hour, min, sec, ms); |
3728 } else if (year < 0) { | 3726 } else if (year < 0) { |
3729 SNPrintF(str, "-%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", -year, month + 1, day, | 3727 SNPrintF(ArrayVector(buffer), "-%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", -year, |
3730 hour, min, sec, ms); | 3728 month + 1, day, hour, min, sec, ms); |
3731 } else { | 3729 } else { |
3732 SNPrintF(str, "+%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, month + 1, day, | 3730 SNPrintF(ArrayVector(buffer), "+%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, |
3733 hour, min, sec, ms); | 3731 month + 1, day, hour, min, sec, ms); |
3734 } | 3732 } |
3735 return *isolate->factory()->NewStringFromAsciiChecked(str.start()); | 3733 return *isolate->factory()->NewStringFromAsciiChecked(buffer); |
3736 } | 3734 } |
3737 | 3735 |
3738 | 3736 |
3739 // ES6 section 20.3.4.41 Date.prototype.toString ( ) | 3737 // ES6 section 20.3.4.41 Date.prototype.toString ( ) |
3740 BUILTIN(DatePrototypeToString) { | 3738 BUILTIN(DatePrototypeToString) { |
3741 HandleScope scope(isolate); | 3739 HandleScope scope(isolate); |
3742 CHECK_RECEIVER(JSDate, date, "Date.prototype.toString"); | 3740 CHECK_RECEIVER(JSDate, date, "Date.prototype.toString"); |
3743 char buffer[128]; | 3741 char buffer[128]; |
3744 Vector<char> str(buffer, arraysize(buffer)); | 3742 ToDateString(date->value()->Number(), ArrayVector(buffer), |
3745 ToDateString(date->value()->Number(), str, isolate->date_cache()); | 3743 isolate->date_cache()); |
3746 Handle<String> result; | 3744 Handle<String> result; |
3747 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3745 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
3748 isolate, result, | 3746 isolate, result, |
3749 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | 3747 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
3750 return *result; | 3748 return *result; |
3751 } | 3749 } |
3752 | 3750 |
3753 | 3751 |
3754 // ES6 section 20.3.4.42 Date.prototype.toTimeString ( ) | 3752 // ES6 section 20.3.4.42 Date.prototype.toTimeString ( ) |
3755 BUILTIN(DatePrototypeToTimeString) { | 3753 BUILTIN(DatePrototypeToTimeString) { |
3756 HandleScope scope(isolate); | 3754 HandleScope scope(isolate); |
3757 CHECK_RECEIVER(JSDate, date, "Date.prototype.toTimeString"); | 3755 CHECK_RECEIVER(JSDate, date, "Date.prototype.toTimeString"); |
3758 char buffer[128]; | 3756 char buffer[128]; |
3759 Vector<char> str(buffer, arraysize(buffer)); | 3757 ToDateString(date->value()->Number(), ArrayVector(buffer), |
3760 ToDateString(date->value()->Number(), str, isolate->date_cache(), kTimeOnly); | 3758 isolate->date_cache(), kTimeOnly); |
3761 Handle<String> result; | 3759 Handle<String> result; |
3762 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3760 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
3763 isolate, result, | 3761 isolate, result, |
3764 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | 3762 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
3765 return *result; | 3763 return *result; |
3766 } | 3764 } |
3767 | 3765 |
3768 | 3766 |
3769 // ES6 section 20.3.4.43 Date.prototype.toUTCString ( ) | 3767 // ES6 section 20.3.4.43 Date.prototype.toUTCString ( ) |
3770 BUILTIN(DatePrototypeToUTCString) { | 3768 BUILTIN(DatePrototypeToUTCString) { |
3771 HandleScope scope(isolate); | 3769 HandleScope scope(isolate); |
3772 CHECK_RECEIVER(JSDate, date, "Date.prototype.toUTCString"); | 3770 CHECK_RECEIVER(JSDate, date, "Date.prototype.toUTCString"); |
3773 double const time_val = date->value()->Number(); | 3771 double const time_val = date->value()->Number(); |
3774 if (std::isnan(time_val)) { | 3772 if (std::isnan(time_val)) { |
3775 return *isolate->factory()->NewStringFromAsciiChecked("Invalid Date"); | 3773 return *isolate->factory()->NewStringFromAsciiChecked("Invalid Date"); |
3776 } | 3774 } |
3777 char buffer[128]; | 3775 char buffer[128]; |
3778 Vector<char> str(buffer, arraysize(buffer)); | |
3779 int64_t time_ms = static_cast<int64_t>(time_val); | 3776 int64_t time_ms = static_cast<int64_t>(time_val); |
3780 int year, month, day, weekday, hour, min, sec, ms; | 3777 int year, month, day, weekday, hour, min, sec, ms; |
3781 isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday, | 3778 isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday, |
3782 &hour, &min, &sec, &ms); | 3779 &hour, &min, &sec, &ms); |
3783 SNPrintF(str, "%s, %02d %s %4d %02d:%02d:%02d GMT", kShortWeekDays[weekday], | 3780 SNPrintF(ArrayVector(buffer), "%s, %02d %s %4d %02d:%02d:%02d GMT", |
3784 day, kShortMonths[month], year, hour, min, sec); | 3781 kShortWeekDays[weekday], day, kShortMonths[month], year, hour, min, |
3785 return *isolate->factory()->NewStringFromAsciiChecked(str.start()); | 3782 sec); |
| 3783 return *isolate->factory()->NewStringFromAsciiChecked(buffer); |
3786 } | 3784 } |
3787 | 3785 |
3788 | 3786 |
3789 // ES6 section 20.3.4.44 Date.prototype.valueOf ( ) | 3787 // ES6 section 20.3.4.44 Date.prototype.valueOf ( ) |
3790 BUILTIN(DatePrototypeValueOf) { | 3788 BUILTIN(DatePrototypeValueOf) { |
3791 HandleScope scope(isolate); | 3789 HandleScope scope(isolate); |
3792 CHECK_RECEIVER(JSDate, date, "Date.prototype.valueOf"); | 3790 CHECK_RECEIVER(JSDate, date, "Date.prototype.valueOf"); |
3793 return date->value(); | 3791 return date->value(); |
3794 } | 3792 } |
3795 | 3793 |
(...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5395 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 5393 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
5396 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 5394 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
5397 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 5395 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
5398 #undef DEFINE_BUILTIN_ACCESSOR_C | 5396 #undef DEFINE_BUILTIN_ACCESSOR_C |
5399 #undef DEFINE_BUILTIN_ACCESSOR_A | 5397 #undef DEFINE_BUILTIN_ACCESSOR_A |
5400 #undef DEFINE_BUILTIN_ACCESSOR_T | 5398 #undef DEFINE_BUILTIN_ACCESSOR_T |
5401 #undef DEFINE_BUILTIN_ACCESSOR_H | 5399 #undef DEFINE_BUILTIN_ACCESSOR_H |
5402 | 5400 |
5403 } // namespace internal | 5401 } // namespace internal |
5404 } // namespace v8 | 5402 } // namespace v8 |
OLD | NEW |