diff options
Diffstat (limited to 'deps/v8/src/builtins/builtins-date.cc')
-rw-r--r-- | deps/v8/src/builtins/builtins-date.cc | 134 |
1 files changed, 66 insertions, 68 deletions
diff --git a/deps/v8/src/builtins/builtins-date.cc b/deps/v8/src/builtins/builtins-date.cc index 0669963a099..569a5807e22 100644 --- a/deps/v8/src/builtins/builtins-date.cc +++ b/deps/v8/src/builtins/builtins-date.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/builtins/builtins-utils.h" +#include "src/builtins/builtins-utils-inl.h" #include "src/builtins/builtins.h" #include "src/code-factory.h" #include "src/code-stub-assembler.h" @@ -195,86 +195,84 @@ BUILTIN(DateConstructor) { ToDateString(time_val, ArrayVector(buffer), isolate->date_cache()); RETURN_RESULT_OR_FAILURE( isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); - } else { - int const argc = args.length() - 1; - Handle<JSFunction> target = args.target(); - Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); - double time_val; - if (argc == 0) { - time_val = JSDate::CurrentTimeValue(isolate); - } else if (argc == 1) { - Handle<Object> value = args.at(1); - if (value->IsJSDate()) { - time_val = Handle<JSDate>::cast(value)->value()->Number(); + } + // [Construct] + int const argc = args.length() - 1; + Handle<JSFunction> target = args.target(); + Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); + double time_val; + if (argc == 0) { + time_val = JSDate::CurrentTimeValue(isolate); + } else if (argc == 1) { + Handle<Object> value = args.at(1); + if (value->IsJSDate()) { + time_val = Handle<JSDate>::cast(value)->value()->Number(); + } else { + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, + Object::ToPrimitive(value)); + if (value->IsString()) { + time_val = ParseDateTimeString(isolate, Handle<String>::cast(value)); } else { ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, - Object::ToPrimitive(value)); - if (value->IsString()) { - time_val = ParseDateTimeString(isolate, Handle<String>::cast(value)); - } else { - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, - Object::ToNumber(isolate, value)); - time_val = value->Number(); - } + Object::ToNumber(isolate, value)); + time_val = value->Number(); } - } else { - Handle<Object> year_object; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, - Object::ToNumber(isolate, args.at(1))); - Handle<Object> month_object; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month_object, - Object::ToNumber(isolate, args.at(2))); - double year = year_object->Number(); - double month = month_object->Number(); - double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; - if (argc >= 3) { - Handle<Object> date_object; + } + } else { + Handle<Object> year_object; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, + Object::ToNumber(isolate, args.at(1))); + Handle<Object> month_object; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month_object, + Object::ToNumber(isolate, args.at(2))); + double year = year_object->Number(); + double month = month_object->Number(); + double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; + if (argc >= 3) { + Handle<Object> date_object; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date_object, + Object::ToNumber(isolate, args.at(3))); + date = date_object->Number(); + if (argc >= 4) { + Handle<Object> hours_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, date_object, Object::ToNumber(isolate, args.at(3))); - date = date_object->Number(); - if (argc >= 4) { - Handle<Object> hours_object; + isolate, hours_object, Object::ToNumber(isolate, args.at(4))); + hours = hours_object->Number(); + if (argc >= 5) { + Handle<Object> minutes_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, hours_object, Object::ToNumber(isolate, args.at(4))); - hours = hours_object->Number(); - if (argc >= 5) { - Handle<Object> minutes_object; + isolate, minutes_object, Object::ToNumber(isolate, args.at(5))); + minutes = minutes_object->Number(); + if (argc >= 6) { + Handle<Object> seconds_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, minutes_object, Object::ToNumber(isolate, args.at(5))); - minutes = minutes_object->Number(); - if (argc >= 6) { - Handle<Object> seconds_object; + isolate, seconds_object, Object::ToNumber(isolate, args.at(6))); + seconds = seconds_object->Number(); + if (argc >= 7) { + Handle<Object> ms_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, seconds_object, - Object::ToNumber(isolate, args.at(6))); - seconds = seconds_object->Number(); - if (argc >= 7) { - Handle<Object> ms_object; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, ms_object, Object::ToNumber(isolate, args.at(7))); - ms = ms_object->Number(); - } + isolate, ms_object, Object::ToNumber(isolate, args.at(7))); + ms = ms_object->Number(); } } } } - if (!std::isnan(year)) { - double const y = DoubleToInteger(year); - if (0.0 <= y && y <= 99) year = 1900 + y; - } - double const day = MakeDay(year, month, date); - double const time = MakeTime(hours, minutes, seconds, ms); - time_val = MakeDate(day, time); - if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs && - time_val <= DateCache::kMaxTimeBeforeUTCInMs) { - time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val)); - } else { - time_val = std::numeric_limits<double>::quiet_NaN(); - } } - RETURN_RESULT_OR_FAILURE(isolate, - JSDate::New(target, new_target, time_val)); + if (!std::isnan(year)) { + double const y = DoubleToInteger(year); + if (0.0 <= y && y <= 99) year = 1900 + y; + } + double const day = MakeDay(year, month, date); + double const time = MakeTime(hours, minutes, seconds, ms); + time_val = MakeDate(day, time); + if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs && + time_val <= DateCache::kMaxTimeBeforeUTCInMs) { + time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val)); + } else { + time_val = std::numeric_limits<double>::quiet_NaN(); + } } + RETURN_RESULT_OR_FAILURE(isolate, JSDate::New(target, new_target, time_val)); } // ES6 section 20.3.3.1 Date.now ( ) |