Commit 251f63d8 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[builtins] Remove DateConstructor_ConstructStub builtin.

Next step on deprecating the construct_stub field in the
SharedFunctionInfo.

Bug: v8:7503
Change-Id: Ibcbf9dc0dbcbcf0e26c103167e8a30074cbdd888
Reviewed-on: https://chromium-review.googlesource.com/940942Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51630}
parent f8c688f4
...@@ -2187,7 +2187,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2187,7 +2187,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
InstallWithIntrinsicDefaultProto(isolate, date_fun, InstallWithIntrinsicDefaultProto(isolate, date_fun,
Context::DATE_FUNCTION_INDEX); Context::DATE_FUNCTION_INDEX);
date_fun->shared()->SetConstructStub( date_fun->shared()->SetConstructStub(
*BUILTIN_CODE(isolate, DateConstructor_ConstructStub)); *BUILTIN_CODE(isolate, JSBuiltinsConstructStub));
date_fun->shared()->set_length(7); date_fun->shared()->set_length(7);
date_fun->shared()->DontAdaptArguments(); date_fun->shared()->DontAdaptArguments();
......
...@@ -193,95 +193,94 @@ Object* SetLocalDateValue(Handle<JSDate> date, double time_val) { ...@@ -193,95 +193,94 @@ Object* SetLocalDateValue(Handle<JSDate> date, double time_val) {
} // namespace } // namespace
// ES6 section 20.3.2 The Date Constructor for the [[Call]] case. // ES #sec-date-constructor
BUILTIN(DateConstructor) { BUILTIN(DateConstructor) {
HandleScope scope(isolate); HandleScope scope(isolate);
double const time_val = JSDate::CurrentTimeValue(isolate); if (args.new_target()->IsUndefined(isolate)) {
char buffer[128]; double const time_val = JSDate::CurrentTimeValue(isolate);
ToDateString(time_val, ArrayVector(buffer), isolate->date_cache()); char buffer[128];
RETURN_RESULT_OR_FAILURE( ToDateString(time_val, ArrayVector(buffer), isolate->date_cache());
isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); RETURN_RESULT_OR_FAILURE(
} isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer)));
} else {
// ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. int const argc = args.length() - 1;
BUILTIN(DateConstructor_ConstructStub) { Handle<JSFunction> target = args.target();
HandleScope scope(isolate); Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
int const argc = args.length() - 1; double time_val;
Handle<JSFunction> target = args.target(); if (argc == 0) {
Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); time_val = JSDate::CurrentTimeValue(isolate);
double time_val; } else if (argc == 1) {
if (argc == 0) { Handle<Object> value = args.at(1);
time_val = JSDate::CurrentTimeValue(isolate); if (value->IsJSDate()) {
} else if (argc == 1) { time_val = Handle<JSDate>::cast(value)->value()->Number();
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(Handle<String>::cast(value));
} else { } else {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value,
Object::ToNumber(value)); Object::ToPrimitive(value));
time_val = value->Number(); if (value->IsString()) {
time_val = ParseDateTimeString(Handle<String>::cast(value));
} else {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value,
Object::ToNumber(value));
time_val = value->Number();
}
} }
} } else {
} else { Handle<Object> year_object;
Handle<Object> year_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object,
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, year_object, Object::ToNumber(args.at(1)));
Object::ToNumber(args.at(1))); Handle<Object> month_object;
Handle<Object> month_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month_object,
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, month_object, Object::ToNumber(args.at(2)));
Object::ToNumber(args.at(2))); double year = year_object->Number();
double year = year_object->Number(); double month = month_object->Number();
double month = month_object->Number(); double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0;
double date = 1.0, hours = 0.0, minutes = 0.0, seconds = 0.0, ms = 0.0; if (argc >= 3) {
if (argc >= 3) { Handle<Object> date_object;
Handle<Object> date_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date_object,
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, date_object, Object::ToNumber(args.at(3)));
Object::ToNumber(args.at(3))); date = date_object->Number();
date = date_object->Number(); if (argc >= 4) {
if (argc >= 4) { Handle<Object> hours_object;
Handle<Object> hours_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hours_object,
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, hours_object, Object::ToNumber(args.at(4)));
Object::ToNumber(args.at(4))); hours = hours_object->Number();
hours = hours_object->Number(); if (argc >= 5) {
if (argc >= 5) { Handle<Object> minutes_object;
Handle<Object> minutes_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, minutes_object,
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, minutes_object, Object::ToNumber(args.at(5)));
Object::ToNumber(args.at(5))); minutes = minutes_object->Number();
minutes = minutes_object->Number(); if (argc >= 6) {
if (argc >= 6) { Handle<Object> seconds_object;
Handle<Object> seconds_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, seconds_object,
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, seconds_object, Object::ToNumber(args.at(6)));
Object::ToNumber(args.at(6))); seconds = seconds_object->Number();
seconds = seconds_object->Number(); if (argc >= 7) {
if (argc >= 7) { Handle<Object> ms_object;
Handle<Object> ms_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, ms_object, isolate, ms_object, Object::ToNumber(args.at(7)));
Object::ToNumber(args.at(7))); ms = ms_object->Number();
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();
}
} }
if (!std::isnan(year)) { RETURN_RESULT_OR_FAILURE(isolate,
double const y = DoubleToInteger(year); JSDate::New(target, new_target, time_val));
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 ( ) // ES6 section 20.3.3.1 Date.now ( )
......
...@@ -461,8 +461,8 @@ namespace internal { ...@@ -461,8 +461,8 @@ namespace internal {
CPP(DataViewPrototypeSetBigUint64) \ CPP(DataViewPrototypeSetBigUint64) \
\ \
/* Date */ \ /* Date */ \
/* ES #sec-date-constructor */ \
CPP(DateConstructor) \ CPP(DateConstructor) \
CPP(DateConstructor_ConstructStub) \
/* ES6 #sec-date.prototype.getdate */ \ /* ES6 #sec-date.prototype.getdate */ \
TFJ(DatePrototypeGetDate, 0) \ TFJ(DatePrototypeGetDate, 0) \
/* ES6 #sec-date.prototype.getday */ \ /* ES6 #sec-date.prototype.getday */ \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment