Commit 4143a667 authored by jochen's avatar jochen Committed by Commit bot

Move properties from JSObject to JSReceiver

That will allow for adding private symbols to JSProxies in a follow-up
change

BUG=chromium:571365
R=neis@chromium.org,verwaest@chromium.org,rossberg@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/1575423002

Cr-Commit-Position: refs/heads/master@{#33241}
parent 863bf39a
......@@ -2025,6 +2025,7 @@ Handle<JSProxy> Factory::NewJSProxy(Handle<JSReceiver> target,
}
DCHECK(map->prototype()->IsNull());
Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE);
result->initialize_properties();
result->set_target(*target);
result->set_handler(*handler);
result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER);
......
......@@ -1599,7 +1599,7 @@ SIMD128_BOOLEAN_LANE_FNS(Bool8x16, int8_t, 16, INT8, kCharSize)
#undef SIMD128_WRITE_LANE
ACCESSORS(JSObject, properties, FixedArray, kPropertiesOffset)
ACCESSORS(JSReceiver, properties, FixedArray, kPropertiesOffset)
Object** FixedArray::GetFirstElementAddress() {
......@@ -1969,12 +1969,6 @@ void JSObject::set_elements(FixedArrayBase* value, WriteBarrierMode mode) {
}
void JSObject::initialize_properties() {
DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array()));
WRITE_FIELD(this, kPropertiesOffset, GetHeap()->empty_fixed_array());
}
void JSObject::initialize_elements() {
FixedArrayBase* elements = map()->GetInitialElements();
WRITE_FIELD(this, kElementsOffset, elements);
......@@ -2315,12 +2309,6 @@ void JSObject::InitializeBody(Map* map, int start_offset,
}
bool JSObject::HasFastProperties() {
DCHECK(properties()->IsDictionary() == map()->is_dictionary_map());
return !properties()->IsDictionary();
}
bool Map::TooManyFastProperties(StoreFromKeyed store_mode) {
if (unused_property_fields() != 0) return false;
if (is_prototype_map()) return false;
......@@ -6764,13 +6752,6 @@ bool JSObject::HasIndexedInterceptor() {
}
NameDictionary* JSObject::property_dictionary() {
DCHECK(!HasFastProperties());
DCHECK(!IsJSGlobalObject());
return NameDictionary::cast(properties());
}
GlobalDictionary* JSObject::global_dictionary() {
DCHECK(!HasFastProperties());
DCHECK(IsJSGlobalObject());
......@@ -7084,6 +7065,25 @@ MaybeHandle<Object> Object::GetPropertyOrElement(Handle<JSReceiver> holder,
}
void JSReceiver::initialize_properties() {
DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array()));
WRITE_FIELD(this, kPropertiesOffset, GetHeap()->empty_fixed_array());
}
bool JSReceiver::HasFastProperties() {
DCHECK(properties()->IsDictionary() == map()->is_dictionary_map());
return !properties()->IsDictionary();
}
NameDictionary* JSReceiver::property_dictionary() {
DCHECK(!HasFastProperties());
DCHECK(!IsJSGlobalObject());
return NameDictionary::cast(properties());
}
Maybe<bool> JSReceiver::HasProperty(Handle<JSReceiver> object,
Handle<Name> name) {
LookupIterator it =
......
......@@ -1802,6 +1802,15 @@ enum GetKeysConversion { KEEP_NUMBERS, CONVERT_TO_STRING };
// JSObject and JSProxy.
class JSReceiver: public HeapObject {
public:
// [properties]: Backing storage for properties.
// properties is a FixedArray in the fast case and a Dictionary in the
// slow case.
DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties.
inline void initialize_properties();
inline bool HasFastProperties();
// Gets slow properties for non-global objects.
inline NameDictionary* property_dictionary();
DECLARE_CAST(JSReceiver)
// ES6 section 7.1.1 ToPrimitive
......@@ -1960,6 +1969,10 @@ class JSReceiver: public HeapObject {
Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter,
GetKeysConversion keys_conversion = KEEP_NUMBERS);
// Layout description.
static const int kPropertiesOffset = HeapObject::kHeaderSize;
static const int kHeaderSize = HeapObject::kHeaderSize + kPointerSize;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver);
};
......@@ -1975,14 +1988,6 @@ class JSObject: public JSReceiver {
Handle<JSFunction> constructor, Handle<JSReceiver> new_target,
Handle<AllocationSite> site = Handle<AllocationSite>::null());
// [properties]: Backing storage for properties.
// properties is a FixedArray in the fast case and a Dictionary in the
// slow case.
DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties.
inline void initialize_properties();
inline bool HasFastProperties();
// Gets slow properties for non-global objects.
inline NameDictionary* property_dictionary();
// Gets global object properties.
inline GlobalDictionary* global_dictionary();
......@@ -2474,13 +2479,12 @@ class JSObject: public JSReceiver {
static const int kFieldsAdded = 3;
// Layout description.
static const int kPropertiesOffset = HeapObject::kHeaderSize;
static const int kElementsOffset = kPropertiesOffset + kPointerSize;
static const int kElementsOffset = JSReceiver::kHeaderSize;
static const int kHeaderSize = kElementsOffset + kPointerSize;
STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize);
typedef FlexibleBodyDescriptor<kPropertiesOffset> BodyDescriptor;
typedef FlexibleBodyDescriptor<JSReceiver::kPropertiesOffset> BodyDescriptor;
// Enqueue change record for Object.observe. May cause GC.
MUST_USE_RESULT static MaybeHandle<Object> EnqueueChangeRecord(
......@@ -9623,15 +9627,14 @@ class JSProxy: public JSReceiver {
DECLARE_PRINTER(JSProxy)
DECLARE_VERIFIER(JSProxy)
// Layout description. We add padding so that a proxy has the same
// size as a virgin JSObject. This is essential for becoming a JSObject
// upon freeze.
static const int kTargetOffset = HeapObject::kHeaderSize;
// Layout description.
static const int kTargetOffset = JSReceiver::kHeaderSize;
static const int kHandlerOffset = kTargetOffset + kPointerSize;
static const int kHashOffset = kHandlerOffset + kPointerSize;
static const int kSize = kHashOffset + kPointerSize;
typedef FixedBodyDescriptor<kTargetOffset, kSize, kSize> BodyDescriptor;
typedef FixedBodyDescriptor<JSReceiver::kPropertiesOffset, kSize, kSize>
BodyDescriptor;
MUST_USE_RESULT Object* GetIdentityHash();
......
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