Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(744)

Unified Diff: src/objects.cc

Issue 639123009: Classes: Add basic support for properties (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: git rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 1dff71eca2e57b89c792365842c4dea87b3b3a76..3a4b9c9d34d938cd79838fd6f0af37e264753c46 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -731,21 +731,6 @@ Handle<Object> JSObject::DeleteNormalizedProperty(Handle<JSObject> object,
}
-bool JSObject::IsDirty() {
- Object* cons_obj = map()->constructor();
- if (!cons_obj->IsJSFunction())
- return true;
- JSFunction* fun = JSFunction::cast(cons_obj);
- if (!fun->shared()->IsApiFunction())
- return true;
- // If the object is fully fast case and has the same map it was
- // created with then no changes can have been made to it.
- return map() != fun->initial_map()
- || !HasFastObjectElements()
- || !HasFastProperties();
-}
-
-
MaybeHandle<Object> Object::GetElementWithReceiver(Isolate* isolate,
Handle<Object> object,
Handle<Object> receiver,
@@ -1198,8 +1183,7 @@ void String::StringShortPrint(StringStream* accumulator) {
return;
}
- ConsStringIteratorOp op;
- StringCharacterStream stream(this, &op);
+ StringCharacterStream stream(this);
bool truncated = false;
if (len > kMaxShortPrintLength) {
@@ -1252,8 +1236,7 @@ void String::StringShortPrint(StringStream* accumulator) {
void String::PrintUC16(std::ostream& os, int start, int end) { // NOLINT
if (end < 0) end = length();
- ConsStringIteratorOp op;
- StringCharacterStream stream(this, &op, start);
+ StringCharacterStream stream(this, start);
for (int i = start; i < end && stream.HasMore(); i++) {
os << AsUC16(stream.GetNext());
}
@@ -1549,15 +1532,7 @@ void HeapObject::HeapObjectShortPrint(std::ostream& os) { // NOLINT
}
case SYMBOL_TYPE: {
Symbol* symbol = Symbol::cast(this);
- os << "<Symbol: " << symbol->Hash();
- if (!symbol->name()->IsUndefined()) {
- os << " ";
- HeapStringAllocator allocator;
- StringStream accumulator(&allocator);
- String::cast(symbol->name())->StringShortPrint(&accumulator);
- os << accumulator.ToCString().get();
- }
- os << ">";
+ symbol->SymbolShortPrint(os);
break;
}
case HEAP_NUMBER_TYPE: {
@@ -2161,17 +2136,6 @@ void JSObject::MigrateFastToFast(Handle<JSObject> object, Handle<Map> new_map) {
}
-void JSObject::GeneralizeFieldRepresentation(Handle<JSObject> object,
- int modify_index,
- Representation new_representation,
- Handle<HeapType> new_field_type) {
- Handle<Map> new_map = Map::GeneralizeRepresentation(
- handle(object->map()), modify_index, new_representation, new_field_type,
- FORCE_FIELD);
- MigrateToMap(object, new_map);
-}
-
-
int Map::NumberOfFields() {
DescriptorArray* descriptors = instance_descriptors();
int result = 0;
@@ -8131,15 +8095,11 @@ SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls,
if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) {
return SmartArrayPointer<char>(NULL);
}
- Heap* heap = GetHeap();
-
// Negative length means the to the end of the string.
if (length < 0) length = kMaxInt - offset;
// Compute the size of the UTF-8 string. Start at the specified offset.
- Access<ConsStringIteratorOp> op(
- heap->isolate()->objects_string_iterator());
- StringCharacterStream stream(this, op.value(), offset);
+ StringCharacterStream stream(this, offset);
int character_position = offset;
int utf8_bytes = 0;
int last = unibrow::Utf16::kNoPreviousCharacter;
@@ -8206,11 +8166,7 @@ SmartArrayPointer<uc16> String::ToWideCString(RobustnessFlag robust_flag) {
if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) {
return SmartArrayPointer<uc16>();
}
- Heap* heap = GetHeap();
-
- Access<ConsStringIteratorOp> op(
- heap->isolate()->objects_string_iterator());
- StringCharacterStream stream(this, op.value());
+ StringCharacterStream stream(this);
uc16* result = NewArray<uc16>(length() + 1);
@@ -8314,7 +8270,7 @@ void FlatStringReader::PostGarbageCollection() {
}
-void ConsStringIteratorOp::Initialize(ConsString* cons_string, int offset) {
+void ConsStringIterator::Initialize(ConsString* cons_string, int offset) {
DCHECK(cons_string != NULL);
root_ = cons_string;
consumed_ = offset;
@@ -8325,7 +8281,7 @@ void ConsStringIteratorOp::Initialize(ConsString* cons_string, int offset) {
}
-String* ConsStringIteratorOp::Continue(int* offset_out) {
+String* ConsStringIterator::Continue(int* offset_out) {
DCHECK(depth_ != 0);
DCHECK_EQ(0, *offset_out);
bool blew_stack = StackBlown();
@@ -8343,7 +8299,7 @@ String* ConsStringIteratorOp::Continue(int* offset_out) {
}
-String* ConsStringIteratorOp::Search(int* offset_out) {
+String* ConsStringIterator::Search(int* offset_out) {
ConsString* cons_string = root_;
// Reset the stack, pushing the root string.
depth_ = 1;
@@ -8404,7 +8360,7 @@ String* ConsStringIteratorOp::Search(int* offset_out) {
}
-String* ConsStringIteratorOp::NextLeaf(bool* blew_stack) {
+String* ConsStringIterator::NextLeaf(bool* blew_stack) {
while (true) {
// Tree traversal complete.
if (depth_ == 0) {
@@ -8681,15 +8637,14 @@ class RawStringComparator<uint8_t, uint8_t> {
class StringComparator {
class State {
public:
- explicit inline State(ConsStringIteratorOp* op)
- : op_(op), is_one_byte_(true), length_(0), buffer8_(NULL) {}
+ State() : is_one_byte_(true), length_(0), buffer8_(NULL) {}
- inline void Init(String* string) {
+ void Init(String* string) {
ConsString* cons_string = String::VisitFlat(this, string);
- op_->Reset(cons_string);
+ iter_.Reset(cons_string);
if (cons_string != NULL) {
int offset;
- string = op_->Next(&offset);
+ string = iter_.Next(&offset);
String::VisitFlat(this, string, offset);
}
}
@@ -8720,13 +8675,13 @@ class StringComparator {
}
// Advance state.
int offset;
- String* next = op_->Next(&offset);
+ String* next = iter_.Next(&offset);
DCHECK_EQ(0, offset);
DCHECK(next != NULL);
String::VisitFlat(this, next);
}
- ConsStringIteratorOp* const op_;
+ ConsStringIterator iter_;
bool is_one_byte_;
int length_;
union {
@@ -8735,15 +8690,11 @@ class StringComparator {
};
private:
- DISALLOW_IMPLICIT_CONSTRUCTORS(State);
+ DISALLOW_COPY_AND_ASSIGN(State);
};
public:
- inline StringComparator(ConsStringIteratorOp* op_1,
- ConsStringIteratorOp* op_2)
- : state_1_(op_1),
- state_2_(op_2) {
- }
+ inline StringComparator() {}
template<typename Chars1, typename Chars2>
static inline bool Equals(State* state_1, State* state_2, int to_check) {
@@ -8786,7 +8737,8 @@ class StringComparator {
private:
State state_1_;
State state_2_;
- DISALLOW_IMPLICIT_CONSTRUCTORS(StringComparator);
+
+ DISALLOW_COPY_AND_ASSIGN(StringComparator);
};
@@ -8827,10 +8779,7 @@ bool String::SlowEquals(String* other) {
return CompareRawStringContents(str1, str2, len);
}
- Isolate* isolate = GetIsolate();
- StringComparator comparator(isolate->objects_string_compare_iterator_a(),
- isolate->objects_string_compare_iterator_b());
-
+ StringComparator comparator;
return comparator.Equals(this, other);
}
@@ -8982,8 +8931,7 @@ uint32_t String::ComputeAndSetHash() {
bool String::ComputeArrayIndex(uint32_t* index) {
int length = this->length();
if (length == 0 || length > kMaxArrayIndexSize) return false;
- ConsStringIteratorOp op;
- StringCharacterStream stream(this, &op);
+ StringCharacterStream stream(this);
return StringToArrayIndex(&stream, index);
}
@@ -9840,7 +9788,7 @@ Handle<JSObject> Script::GetWrapper(Handle<Script> script) {
Isolate* isolate = script->GetIsolate();
if (!script->wrapper()->IsUndefined()) {
Handle<WeakCell> cell(WeakCell::cast(script->wrapper()));
- if (!cell->value()->IsUndefined()) {
+ if (!cell->cleared()) {
// Return a handle for the existing script wrapper from the cache.
return handle(JSObject::cast(cell->value()));
}
@@ -10497,27 +10445,7 @@ void Code::ClearInlineCaches(Code::Kind* kind) {
void SharedFunctionInfo::ClearTypeFeedbackInfo() {
- TypeFeedbackVector* vector = feedback_vector();
- Heap* heap = GetHeap();
- int length = vector->length();
-
- for (int i = 0; i < length; i++) {
- Object* obj = vector->get(i);
- if (obj->IsHeapObject()) {
- InstanceType instance_type =
- HeapObject::cast(obj)->map()->instance_type();
- switch (instance_type) {
- case ALLOCATION_SITE_TYPE:
- // AllocationSites are not cleared because they do not store
- // information that leaks.
- break;
- // Fall through...
- default:
- vector->set(i, TypeFeedbackVector::RawUninitializedSentinel(heap),
- SKIP_WRITE_BARRIER);
- }
- }
- }
+ feedback_vector()->ClearSlots(this);
}
@@ -11842,7 +11770,7 @@ MaybeHandle<Object> JSObject::SetPrototype(Handle<JSObject> object,
DCHECK(new_map->prototype() == *value);
JSObject::MigrateToMap(real_receiver, new_map);
- if (!dictionary_elements_in_chain &&
+ if (from_javascript && !dictionary_elements_in_chain &&
new_map->DictionaryElementsInPrototypeChainOnly()) {
// If the prototype chain didn't previously have element callbacks, then
// KeyedStoreICs need to be cleared to ensure any that involve this
@@ -13202,7 +13130,7 @@ void Dictionary<Derived, Shape, Key>::Print(std::ostream& os) { // NOLINT
} else {
os << Brief(k);
}
- os << ": " << Brief(ValueAt(i)) << "\n";
+ os << ": " << Brief(ValueAt(i)) << " " << DetailsAt(i) << "\n";
}
}
}
@@ -13676,6 +13604,31 @@ int JSObject::GetEnumElementKeys(FixedArray* storage) {
}
+const char* Symbol::PrivateSymbolToName() const {
+ Heap* heap = GetIsolate()->heap();
+#define SYMBOL_CHECK_AND_PRINT(name) \
+ if (this == heap->name()) return #name;
+ PRIVATE_SYMBOL_LIST(SYMBOL_CHECK_AND_PRINT)
+#undef SYMBOL_CHECK_AND_PRINT
+ return "UNKNOWN";
+}
+
+
+void Symbol::SymbolShortPrint(std::ostream& os) {
+ os << "<Symbol: " << Hash();
+ if (!name()->IsUndefined()) {
+ os << " ";
+ HeapStringAllocator allocator;
+ StringStream accumulator(&allocator);
+ String::cast(name())->StringShortPrint(&accumulator);
+ os << accumulator.ToCString().get();
+ } else {
+ os << " (" << PrivateSymbolToName() << ")";
+ }
+ os << ">";
+}
+
+
// StringSharedKeys are used as keys in the eval cache.
class StringSharedKey : public HashTableKey {
public:
@@ -14276,9 +14229,11 @@ template
int Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >::
NumberOfEnumElements();
-template
-int HashTable<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
- FindEntry(uint32_t);
+template bool Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape,
+ uint32_t>::HasComplexElements();
+
+template int HashTable<SeededNumberDictionary, SeededNumberDictionaryShape,
+ uint32_t>::FindEntry(uint32_t);
Handle<Object> JSObject::PrepareSlowElementsForSort(
@@ -14833,6 +14788,16 @@ MaybeHandle<String> StringTable::LookupTwoCharsStringIfExists(
}
+void StringTable::EnsureCapacityForDeserialization(Isolate* isolate,
+ int expected) {
+ Handle<StringTable> table = isolate->factory()->string_table();
+ // We need a key instance for the virtual hash function.
+ InternalizedStringKey dummy_key(Handle<String>::null());
+ table = StringTable::EnsureCapacity(table, expected, &dummy_key);
+ isolate->factory()->set_string_table(table);
+}
+
+
Handle<String> StringTable::LookupString(Isolate* isolate,
Handle<String> string) {
InternalizedStringKey key(string);
@@ -15316,10 +15281,26 @@ int Dictionary<Derived, Shape, Key>::NumberOfEnumElements() {
}
-template<typename Derived, typename Shape, typename Key>
+template <typename Derived, typename Shape, typename Key>
+bool Dictionary<Derived, Shape, Key>::HasComplexElements() {
+ int capacity = DerivedHashTable::Capacity();
+ for (int i = 0; i < capacity; i++) {
+ Object* k = DerivedHashTable::KeyAt(i);
+ if (DerivedHashTable::IsKey(k) && !FilterKey(k, NONE)) {
+ PropertyDetails details = DetailsAt(i);
+ if (details.IsDeleted()) continue;
+ if (details.type() == CALLBACKS) return true;
+ PropertyAttributes attr = details.attributes();
+ if (attr & (READ_ONLY | DONT_DELETE | DONT_ENUM)) return true;
+ }
+ }
+ return false;
+}
+
+
+template <typename Derived, typename Shape, typename Key>
void Dictionary<Derived, Shape, Key>::CopyKeysTo(
- FixedArray* storage,
- PropertyAttributes filter,
+ FixedArray* storage, PropertyAttributes filter,
typename Dictionary<Derived, Shape, Key>::SortMode sort_mode) {
DCHECK(storage->length() >= NumberOfElementsFilterAttributes(filter));
int capacity = DerivedHashTable::Capacity();
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698