Commit 52a7d787 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] remove Unpack* methods & make intl objects consistent

Remove Unpack* methods from all Intl objects
Make the icu data in Intl objects more consistent in naming

Bug: v8:8248
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: If81a3010265e91919b548dad2dbd11c5ae8e4abd
Reviewed-on: https://chromium-review.googlesource.com/1252883Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56299}
parent 9b5ba969
......@@ -1068,7 +1068,7 @@ BUILTIN(V8BreakIteratorInternalFirst) {
isolate);
icu::BreakIterator* break_iterator =
JSV8BreakIterator::UnpackBreakIterator(break_iterator_holder);
break_iterator_holder->break_iterator()->raw();
CHECK_NOT_NULL(break_iterator);
return *isolate->factory()->NewNumberFromInt(break_iterator->first());
......@@ -1103,7 +1103,7 @@ BUILTIN(V8BreakIteratorInternalNext) {
isolate);
icu::BreakIterator* break_iterator =
JSV8BreakIterator::UnpackBreakIterator(break_iterator_holder);
break_iterator_holder->break_iterator()->raw();
CHECK_NOT_NULL(break_iterator);
return *isolate->factory()->NewNumberFromInt(break_iterator->next());
......@@ -1138,7 +1138,7 @@ BUILTIN(V8BreakIteratorInternalCurrent) {
isolate);
icu::BreakIterator* break_iterator =
JSV8BreakIterator::UnpackBreakIterator(break_iterator_holder);
break_iterator_holder->break_iterator()->raw();
CHECK_NOT_NULL(break_iterator);
return *isolate->factory()->NewNumberFromInt(break_iterator->current());
......@@ -1174,7 +1174,7 @@ BUILTIN(V8BreakIteratorInternalBreakType) {
isolate);
icu::BreakIterator* break_iterator =
JSV8BreakIterator::UnpackBreakIterator(break_iterator_holder);
break_iterator_holder->break_iterator()->raw();
CHECK_NOT_NULL(break_iterator);
int32_t status = break_iterator->getRuleStatus();
......
......@@ -1913,7 +1913,7 @@ void JSDateTimeFormat::JSDateTimeFormatVerify(Isolate* isolate) {
void JSListFormat::JSListFormatVerify(Isolate* isolate) {
JSObjectVerify(isolate);
VerifyObjectField(isolate, kLocaleOffset);
VerifyObjectField(isolate, kFormatterOffset);
VerifyObjectField(isolate, kICUFormatterOffset);
VerifyObjectField(isolate, kFlagsOffset);
}
......@@ -1954,7 +1954,7 @@ void JSPluralRules::JSPluralRulesVerify(Isolate* isolate) {
void JSRelativeTimeFormat::JSRelativeTimeFormatVerify(Isolate* isolate) {
JSObjectVerify(isolate);
VerifyObjectField(isolate, kLocaleOffset);
VerifyObjectField(isolate, kFormatterOffset);
VerifyObjectField(isolate, kICUFormatterOffset);
VerifyObjectField(isolate, kFlagsOffset);
}
#endif // V8_INTL_SUPPORT
......
......@@ -1980,7 +1980,7 @@ void JSListFormat::JSListFormatPrint(std::ostream& os) { // NOLINT
os << "\n - locale: " << Brief(locale());
os << "\n - style: " << StyleAsString();
os << "\n - type: " << TypeAsString();
os << "\n - formatter: " << Brief(formatter());
os << "\n - icu formatter: " << Brief(icu_formatter());
os << "\n";
}
......@@ -2026,7 +2026,7 @@ void JSRelativeTimeFormat::JSRelativeTimeFormatPrint(
os << "\n - locale: " << Brief(locale());
os << "\n - style: " << StyleAsString();
os << "\n - numeric: " << NumericAsString();
os << "\n - formatter: " << Brief(formatter());
os << "\n - icu formatter: " << Brief(icu_formatter());
os << "\n";
}
#endif // V8_INTL_SUPPORT
......
......@@ -127,11 +127,6 @@ Handle<JSObject> JSV8BreakIterator::ResolvedOptions(
return result;
}
icu::BreakIterator* JSV8BreakIterator::UnpackBreakIterator(
Handle<JSV8BreakIterator> obj) {
return Managed<icu::BreakIterator>::cast(obj->break_iterator())->raw();
}
void JSV8BreakIterator::AdoptText(
Isolate* isolate, Handle<JSV8BreakIterator> break_iterator_holder,
Handle<String> text) {
......
......@@ -34,7 +34,6 @@ class JSV8BreakIterator : public JSObject {
static Handle<JSObject> ResolvedOptions(
Isolate* isolate, Handle<JSV8BreakIterator> break_iterator);
static icu::BreakIterator* UnpackBreakIterator(Handle<JSV8BreakIterator> obj);
static void AdoptText(Isolate* isolate,
Handle<JSV8BreakIterator> break_iterator_holder,
Handle<String> text);
......
......@@ -314,7 +314,7 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
.FromJust());
icu::SimpleDateFormat* icu_simple_date_format =
UnpackDateFormat(date_time_format);
date_time_format->icu_simple_date_format()->raw();
// calendar
const icu::Calendar* calendar = icu_simple_date_format->getCalendar();
// getType() returns legacy calendar type name instead of LDML/BCP47 calendar
......@@ -435,7 +435,7 @@ MaybeHandle<String> FormatDateTime(Isolate* isolate,
}
icu::SimpleDateFormat* date_format =
JSDateTimeFormat::UnpackDateFormat(date_time_format);
date_time_format->icu_simple_date_format()->raw();
CHECK_NOT_NULL(date_format);
icu::UnicodeString result;
......@@ -849,11 +849,6 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::Initialize(
return date_time_format;
}
icu::SimpleDateFormat* JSDateTimeFormat::UnpackDateFormat(
Handle<JSDateTimeFormat> date_time_format) {
return date_time_format->icu_simple_date_format()->raw();
}
namespace {
// The list comes from third_party/icu/source/i18n/unicode/udat.h.
......@@ -913,7 +908,7 @@ MaybeHandle<Object> JSDateTimeFormat::FormatToParts(
double date_value) {
Factory* factory = isolate->factory();
icu::SimpleDateFormat* format =
JSDateTimeFormat::UnpackDateFormat(date_time_format);
date_time_format->icu_simple_date_format()->raw();
CHECK_NOT_NULL(format);
icu::UnicodeString formatted;
......
......@@ -29,9 +29,6 @@ class JSDateTimeFormat : public JSObject {
Isolate* isolate, Handle<JSDateTimeFormat> date_time_format,
Handle<Object> locales, Handle<Object> options);
static icu::SimpleDateFormat* UnpackDateFormat(
Handle<JSDateTimeFormat> date_time_format);
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> ResolvedOptions(
Isolate* isolate, Handle<JSDateTimeFormat> date_time_format);
......
......@@ -20,7 +20,8 @@ namespace internal {
// Base list format accessors.
ACCESSORS(JSListFormat, locale, String, kLocaleOffset)
ACCESSORS(JSListFormat, formatter, Foreign, kFormatterOffset)
ACCESSORS(JSListFormat, icu_formatter, Managed<icu::ListFormatter>,
kICUFormatterOffset)
SMI_ACCESSORS(JSListFormat, flags, kFlagsOffset)
inline void JSListFormat::set_style(Style style) {
......
......@@ -199,7 +199,7 @@ MaybeHandle<JSListFormat> JSListFormat::InitializeListFormat(
Handle<Managed<icu::ListFormatter>> managed_formatter =
Managed<icu::ListFormatter>::FromRawPtr(isolate, 0, formatter);
list_format_holder->set_formatter(*managed_formatter);
list_format_holder->set_icu_formatter(*managed_formatter);
return list_format_holder;
}
......@@ -217,11 +217,6 @@ Handle<JSObject> JSListFormat::ResolvedOptions(
return result;
}
icu::ListFormatter* JSListFormat::UnpackFormatter(Isolate* isolate,
Handle<JSListFormat> holder) {
return Managed<icu::ListFormatter>::cast(holder->formatter())->raw();
}
Handle<String> JSListFormat::StyleAsString() const {
switch (style()) {
case Style::LONG:
......@@ -352,8 +347,7 @@ Maybe<bool> FormatListCommon(Isolate* isolate,
std::unique_ptr<icu::UnicodeString[]>& array) {
DCHECK(!list->IsUndefined());
icu::ListFormatter* formatter =
JSListFormat::UnpackFormatter(isolate, format_holder);
icu::ListFormatter* formatter = format_holder->icu_formatter()->raw();
CHECK_NOT_NULL(formatter);
*length = list->GetElementsAccessor()->NumberOfElements(*list);
......
......@@ -12,6 +12,7 @@
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects.h"
#include "src/objects/managed.h"
#include "unicode/uversion.h"
// Has to be the last include (doesn't have include guards):
......@@ -35,10 +36,6 @@ class JSListFormat : public JSObject {
static Handle<JSObject> ResolvedOptions(Isolate* isolate,
Handle<JSListFormat> format_holder);
// Unpacks formatter object from corresponding JavaScript object.
static icu::ListFormatter* UnpackFormatter(
Isolate* isolate, Handle<JSListFormat> list_format_holder);
// ecma402 #sec-formatlist
V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatList(
Isolate* isolate, Handle<JSListFormat> format_holder,
......@@ -56,7 +53,7 @@ class JSListFormat : public JSObject {
// ListFormat accessors.
DECL_ACCESSORS(locale, String)
DECL_ACCESSORS(formatter, Foreign)
DECL_ACCESSORS(icu_formatter, Managed<icu::ListFormatter>)
// Style: identifying the relative time format style used.
//
......@@ -105,8 +102,8 @@ class JSListFormat : public JSObject {
// Layout description.
static const int kJSListFormatOffset = JSObject::kHeaderSize;
static const int kLocaleOffset = kJSListFormatOffset + kPointerSize;
static const int kFormatterOffset = kLocaleOffset + kPointerSize;
static const int kFlagsOffset = kFormatterOffset + kPointerSize;
static const int kICUFormatterOffset = kLocaleOffset + kPointerSize;
static const int kFlagsOffset = kICUFormatterOffset + kPointerSize;
static const int kSize = kFlagsOffset + kPointerSize;
private:
......
......@@ -70,7 +70,7 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
.FromJust());
icu::NumberFormat* number_format =
UnpackIcuNumberFormat(isolate, number_format_holder);
number_format_holder->icu_number_format()->raw();
CHECK_NOT_NULL(number_format);
icu::DecimalFormat* decimal_format =
static_cast<icu::DecimalFormat*>(number_format);
......@@ -458,11 +458,6 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
return number_format;
}
icu::NumberFormat* JSNumberFormat::UnpackIcuNumberFormat(
Isolate* isolate, Handle<JSNumberFormat> holder) {
return Managed<icu::NumberFormat>::cast(holder->icu_number_format())->raw();
}
Handle<String> JSNumberFormat::StyleAsString() const {
switch (style()) {
case Style::DECIMAL:
......@@ -493,7 +488,7 @@ MaybeHandle<String> JSNumberFormat::FormatNumber(
Isolate* isolate, Handle<JSNumberFormat> number_format_holder,
double number) {
icu::NumberFormat* number_format =
UnpackIcuNumberFormat(isolate, number_format_holder);
number_format_holder->icu_number_format()->raw();
CHECK_NOT_NULL(number_format);
icu::UnicodeString result;
......
......@@ -46,10 +46,6 @@ class JSNumberFormat : public JSObject {
V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatNumber(
Isolate* isolate, Handle<JSNumberFormat> number_format, double number);
// Unpacks format object from corresponding JavaScript object.
static icu::NumberFormat* UnpackIcuNumberFormat(
Isolate* isolate, Handle<JSNumberFormat> number_format_holder);
Handle<String> StyleAsString() const;
Handle<String> CurrencyDisplayAsString() const;
......
......@@ -20,7 +20,8 @@ namespace internal {
// Base relative time format accessors.
ACCESSORS(JSRelativeTimeFormat, locale, String, kLocaleOffset)
ACCESSORS(JSRelativeTimeFormat, formatter, Foreign, kFormatterOffset)
ACCESSORS(JSRelativeTimeFormat, icu_formatter,
Managed<icu::RelativeDateTimeFormatter>, kICUFormatterOffset)
SMI_ACCESSORS(JSRelativeTimeFormat, flags, kFlagsOffset)
// TODO(ftang): Use bit field accessor for style and numeric later.
......
......@@ -17,7 +17,6 @@
#include "src/objects-inl.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-relative-time-format-inl.h"
#include "src/objects/managed.h"
#include "unicode/numfmt.h"
#include "unicode/reldatefmt.h"
#include "unicode/uvernum.h" // for U_ICU_VERSION_MAJOR_NUM
......@@ -162,7 +161,7 @@ JSRelativeTimeFormat::InitializeRelativeTimeFormat(
icu_formatter);
// 30. Set relativeTimeFormat.[[InitializedRelativeTimeFormat]] to true.
relative_time_format_holder->set_formatter(*managed_formatter);
relative_time_format_holder->set_icu_formatter(*managed_formatter);
// 31. Return relativeTimeFormat.
return relative_time_format_holder;
}
......@@ -181,12 +180,6 @@ Handle<JSObject> JSRelativeTimeFormat::ResolvedOptions(
return result;
}
icu::RelativeDateTimeFormatter* JSRelativeTimeFormat::UnpackFormatter(
Handle<JSRelativeTimeFormat> holder) {
return Managed<icu::RelativeDateTimeFormatter>::cast(holder->formatter())
->raw();
}
Handle<String> JSRelativeTimeFormat::StyleAsString() const {
switch (style()) {
case Style::LONG:
......@@ -362,7 +355,7 @@ MaybeHandle<Object> JSRelativeTimeFormat::Format(
}
icu::RelativeDateTimeFormatter* formatter =
JSRelativeTimeFormat::UnpackFormatter(format_holder);
format_holder->icu_formatter()->raw();
CHECK_NOT_NULL(formatter);
URelativeDateTimeUnit unit_enum;
......
......@@ -12,6 +12,7 @@
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects.h"
#include "src/objects/managed.h"
#include "unicode/uversion.h"
// Has to be the last include (doesn't have include guards):
......@@ -37,10 +38,6 @@ class JSRelativeTimeFormat : public JSObject {
V8_WARN_UNUSED_RESULT static Handle<JSObject> ResolvedOptions(
Isolate* isolate, Handle<JSRelativeTimeFormat> format_holder);
// Unpacks formatter object from corresponding JavaScript object.
V8_WARN_UNUSED_RESULT static icu::RelativeDateTimeFormatter* UnpackFormatter(
Handle<JSRelativeTimeFormat> relative_time_format_holder);
Handle<String> StyleAsString() const;
Handle<String> NumericAsString() const;
......@@ -56,7 +53,7 @@ class JSRelativeTimeFormat : public JSObject {
// RelativeTimeFormat accessors.
DECL_ACCESSORS(locale, String)
DECL_ACCESSORS(formatter, Foreign)
DECL_ACCESSORS(icu_formatter, Managed<icu::RelativeDateTimeFormatter>)
// Style: identifying the relative time format style used.
//
......@@ -107,8 +104,8 @@ class JSRelativeTimeFormat : public JSObject {
// Layout description.
static const int kJSRelativeTimeFormatOffset = JSObject::kHeaderSize;
static const int kLocaleOffset = kJSRelativeTimeFormatOffset + kPointerSize;
static const int kFormatterOffset = kLocaleOffset + kPointerSize;
static const int kFlagsOffset = kFormatterOffset + kPointerSize;
static const int kICUFormatterOffset = kLocaleOffset + kPointerSize;
static const int kFlagsOffset = kICUFormatterOffset + kPointerSize;
static const int kSize = kFlagsOffset + kPointerSize;
private:
......
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