Commit 5f950698 authored by marja's avatar marja Committed by Commit bot

[objects.h splitting] Move out ConstantElementsPair and BoileplateDescriptor.

BUG=v8:5402

Review-Url: https://codereview.chromium.org/2663513002
Cr-Commit-Position: refs/heads/master@{#42742}
parent 2f728bd9
......@@ -1576,6 +1576,8 @@ v8_source_set("v8_base") {
"src/objects-printer.cc",
"src/objects.cc",
"src/objects.h",
"src/objects/literal-objects.cc",
"src/objects/literal-objects.h",
"src/objects/module-info.h",
"src/objects/object-macros-undef.h",
"src/objects/object-macros.h",
......
......@@ -16,6 +16,7 @@
#include "src/contexts.h"
#include "src/conversions.h"
#include "src/elements.h"
#include "src/objects/literal-objects.h"
#include "src/property-details.h"
#include "src/property.h"
#include "src/string-stream.h"
......@@ -671,6 +672,10 @@ bool ObjectLiteral::IsFastCloningSupported() const {
kMaximumClonedShallowObjectProperties;
}
ElementsKind ArrayLiteral::constant_elements_kind() const {
return static_cast<ElementsKind>(constant_elements()->elements_kind());
}
void ArrayLiteral::InitDepthAndFlags() {
DCHECK_LT(first_spread_index_, 0);
......
......@@ -1554,9 +1554,7 @@ class ArrayLiteral final : public MaterializedLiteral {
Handle<ConstantElementsPair> constant_elements() const {
return constant_elements_;
}
ElementsKind constant_elements_kind() const {
return static_cast<ElementsKind>(constant_elements()->elements_kind());
}
ElementsKind constant_elements_kind() const;
ZoneList<Expression*>* values() const { return values_; }
......
......@@ -18,6 +18,7 @@
#include "src/compiler/operator-properties.h"
#include "src/compiler/state-values-utils.h"
#include "src/objects-inl.h"
#include "src/objects/literal-objects.h"
namespace v8 {
namespace internal {
......
......@@ -13,6 +13,7 @@
#include "src/compiler/simplified-operator.h"
#include "src/interpreter/bytecodes.h"
#include "src/objects-inl.h"
#include "src/objects/literal-objects.h"
namespace v8 {
namespace internal {
......
......@@ -12,6 +12,10 @@
namespace v8 {
namespace internal {
class BoilerplateDescription;
class ConstantElementsPair;
namespace compiler {
// Forward declarations.
......
......@@ -13,6 +13,9 @@
namespace v8 {
namespace internal {
class BoilerplateDescription;
class ConstantElementsPair;
enum FunctionMode {
// With prototype.
FUNCTION_WITH_WRITEABLE_PROTOTYPE,
......
......@@ -30,6 +30,7 @@
#include "src/lookup-cache-inl.h"
#include "src/lookup.h"
#include "src/objects.h"
#include "src/objects/literal-objects.h"
#include "src/objects/module-info.h"
#include "src/objects/regexp-match-info.h"
#include "src/objects/scope-info.h"
......
......@@ -9837,46 +9837,6 @@ void FixedArray::CopyTo(int pos, FixedArray* dest, int dest_pos, int len) {
}
}
Object* BoilerplateDescription::name(int index) const {
// get() already checks for out of bounds access, but we do not want to allow
// access to the last element, if it is the number of properties.
DCHECK_NE(size(), index);
return get(2 * index);
}
Object* BoilerplateDescription::value(int index) const {
return get(2 * index + 1);
}
int BoilerplateDescription::size() const {
DCHECK_EQ(0, (length() - (this->has_number_of_properties() ? 1 : 0)) % 2);
// Rounding is intended.
return length() / 2;
}
int BoilerplateDescription::backing_store_size() const {
if (has_number_of_properties()) {
// If present, the last entry contains the number of properties.
return Smi::cast(this->get(length() - 1))->value();
}
// If the number is not given explicitly, we assume there are no
// properties with computed names.
return size();
}
void BoilerplateDescription::set_backing_store_size(Isolate* isolate,
int backing_store_size) {
DCHECK(has_number_of_properties());
DCHECK_NE(size(), backing_store_size);
Handle<Object> backing_store_size_obj =
isolate->factory()->NewNumberFromInt(backing_store_size);
set(length() - 1, *backing_store_size_obj);
}
bool BoilerplateDescription::has_number_of_properties() const {
return length() % 2 != 0;
}
#ifdef DEBUG
bool FixedArray::IsEqualTo(FixedArray* other) {
if (length() != other->length()) return false;
......
......@@ -2919,30 +2919,6 @@ class FixedArray: public FixedArrayBase {
DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray);
};
// BoilerplateDescription is a list of properties consisting of name value
// pairs. In addition to the properties, it provides the projected number
// of properties in the backing store. This number includes properties with
// computed names that are not
// in the list.
class BoilerplateDescription : public FixedArray {
public:
Object* name(int index) const;
Object* value(int index) const;
// The number of boilerplate properties.
int size() const;
// Number of boilerplate properties and properties with computed names.
int backing_store_size() const;
void set_backing_store_size(Isolate* isolate, int backing_store_size);
DECLARE_CAST(BoilerplateDescription)
private:
bool has_number_of_properties() const;
};
// FixedDoubleArray describes fixed-sized arrays with element type double.
class FixedDoubleArray: public FixedArrayBase {
public:
......@@ -6731,28 +6707,6 @@ class ContextExtension : public Struct {
DISALLOW_IMPLICIT_CONSTRUCTORS(ContextExtension);
};
// Pair of {ElementsKind} and an array of constant values for {ArrayLiteral}
// expressions. Used to communicate with the runtime for literal boilerplate
// creation within the {Runtime_CreateArrayLiteral} method.
class ConstantElementsPair : public Struct {
public:
DECL_INT_ACCESSORS(elements_kind)
DECL_ACCESSORS(constant_values, FixedArrayBase)
DECLARE_CAST(ConstantElementsPair)
// Dispatched behavior.
DECLARE_PRINTER(ConstantElementsPair)
DECLARE_VERIFIER(ConstantElementsPair)
static const int kElementsKindOffset = HeapObject::kHeaderSize;
static const int kConstantValuesOffset = kElementsKindOffset + kPointerSize;
static const int kSize = kConstantValuesOffset + kPointerSize;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantElementsPair);
};
// Script describes a script which has been added to the VM.
class Script: public Struct {
public:
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/objects/literal-objects.h"
#include "src/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
namespace v8 {
namespace internal {
Object* BoilerplateDescription::name(int index) const {
// get() already checks for out of bounds access, but we do not want to allow
// access to the last element, if it is the number of properties.
DCHECK_NE(size(), index);
return get(2 * index);
}
Object* BoilerplateDescription::value(int index) const {
return get(2 * index + 1);
}
int BoilerplateDescription::size() const {
DCHECK_EQ(0, (length() - (this->has_number_of_properties() ? 1 : 0)) % 2);
// Rounding is intended.
return length() / 2;
}
int BoilerplateDescription::backing_store_size() const {
if (has_number_of_properties()) {
// If present, the last entry contains the number of properties.
return Smi::cast(this->get(length() - 1))->value();
}
// If the number is not given explicitly, we assume there are no
// properties with computed names.
return size();
}
void BoilerplateDescription::set_backing_store_size(Isolate* isolate,
int backing_store_size) {
DCHECK(has_number_of_properties());
DCHECK_NE(size(), backing_store_size);
Handle<Object> backing_store_size_obj =
isolate->factory()->NewNumberFromInt(backing_store_size);
set(length() - 1, *backing_store_size_obj);
}
bool BoilerplateDescription::has_number_of_properties() const {
return length() % 2 != 0;
}
} // namespace internal
} // namespace v8
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_LITERAL_OBJECTS_H_
#define V8_OBJECTS_LITERAL_OBJECTS_H_
#include "src/objects.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
// BoilerplateDescription is a list of properties consisting of name value
// pairs. In addition to the properties, it provides the projected number
// of properties in the backing store. This number includes properties with
// computed names that are not
// in the list.
class BoilerplateDescription : public FixedArray {
public:
Object* name(int index) const;
Object* value(int index) const;
// The number of boilerplate properties.
int size() const;
// Number of boilerplate properties and properties with computed names.
int backing_store_size() const;
void set_backing_store_size(Isolate* isolate, int backing_store_size);
DECLARE_CAST(BoilerplateDescription)
private:
bool has_number_of_properties() const;
};
// Pair of {ElementsKind} and an array of constant values for {ArrayLiteral}
// expressions. Used to communicate with the runtime for literal boilerplate
// creation within the {Runtime_CreateArrayLiteral} method.
class ConstantElementsPair : public Struct {
public:
DECL_INT_ACCESSORS(elements_kind)
DECL_ACCESSORS(constant_values, FixedArrayBase)
DECLARE_CAST(ConstantElementsPair)
// Dispatched behavior.
DECLARE_PRINTER(ConstantElementsPair)
DECLARE_VERIFIER(ConstantElementsPair)
static const int kElementsKindOffset = HeapObject::kHeaderSize;
static const int kConstantValuesOffset = kElementsKindOffset + kPointerSize;
static const int kSize = kConstantValuesOffset + kPointerSize;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantElementsPair);
};
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_LITERAL_OBJECTS_H_
......@@ -1084,6 +1084,8 @@
'objects/object-macros.h',
'objects/object-macros-undef.h',
'objects/regexp-match-info.h',
'objects/literal-objects.cc',
'objects/literal-objects.h',
'objects/scope-info.cc',
'objects/scope-info.h',
'ostreams.cc',
......
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