Move date-related files
R=bmeurer@chromium.org, ishell@chromium.org, jshin@chromium.org, ulan@chromium.org Bug: v8:9247 Change-Id: I67b591b613dd066f441e63fd61952728f4036636 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1613247 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Igor Sheludko <ishell@chromium.org> Commit-Queue: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#61532}
This commit is contained in:
parent
a3187716d3
commit
c39cabbcbe
10
BUILD.gn
10
BUILD.gn
@ -2136,11 +2136,11 @@ v8_source_set("v8_base_without_compiler") {
|
||||
"src/counters.cc",
|
||||
"src/counters.h",
|
||||
"src/cpu-features.h",
|
||||
"src/date.cc",
|
||||
"src/date.h",
|
||||
"src/dateparser-inl.h",
|
||||
"src/dateparser.cc",
|
||||
"src/dateparser.h",
|
||||
"src/date/date.cc",
|
||||
"src/date/date.h",
|
||||
"src/date/dateparser-inl.h",
|
||||
"src/date/dateparser.cc",
|
||||
"src/date/dateparser.h",
|
||||
"src/debug/debug-coverage.cc",
|
||||
"src/debug/debug-coverage.h",
|
||||
"src/debug/debug-evaluate.cc",
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "src/conversions-inl.h"
|
||||
#include "src/counters.h"
|
||||
#include "src/cpu-features.h"
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/debug/debug-coverage.h"
|
||||
#include "src/debug/debug-evaluate.h"
|
||||
#include "src/debug/debug-type-profile.h"
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include "src/code-factory.h"
|
||||
#include "src/conversions.h"
|
||||
#include "src/counters.h"
|
||||
#include "src/date.h"
|
||||
#include "src/dateparser-inl.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/date/dateparser-inl.h"
|
||||
#include "src/objects-inl.h"
|
||||
#ifdef V8_INTL_SUPPORT
|
||||
#include "src/objects/intl-objects.h"
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "src/builtins/builtins-utils-inl.h"
|
||||
#include "src/builtins/builtins.h"
|
||||
#include "src/counters.h"
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/elements.h"
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/objects/intl-objects.h"
|
||||
|
@ -6,7 +6,7 @@
|
||||
#define V8_COMPILER_TYPE_CACHE_H_
|
||||
|
||||
#include "src/compiler/types.h"
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/objects/code.h"
|
||||
#include "src/objects/js-array-buffer.h"
|
||||
#include "src/objects/string.h"
|
||||
|
3
src/date/OWNERS
Normal file
3
src/date/OWNERS
Normal file
@ -0,0 +1,3 @@
|
||||
ishell@chromium.org
|
||||
jshin@chromium.org
|
||||
ulan@chromium.org
|
@ -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/date.h"
|
||||
#include "src/date/date.h"
|
||||
|
||||
#include "src/base/overflowing-math.h"
|
||||
#include "src/conversions.h"
|
||||
@ -14,16 +14,15 @@
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
|
||||
static const int kDaysIn4Years = 4 * 365 + 1;
|
||||
static const int kDaysIn100Years = 25 * kDaysIn4Years - 1;
|
||||
static const int kDaysIn400Years = 4 * kDaysIn100Years + 1;
|
||||
static const int kDays1970to2000 = 30 * 365 + 7;
|
||||
static const int kDaysOffset = 1000 * kDaysIn400Years + 5 * kDaysIn400Years -
|
||||
kDays1970to2000;
|
||||
static const int kDaysOffset =
|
||||
1000 * kDaysIn400Years + 5 * kDaysIn400Years - kDays1970to2000;
|
||||
static const int kYearsOffset = 400000;
|
||||
static const char kDaysInMonths[] =
|
||||
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
static const char kDaysInMonths[] = {31, 28, 31, 30, 31, 30,
|
||||
31, 31, 30, 31, 30, 31};
|
||||
|
||||
DateCache::DateCache()
|
||||
: stamp_(kNullAddress),
|
||||
@ -33,7 +32,7 @@ DateCache::DateCache()
|
||||
#else
|
||||
base::OS::CreateTimezoneCache()
|
||||
#endif
|
||||
) {
|
||||
) {
|
||||
ResetDateCache(base::TimezoneCache::TimeZoneDetection::kSkip);
|
||||
}
|
||||
|
||||
@ -79,9 +78,8 @@ void DateCache::ClearSegment(DST* segment) {
|
||||
segment->last_used = 0;
|
||||
}
|
||||
|
||||
|
||||
void DateCache::YearMonthDayFromDays(
|
||||
int days, int* year, int* month, int* day) {
|
||||
void DateCache::YearMonthDayFromDays(int days, int* year, int* month,
|
||||
int* day) {
|
||||
if (ymd_valid_) {
|
||||
// Check conservatively if the given 'days' has
|
||||
// the same year and month as the cached 'days'.
|
||||
@ -118,7 +116,6 @@ void DateCache::YearMonthDayFromDays(
|
||||
days %= 365;
|
||||
*year += yd3;
|
||||
|
||||
|
||||
bool is_leap = (!yd1 || yd2) && !yd3;
|
||||
|
||||
DCHECK_GE(days, -1);
|
||||
@ -160,11 +157,10 @@ void DateCache::YearMonthDayFromDays(
|
||||
ymd_days_ = save_days;
|
||||
}
|
||||
|
||||
|
||||
int DateCache::DaysFromYearMonth(int year, int month) {
|
||||
static const int day_from_month[] = {0, 31, 59, 90, 120, 151,
|
||||
static const int day_from_month[] = {0, 31, 59, 90, 120, 151,
|
||||
181, 212, 243, 273, 304, 334};
|
||||
static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152,
|
||||
static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152,
|
||||
182, 213, 244, 274, 305, 335};
|
||||
|
||||
year += month / 12;
|
||||
@ -186,17 +182,13 @@ int DateCache::DaysFromYearMonth(int year, int month) {
|
||||
// c) there shouldn't be an overflow for 32-bit integers in the following
|
||||
// operations.
|
||||
static const int year_delta = 399999;
|
||||
static const int base_day = 365 * (1970 + year_delta) +
|
||||
(1970 + year_delta) / 4 -
|
||||
(1970 + year_delta) / 100 +
|
||||
(1970 + year_delta) / 400;
|
||||
static const int base_day =
|
||||
365 * (1970 + year_delta) + (1970 + year_delta) / 4 -
|
||||
(1970 + year_delta) / 100 + (1970 + year_delta) / 400;
|
||||
|
||||
int year1 = year + year_delta;
|
||||
int day_from_year = 365 * year1 +
|
||||
year1 / 4 -
|
||||
year1 / 100 +
|
||||
year1 / 400 -
|
||||
base_day;
|
||||
int day_from_year =
|
||||
365 * year1 + year1 / 4 - year1 / 100 + year1 / 400 - base_day;
|
||||
|
||||
if ((year % 4 != 0) || (year % 100 == 0 && year % 400 != 0)) {
|
||||
return day_from_year + day_from_month[month];
|
||||
@ -204,7 +196,6 @@ int DateCache::DaysFromYearMonth(int year, int month) {
|
||||
return day_from_year + day_from_month_leap[month];
|
||||
}
|
||||
|
||||
|
||||
void DateCache::BreakDownTime(int64_t time_ms, int* year, int* month, int* day,
|
||||
int* weekday, int* hour, int* min, int* sec,
|
||||
int* ms) {
|
||||
@ -302,11 +293,10 @@ void DateCache::ExtendTheAfterSegment(int time_sec, int offset_ms) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int DateCache::DaylightSavingsOffsetInMs(int64_t time_ms) {
|
||||
int time_sec = (time_ms >= 0 && time_ms <= kMaxEpochTimeInMs)
|
||||
? static_cast<int>(time_ms / 1000)
|
||||
: static_cast<int>(EquivalentTime(time_ms) / 1000);
|
||||
? static_cast<int>(time_ms / 1000)
|
||||
: static_cast<int>(EquivalentTime(time_ms) / 1000);
|
||||
|
||||
// Invalidate cache if the usage counter is close to overflow.
|
||||
// Note that dst_usage_counter is incremented less than ten times
|
||||
@ -319,8 +309,7 @@ int DateCache::DaylightSavingsOffsetInMs(int64_t time_ms) {
|
||||
}
|
||||
|
||||
// Optimistic fast check.
|
||||
if (before_->start_sec <= time_sec &&
|
||||
time_sec <= before_->end_sec) {
|
||||
if (before_->start_sec <= time_sec && time_sec <= before_->end_sec) {
|
||||
// Cache hit.
|
||||
before_->last_used = ++dst_usage_counter_;
|
||||
return before_->offset_ms;
|
||||
@ -414,7 +403,6 @@ int DateCache::DaylightSavingsOffsetInMs(int64_t time_ms) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void DateCache::ProbeDST(int time_sec) {
|
||||
DST* before = nullptr;
|
||||
DST* after = nullptr;
|
||||
@ -439,7 +427,8 @@ void DateCache::ProbeDST(int time_sec) {
|
||||
}
|
||||
if (after == nullptr) {
|
||||
after = InvalidSegment(after_) && before != after_
|
||||
? after_ : LeastRecentlyUsedDST(before);
|
||||
? after_
|
||||
: LeastRecentlyUsedDST(before);
|
||||
}
|
||||
|
||||
DCHECK_NOT_NULL(before);
|
||||
@ -454,7 +443,6 @@ void DateCache::ProbeDST(int time_sec) {
|
||||
after_ = after;
|
||||
}
|
||||
|
||||
|
||||
DateCache::DST* DateCache::LeastRecentlyUsedDST(DST* skip) {
|
||||
DST* result = nullptr;
|
||||
for (int i = 0; i < kDSTSize; ++i) {
|
@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_DATE_H_
|
||||
#define V8_DATE_H_
|
||||
#ifndef V8_DATE_DATE_H_
|
||||
#define V8_DATE_DATE_H_
|
||||
|
||||
#include "src/base/timezone-cache.h"
|
||||
#include "src/globals.h"
|
||||
@ -21,8 +21,7 @@ class V8_EXPORT_PRIVATE DateCache {
|
||||
|
||||
// The largest time that can be passed to OS date-time library functions.
|
||||
static const int kMaxEpochTimeInSec = kMaxInt;
|
||||
static const int64_t kMaxEpochTimeInMs =
|
||||
static_cast<int64_t>(kMaxInt) * 1000;
|
||||
static const int64_t kMaxEpochTimeInMs = static_cast<int64_t>(kMaxInt) * 1000;
|
||||
|
||||
// The largest time that can be stored in JSDate.
|
||||
static const int64_t kMaxTimeInMs =
|
||||
@ -55,7 +54,6 @@ class V8_EXPORT_PRIVATE DateCache {
|
||||
return static_cast<int>(time_ms / kMsPerDay);
|
||||
}
|
||||
|
||||
|
||||
// Computes modulo(time_ms, kMsPerDay) given that
|
||||
// days = floor(time_ms / kMsPerDay).
|
||||
static int TimeInDay(int64_t time_ms, int days) {
|
||||
@ -72,7 +70,6 @@ class V8_EXPORT_PRIVATE DateCache {
|
||||
return result >= 0 ? result : result + 7;
|
||||
}
|
||||
|
||||
|
||||
bool IsLeap(int year) {
|
||||
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
||||
}
|
||||
@ -82,7 +79,6 @@ class V8_EXPORT_PRIVATE DateCache {
|
||||
return GetLocalOffsetFromOS(time, is_utc);
|
||||
}
|
||||
|
||||
|
||||
const char* LocalTimezone(int64_t time_ms) {
|
||||
if (time_ms < 0 || time_ms > kMaxEpochTimeInMs) {
|
||||
time_ms = EquivalentTime(time_ms);
|
||||
@ -113,7 +109,6 @@ class V8_EXPORT_PRIVATE DateCache {
|
||||
return time_ms - LocalOffsetInMs(time_ms, false);
|
||||
}
|
||||
|
||||
|
||||
// Computes a time equivalent to the given time according
|
||||
// to ECMA 262 - 15.9.1.9.
|
||||
// The issue here is that some library calls don't work right for dates
|
||||
@ -244,4 +239,4 @@ class V8_EXPORT_PRIVATE DateCache {
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_DATE_H_
|
||||
#endif // V8_DATE_DATE_H_
|
@ -2,11 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_DATEPARSER_INL_H_
|
||||
#define V8_DATEPARSER_INL_H_
|
||||
#ifndef V8_DATE_DATEPARSER_INL_H_
|
||||
#define V8_DATE_DATEPARSER_INL_H_
|
||||
|
||||
#include "src/char-predicates-inl.h"
|
||||
#include "src/dateparser.h"
|
||||
#include "src/date/dateparser.h"
|
||||
#include "src/isolate.h"
|
||||
|
||||
namespace v8 {
|
||||
@ -75,8 +75,7 @@ bool DateParser::Parse(Isolate* isolate, Vector<Char> str, FixedArray out) {
|
||||
bool has_read_number = !day.IsEmpty();
|
||||
// If there's anything left, continue with the legacy parser.
|
||||
bool legacy_parser = false;
|
||||
for (DateToken token = next_unhandled_token;
|
||||
!token.IsEndOfInput();
|
||||
for (DateToken token = next_unhandled_token; !token.IsEndOfInput();
|
||||
token = scanner.Next()) {
|
||||
if (token.IsNumber()) {
|
||||
legacy_parser = true;
|
||||
@ -106,10 +105,9 @@ bool DateParser::Parse(Isolate* isolate, Vector<Char> str, FixedArray out) {
|
||||
// Require end, white space, "Z", "+" or "-" immediately after
|
||||
// finalizing time.
|
||||
DateToken peek = scanner.Peek();
|
||||
if (!peek.IsEndOfInput() &&
|
||||
!peek.IsWhiteSpace() &&
|
||||
!peek.IsKeywordZ() &&
|
||||
!peek.IsAsciiSign()) return false;
|
||||
if (!peek.IsEndOfInput() && !peek.IsWhiteSpace() &&
|
||||
!peek.IsKeywordZ() && !peek.IsAsciiSign())
|
||||
return false;
|
||||
} else {
|
||||
if (!day.Add(n)) return false;
|
||||
scanner.SkipSymbol('-');
|
||||
@ -181,7 +179,7 @@ bool DateParser::Parse(Isolate* isolate, Vector<Char> str, FixedArray out) {
|
||||
return success;
|
||||
}
|
||||
|
||||
template<typename CharType>
|
||||
template <typename CharType>
|
||||
DateParser::DateToken DateParser::DateStringTokenizer<CharType>::Scan() {
|
||||
int pre_pos = in_->position();
|
||||
if (in_->IsEnd()) return DateToken::EndOfInput();
|
||||
@ -201,8 +199,7 @@ DateParser::DateToken DateParser::DateStringTokenizer<CharType>::Scan() {
|
||||
int length = in_->ReadWord(buffer, 3);
|
||||
int index = KeywordTable::Lookup(buffer, length);
|
||||
return DateToken::Keyword(KeywordTable::GetType(index),
|
||||
KeywordTable::GetValue(index),
|
||||
length);
|
||||
KeywordTable::GetValue(index), length);
|
||||
}
|
||||
if (in_->SkipWhiteSpace()) {
|
||||
return DateToken::WhiteSpace(in_->position() - pre_pos);
|
||||
@ -214,7 +211,6 @@ DateParser::DateToken DateParser::DateStringTokenizer<CharType>::Scan() {
|
||||
return DateToken::Unknown();
|
||||
}
|
||||
|
||||
|
||||
template <typename Char>
|
||||
bool DateParser::InputReader<Char>::SkipWhiteSpace() {
|
||||
if (IsWhiteSpaceOrLineTerminator(ch_)) {
|
||||
@ -224,20 +220,20 @@ bool DateParser::InputReader<Char>::SkipWhiteSpace() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template <typename Char>
|
||||
bool DateParser::InputReader<Char>::SkipParentheses() {
|
||||
if (ch_ != '(') return false;
|
||||
int balance = 0;
|
||||
do {
|
||||
if (ch_ == ')') --balance;
|
||||
else if (ch_ == '(') ++balance;
|
||||
if (ch_ == ')')
|
||||
--balance;
|
||||
else if (ch_ == '(')
|
||||
++balance;
|
||||
Next();
|
||||
} while (balance > 0 && ch_);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <typename Char>
|
||||
DateParser::DateToken DateParser::ParseES5DateTime(
|
||||
DateStringTokenizer<Char>* scanner, DayComposer* day, TimeComposer* time,
|
||||
@ -263,11 +259,13 @@ DateParser::DateToken DateParser::ParseES5DateTime(
|
||||
}
|
||||
if (scanner->SkipSymbol('-')) {
|
||||
if (!scanner->Peek().IsFixedLengthNumber(2) ||
|
||||
!DayComposer::IsMonth(scanner->Peek().number())) return scanner->Next();
|
||||
!DayComposer::IsMonth(scanner->Peek().number()))
|
||||
return scanner->Next();
|
||||
day->Add(scanner->Next().number());
|
||||
if (scanner->SkipSymbol('-')) {
|
||||
if (!scanner->Peek().IsFixedLengthNumber(2) ||
|
||||
!DayComposer::IsDay(scanner->Peek().number())) return scanner->Next();
|
||||
!DayComposer::IsDay(scanner->Peek().number()))
|
||||
return scanner->Next();
|
||||
day->Add(scanner->Next().number());
|
||||
}
|
||||
}
|
||||
@ -311,8 +309,7 @@ DateParser::DateToken DateParser::ParseES5DateTime(
|
||||
if (scanner->Peek().IsKeywordZ()) {
|
||||
scanner->Next();
|
||||
tz->Set(0);
|
||||
} else if (scanner->Peek().IsSymbol('+') ||
|
||||
scanner->Peek().IsSymbol('-')) {
|
||||
} else if (scanner->Peek().IsSymbol('+') || scanner->Peek().IsSymbol('-')) {
|
||||
tz->SetSign(scanner->Next().symbol() == '+' ? 1 : -1);
|
||||
if (scanner->Peek().IsFixedLengthNumber(4)) {
|
||||
// hhmm extension syntax.
|
||||
@ -352,8 +349,7 @@ DateParser::DateToken DateParser::ParseES5DateTime(
|
||||
return DateToken::EndOfInput();
|
||||
}
|
||||
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_DATEPARSER_INL_H_
|
||||
#endif // V8_DATE_DATEPARSER_INL_H_
|
@ -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/dateparser.h"
|
||||
#include "src/date/dateparser.h"
|
||||
|
||||
#include "src/char-predicates-inl.h"
|
||||
#include "src/objects-inl.h"
|
||||
@ -50,8 +50,10 @@ bool DateParser::DayComposer::Write(FixedArray output) {
|
||||
}
|
||||
|
||||
if (!is_iso_date_) {
|
||||
if (Between(year, 0, 49)) year += 2000;
|
||||
else if (Between(year, 50, 99)) year += 1900;
|
||||
if (Between(year, 0, 49))
|
||||
year += 2000;
|
||||
else if (Between(year, 50, 99))
|
||||
year += 1900;
|
||||
}
|
||||
|
||||
if (!Smi::IsValid(year) || !IsMonth(month) || !IsDay(day)) return false;
|
||||
@ -79,8 +81,8 @@ bool DateParser::TimeComposer::Write(FixedArray output) {
|
||||
hour += hour_offset_;
|
||||
}
|
||||
|
||||
if (!IsHour(hour) || !IsMinute(minute) ||
|
||||
!IsSecond(second) || !IsMillisecond(millisecond)) {
|
||||
if (!IsHour(hour) || !IsMinute(minute) || !IsSecond(second) ||
|
||||
!IsMillisecond(millisecond)) {
|
||||
// A 24th hour is allowed if minutes, seconds, and milliseconds are 0
|
||||
if (hour != 24 || minute != 0 || second != 0 || millisecond != 0) {
|
||||
return false;
|
||||
@ -114,46 +116,44 @@ bool DateParser::TimeZoneComposer::Write(FixedArray output) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const int8_t DateParser::KeywordTable::
|
||||
array[][DateParser::KeywordTable::kEntrySize] = {
|
||||
{'j', 'a', 'n', DateParser::MONTH_NAME, 1},
|
||||
{'f', 'e', 'b', DateParser::MONTH_NAME, 2},
|
||||
{'m', 'a', 'r', DateParser::MONTH_NAME, 3},
|
||||
{'a', 'p', 'r', DateParser::MONTH_NAME, 4},
|
||||
{'m', 'a', 'y', DateParser::MONTH_NAME, 5},
|
||||
{'j', 'u', 'n', DateParser::MONTH_NAME, 6},
|
||||
{'j', 'u', 'l', DateParser::MONTH_NAME, 7},
|
||||
{'a', 'u', 'g', DateParser::MONTH_NAME, 8},
|
||||
{'s', 'e', 'p', DateParser::MONTH_NAME, 9},
|
||||
{'o', 'c', 't', DateParser::MONTH_NAME, 10},
|
||||
{'n', 'o', 'v', DateParser::MONTH_NAME, 11},
|
||||
{'d', 'e', 'c', DateParser::MONTH_NAME, 12},
|
||||
{'a', 'm', '\0', DateParser::AM_PM, 0},
|
||||
{'p', 'm', '\0', DateParser::AM_PM, 12},
|
||||
{'u', 't', '\0', DateParser::TIME_ZONE_NAME, 0},
|
||||
{'u', 't', 'c', DateParser::TIME_ZONE_NAME, 0},
|
||||
{'z', '\0', '\0', DateParser::TIME_ZONE_NAME, 0},
|
||||
{'g', 'm', 't', DateParser::TIME_ZONE_NAME, 0},
|
||||
{'c', 'd', 't', DateParser::TIME_ZONE_NAME, -5},
|
||||
{'c', 's', 't', DateParser::TIME_ZONE_NAME, -6},
|
||||
{'e', 'd', 't', DateParser::TIME_ZONE_NAME, -4},
|
||||
{'e', 's', 't', DateParser::TIME_ZONE_NAME, -5},
|
||||
{'m', 'd', 't', DateParser::TIME_ZONE_NAME, -6},
|
||||
{'m', 's', 't', DateParser::TIME_ZONE_NAME, -7},
|
||||
{'p', 'd', 't', DateParser::TIME_ZONE_NAME, -7},
|
||||
{'p', 's', 't', DateParser::TIME_ZONE_NAME, -8},
|
||||
{'t', '\0', '\0', DateParser::TIME_SEPARATOR, 0},
|
||||
{'\0', '\0', '\0', DateParser::INVALID, 0},
|
||||
const int8_t
|
||||
DateParser::KeywordTable::array[][DateParser::KeywordTable::kEntrySize] = {
|
||||
{'j', 'a', 'n', DateParser::MONTH_NAME, 1},
|
||||
{'f', 'e', 'b', DateParser::MONTH_NAME, 2},
|
||||
{'m', 'a', 'r', DateParser::MONTH_NAME, 3},
|
||||
{'a', 'p', 'r', DateParser::MONTH_NAME, 4},
|
||||
{'m', 'a', 'y', DateParser::MONTH_NAME, 5},
|
||||
{'j', 'u', 'n', DateParser::MONTH_NAME, 6},
|
||||
{'j', 'u', 'l', DateParser::MONTH_NAME, 7},
|
||||
{'a', 'u', 'g', DateParser::MONTH_NAME, 8},
|
||||
{'s', 'e', 'p', DateParser::MONTH_NAME, 9},
|
||||
{'o', 'c', 't', DateParser::MONTH_NAME, 10},
|
||||
{'n', 'o', 'v', DateParser::MONTH_NAME, 11},
|
||||
{'d', 'e', 'c', DateParser::MONTH_NAME, 12},
|
||||
{'a', 'm', '\0', DateParser::AM_PM, 0},
|
||||
{'p', 'm', '\0', DateParser::AM_PM, 12},
|
||||
{'u', 't', '\0', DateParser::TIME_ZONE_NAME, 0},
|
||||
{'u', 't', 'c', DateParser::TIME_ZONE_NAME, 0},
|
||||
{'z', '\0', '\0', DateParser::TIME_ZONE_NAME, 0},
|
||||
{'g', 'm', 't', DateParser::TIME_ZONE_NAME, 0},
|
||||
{'c', 'd', 't', DateParser::TIME_ZONE_NAME, -5},
|
||||
{'c', 's', 't', DateParser::TIME_ZONE_NAME, -6},
|
||||
{'e', 'd', 't', DateParser::TIME_ZONE_NAME, -4},
|
||||
{'e', 's', 't', DateParser::TIME_ZONE_NAME, -5},
|
||||
{'m', 'd', 't', DateParser::TIME_ZONE_NAME, -6},
|
||||
{'m', 's', 't', DateParser::TIME_ZONE_NAME, -7},
|
||||
{'p', 'd', 't', DateParser::TIME_ZONE_NAME, -7},
|
||||
{'p', 's', 't', DateParser::TIME_ZONE_NAME, -8},
|
||||
{'t', '\0', '\0', DateParser::TIME_SEPARATOR, 0},
|
||||
{'\0', '\0', '\0', DateParser::INVALID, 0},
|
||||
};
|
||||
|
||||
|
||||
// We could use perfect hashing here, but this is not a bottleneck.
|
||||
int DateParser::KeywordTable::Lookup(const uint32_t* pre, int len) {
|
||||
int i;
|
||||
for (i = 0; array[i][kTypeOffset] != INVALID; i++) {
|
||||
int j = 0;
|
||||
while (j < kPrefixLength &&
|
||||
pre[j] == static_cast<uint32_t>(array[i][j])) {
|
||||
while (j < kPrefixLength && pre[j] == static_cast<uint32_t>(array[i][j])) {
|
||||
j++;
|
||||
}
|
||||
// Check if we have a match and the length is legal.
|
||||
@ -166,7 +166,6 @@ int DateParser::KeywordTable::Lookup(const uint32_t* pre, int len) {
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
int DateParser::ReadMilliseconds(DateToken token) {
|
||||
// Read first three significant digits of the original numeral,
|
||||
// as inferred from the value and the number of digits.
|
||||
@ -197,6 +196,5 @@ int DateParser::ReadMilliseconds(DateToken token) {
|
||||
return number;
|
||||
}
|
||||
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_DATEPARSER_H_
|
||||
#define V8_DATEPARSER_H_
|
||||
#ifndef V8_DATE_DATEPARSER_H_
|
||||
#define V8_DATE_DATEPARSER_H_
|
||||
|
||||
#include "src/allocation.h"
|
||||
#include "src/char-predicates.h"
|
||||
@ -28,7 +28,15 @@ class DateParser : public AllStatic {
|
||||
static bool Parse(Isolate* isolate, Vector<Char> str, FixedArray output);
|
||||
|
||||
enum {
|
||||
YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND, UTC_OFFSET, OUTPUT_SIZE
|
||||
YEAR,
|
||||
MONTH,
|
||||
DAY,
|
||||
HOUR,
|
||||
MINUTE,
|
||||
SECOND,
|
||||
MILLISECOND,
|
||||
UTC_OFFSET,
|
||||
OUTPUT_SIZE
|
||||
};
|
||||
|
||||
private:
|
||||
@ -113,7 +121,11 @@ class DateParser : public AllStatic {
|
||||
};
|
||||
|
||||
enum KeywordType {
|
||||
INVALID, MONTH_NAME, TIME_ZONE_NAME, TIME_SEPARATOR, AM_PM
|
||||
INVALID,
|
||||
MONTH_NAME,
|
||||
TIME_ZONE_NAME,
|
||||
TIME_SEPARATOR,
|
||||
AM_PM
|
||||
};
|
||||
|
||||
struct DateToken {
|
||||
@ -147,9 +159,7 @@ class DateParser : public AllStatic {
|
||||
bool IsSymbol(char symbol) {
|
||||
return IsSymbol() && this->symbol() == symbol;
|
||||
}
|
||||
bool IsKeywordType(KeywordType tag) {
|
||||
return tag_ == tag;
|
||||
}
|
||||
bool IsKeywordType(KeywordType tag) { return tag_ == tag; }
|
||||
bool IsFixedLengthNumber(int length) {
|
||||
return IsNumber() && length_ == length;
|
||||
}
|
||||
@ -163,9 +173,7 @@ class DateParser : public AllStatic {
|
||||
bool IsKeywordZ() {
|
||||
return IsKeywordType(TIME_ZONE_NAME) && length_ == 1 && value_ == 0;
|
||||
}
|
||||
bool IsUnknown(int character) {
|
||||
return IsUnknown() && value_ == character;
|
||||
}
|
||||
bool IsUnknown(int character) { return IsUnknown() && value_ == character; }
|
||||
// Factory functions.
|
||||
static DateToken Keyword(KeywordType tag, int value, int length) {
|
||||
return DateToken(tag, length, value);
|
||||
@ -176,18 +184,12 @@ class DateParser : public AllStatic {
|
||||
static DateToken Symbol(char symbol) {
|
||||
return DateToken(kSymbolTag, 1, symbol);
|
||||
}
|
||||
static DateToken EndOfInput() {
|
||||
return DateToken(kEndOfInputTag, 0, -1);
|
||||
}
|
||||
static DateToken EndOfInput() { return DateToken(kEndOfInputTag, 0, -1); }
|
||||
static DateToken WhiteSpace(int length) {
|
||||
return DateToken(kWhiteSpaceTag, length, -1);
|
||||
}
|
||||
static DateToken Unknown() {
|
||||
return DateToken(kUnknownTokenTag, 1, -1);
|
||||
}
|
||||
static DateToken Invalid() {
|
||||
return DateToken(kInvalidTokenTag, 0, -1);
|
||||
}
|
||||
static DateToken Unknown() { return DateToken(kUnknownTokenTag, 1, -1); }
|
||||
static DateToken Invalid() { return DateToken(kInvalidTokenTag, 0, -1); }
|
||||
|
||||
private:
|
||||
enum TagType {
|
||||
@ -200,9 +202,7 @@ class DateParser : public AllStatic {
|
||||
kKeywordTagStart = 0
|
||||
};
|
||||
DateToken(int tag, int length, int value)
|
||||
: tag_(tag),
|
||||
length_(length),
|
||||
value_(value) { }
|
||||
: tag_(tag), length_(length), value_(value) {}
|
||||
|
||||
int tag_;
|
||||
int length_; // Number of characters.
|
||||
@ -213,16 +213,14 @@ class DateParser : public AllStatic {
|
||||
class DateStringTokenizer {
|
||||
public:
|
||||
explicit DateStringTokenizer(InputReader<Char>* in)
|
||||
: in_(in), next_(Scan()) { }
|
||||
: in_(in), next_(Scan()) {}
|
||||
DateToken Next() {
|
||||
DateToken result = next_;
|
||||
next_ = Scan();
|
||||
return result;
|
||||
}
|
||||
|
||||
DateToken Peek() {
|
||||
return next_;
|
||||
}
|
||||
DateToken Peek() { return next_; }
|
||||
bool SkipSymbol(char symbol) {
|
||||
if (next_.IsSymbol(symbol)) {
|
||||
next_ = Scan();
|
||||
@ -278,6 +276,7 @@ class DateParser : public AllStatic {
|
||||
bool IsUTC() const { return hour_ == 0 && minute_ == 0; }
|
||||
bool Write(FixedArray output);
|
||||
bool IsEmpty() { return hour_ == kNone; }
|
||||
|
||||
private:
|
||||
int sign_;
|
||||
int hour_;
|
||||
@ -289,8 +288,7 @@ class DateParser : public AllStatic {
|
||||
TimeComposer() : index_(0), hour_offset_(kNone) {}
|
||||
bool IsEmpty() const { return index_ == 0; }
|
||||
bool IsExpecting(int n) const {
|
||||
return (index_ == 1 && IsMinute(n)) ||
|
||||
(index_ == 2 && IsSecond(n)) ||
|
||||
return (index_ == 1 && IsMinute(n)) || (index_ == 2 && IsSecond(n)) ||
|
||||
(index_ == 3 && IsMillisecond(n));
|
||||
}
|
||||
bool Add(int n) {
|
||||
@ -356,8 +354,7 @@ class DateParser : public AllStatic {
|
||||
TimeZoneComposer* tz);
|
||||
};
|
||||
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_DATEPARSER_H_
|
||||
#endif // V8_DATE_DATEPARSER_H_
|
@ -9,7 +9,7 @@
|
||||
#include "src/compiler/code-assembler.h"
|
||||
#include "src/counters.h"
|
||||
#include "src/cpu-features.h"
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/debug/debug.h"
|
||||
#include "src/deoptimizer.h"
|
||||
#include "src/elements.h"
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "src/compilation-statistics.h"
|
||||
#include "src/compiler-dispatcher/compiler-dispatcher.h"
|
||||
#include "src/compiler-dispatcher/optimizing-compile-dispatcher.h"
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/debug/debug-frames.h"
|
||||
#include "src/debug/debug.h"
|
||||
#include "src/deoptimizer.h"
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "src/assembler-inl.h"
|
||||
#include "src/bootstrapper.h"
|
||||
#include "src/counters.h"
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/disasm.h"
|
||||
#include "src/disassembler.h"
|
||||
#include "src/elements.h"
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "src/compiler.h"
|
||||
#include "src/counters-inl.h"
|
||||
#include "src/counters.h"
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/debug/debug.h"
|
||||
#include "src/elements.h"
|
||||
#include "src/execution.h"
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/objects/intl-objects.h"
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "src/bootstrapper.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/counters.h"
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/elements.h"
|
||||
#include "src/field-type.h"
|
||||
#include "src/handles-inl.h"
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "src/arguments.h"
|
||||
#include "src/conversions-inl.h"
|
||||
#include "src/counters.h"
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/isolate-inl.h"
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "src/api-natives.h"
|
||||
#include "src/arguments-inl.h"
|
||||
#include "src/counters.h"
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/global-handles.h"
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/isolate-inl.h"
|
||||
|
@ -25,7 +25,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "src/date.h"
|
||||
#include "src/date/date.h"
|
||||
#include "src/global-handles.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/v8.h"
|
||||
|
Loading…
Reference in New Issue
Block a user