Commit 1ae4d38c authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Use bit fields for Intl.ListFormat internal values

Bug: v8:7871
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I466d0d2fc7ad61924e3e7e519307281c01873166
Reviewed-on: https://chromium-review.googlesource.com/1142380
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54669}
parent ac8b5b91
......@@ -643,15 +643,15 @@ BUILTIN(ListFormatConstructor) {
// "%ListFormatPrototype%").
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
JSObject::New(target, new_target));
Handle<JSListFormat> format = Handle<JSListFormat>::cast(result);
format->set_flags(0);
Handle<Object> locales = args.atOrUndefined(isolate, 1);
Handle<Object> options = args.atOrUndefined(isolate, 2);
// 3. Return InitializeListFormat(listFormat, locales, options).
RETURN_RESULT_OR_FAILURE(
isolate,
JSListFormat::InitializeListFormat(
isolate, Handle<JSListFormat>::cast(result), locales, options));
RETURN_RESULT_OR_FAILURE(isolate, JSListFormat::InitializeListFormat(
isolate, format, locales, options));
}
namespace {
......
......@@ -1852,9 +1852,8 @@ void InterpreterData::InterpreterDataVerify(Isolate* isolate) {
#ifdef V8_INTL_SUPPORT
void JSListFormat::JSListFormatVerify(Isolate* isolate) {
VerifyObjectField(isolate, kLocaleOffset);
VerifyObjectField(isolate, kStyleOffset);
VerifyObjectField(isolate, kTypeOffset);
VerifyObjectField(isolate, kFormatterOffset);
VerifyObjectField(isolate, kFlagsOffset);
}
void JSLocale::JSLocaleVerify(Isolate* isolate) {
......
......@@ -19,37 +19,30 @@ namespace v8 {
namespace internal {
// Base list format accessors.
ACCESSORS(JSListFormat, locale, String, kLocaleOffset);
ACCESSORS(JSListFormat, formatter, Foreign, kFormatterOffset);
// TODO(ftang): Use bit field accessor for style and type later.
ACCESSORS(JSListFormat, locale, String, kLocaleOffset)
ACCESSORS(JSListFormat, formatter, Foreign, kFormatterOffset)
SMI_ACCESSORS(JSListFormat, flags, kFlagsOffset)
inline void JSListFormat::set_style(Style style) {
DCHECK_GT(Style::COUNT, style);
int value = static_cast<int>(style);
WRITE_FIELD(this, kStyleOffset, Smi::FromInt(value));
int hints = flags();
hints = StyleBits::update(hints, style);
set_flags(hints);
}
inline JSListFormat::Style JSListFormat::style() const {
Object* value = READ_FIELD(this, kStyleOffset);
int style = Smi::ToInt(value);
DCHECK_LE(0, style);
DCHECK_GT(static_cast<int>(Style::COUNT), style);
return static_cast<Style>(style);
return StyleBits::decode(flags());
}
inline void JSListFormat::set_type(Type type) {
DCHECK_GT(Type::COUNT, type);
int value = static_cast<int>(type);
WRITE_FIELD(this, kTypeOffset, Smi::FromInt(value));
int hints = flags();
hints = TypeBits::update(hints, type);
set_flags(hints);
}
inline JSListFormat::Type JSListFormat::type() const {
Object* value = READ_FIELD(this, kTypeOffset);
int type = Smi::ToInt(value);
DCHECK_LE(0, type);
DCHECK_GT(static_cast<int>(Type::COUNT), type);
return static_cast<Type>(type);
return TypeBits::decode(flags());
}
CAST_ACCESSOR(JSListFormat);
......
......@@ -120,6 +120,7 @@ MaybeHandle<JSListFormat> JSListFormat::InitializeListFormat(
Isolate* isolate, Handle<JSListFormat> list_format_holder,
Handle<Object> input_locales, Handle<Object> input_options) {
Factory* factory = isolate->factory();
list_format_holder->set_flags(0);
Handle<JSReceiver> options;
// 2. If options is undefined, then
......
......@@ -46,11 +46,8 @@ class JSListFormat : public JSObject {
// ListFormat accessors.
DECL_ACCESSORS(locale, String)
DECL_ACCESSORS(formatter, Foreign)
// TODO(ftang): Style requires only 2 bits and Type requires only 2 bits
// but here we're using 64 bits for each. We should fold these two fields into
// a single Flags field and use BIT_FIELD_ACCESSORS to access it.
//
// Style: identifying the relative time format style used.
//
// ecma402/#sec-properties-of-intl-listformat-instances
......@@ -75,20 +72,32 @@ class JSListFormat : public JSObject {
inline void set_type(Type type);
inline Type type() const;
DECL_ACCESSORS(formatter, Foreign)
// Bit positions in |flags|.
#define FLAGS_BIT_FIELDS(V, _) \
V(StyleBits, Style, 2, _) \
V(TypeBits, Type, 2, _)
DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
#undef FLAGS_BIT_FIELDS
STATIC_ASSERT(Style::LONG <= StyleBits::kMax);
STATIC_ASSERT(Style::SHORT <= StyleBits::kMax);
STATIC_ASSERT(Style::NARROW <= StyleBits::kMax);
STATIC_ASSERT(Type::CONJUNCTION <= TypeBits::kMax);
STATIC_ASSERT(Type::DISJUNCTION <= TypeBits::kMax);
STATIC_ASSERT(Type::UNIT <= TypeBits::kMax);
// [flags] Bit field containing various flags about the function.
DECL_INT_ACCESSORS(flags)
DECL_PRINTER(JSListFormat)
DECL_VERIFIER(JSListFormat)
// Layout description.
static const int kJSListFormatOffset = JSObject::kHeaderSize;
static const int kLocaleOffset = kJSListFormatOffset + kPointerSize;
static const int kStyleOffset = kLocaleOffset + kPointerSize;
static const int kTypeOffset = kStyleOffset + kPointerSize;
static const int kFormatterOffset = kTypeOffset + kPointerSize;
static const int kSize = kFormatterOffset + kPointerSize;
// Constant to access field
static const int kFormatterField = 3;
static const int kFormatterOffset = kLocaleOffset + kPointerSize;
static const int kFlagsOffset = kFormatterOffset + kPointerSize;
static const int kSize = kFlagsOffset + kPointerSize;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JSListFormat);
......
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