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

Unified Diff: src/objects-inl.h

Issue 3970005: Make Failure inherit from MaybeObject instead of Object. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 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-debug.cc ('k') | src/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
===================================================================
--- src/objects-inl.h (revision 5696)
+++ src/objects-inl.h (working copy)
@@ -396,28 +396,39 @@
}
-bool Object::IsFailure() {
+bool MaybeObject::IsFailure() {
return HAS_FAILURE_TAG(this);
}
-bool Object::IsRetryAfterGC() {
+bool MaybeObject::IsRetryAfterGC() {
return HAS_FAILURE_TAG(this)
&& Failure::cast(this)->type() == Failure::RETRY_AFTER_GC;
}
-bool Object::IsOutOfMemoryFailure() {
+bool MaybeObject::IsOutOfMemory() {
return HAS_FAILURE_TAG(this)
&& Failure::cast(this)->IsOutOfMemoryException();
}
-bool Object::IsException() {
+bool MaybeObject::IsException() {
return this == Failure::Exception();
}
+bool MaybeObject::IsTheHole() {
+ return this == Heap::the_hole_value();
+}
+
+
+Failure* Failure::cast(MaybeObject* obj) {
+ ASSERT(HAS_FAILURE_TAG(obj));
+ return reinterpret_cast<Failure*>(obj);
+}
+
+
bool Object::IsJSObject() {
return IsHeapObject()
&& HeapObject::cast(this)->map()->instance_type() >= FIRST_JS_OBJECT_TYPE;
@@ -677,11 +688,6 @@
}
-bool Object::IsTheHole() {
- return this == Heap::the_hole_value();
-}
-
-
bool Object::IsNull() {
return this == Heap::null_value();
}
@@ -706,7 +712,7 @@
-Object* Object::ToSmi() {
+MaybeObject* Object::ToSmi() {
if (IsSmi()) return this;
if (IsHeapNumber()) {
double value = HeapNumber::cast(this)->value();
@@ -724,18 +730,27 @@
}
-Object* Object::GetElement(uint32_t index) {
+MaybeObject* Object::GetElement(uint32_t index) {
return GetElementWithReceiver(this, index);
}
-Object* Object::GetProperty(String* key) {
+Object* Object::GetElementNoExceptionThrown(uint32_t index) {
+ MaybeObject* maybe = GetElementWithReceiver(this, index);
+ ASSERT(!maybe->IsFailure());
+ Object* result = NULL; // Initialization to please compiler.
+ maybe->ToObject(&result);
+ return result;
+}
+
+
+MaybeObject* Object::GetProperty(String* key) {
PropertyAttributes attributes;
return GetPropertyWithReceiver(this, key, &attributes);
}
-Object* Object::GetProperty(String* key, PropertyAttributes* attributes) {
+MaybeObject* Object::GetProperty(String* key, PropertyAttributes* attributes) {
return GetPropertyWithReceiver(this, key, attributes);
}
@@ -1189,9 +1204,11 @@
}
-Object* JSObject::ResetElements() {
- Object* obj = map()->GetFastElementsMap();
- if (obj->IsFailure()) return obj;
+MaybeObject* JSObject::ResetElements() {
+ Object* obj;
+ { MaybeObject* maybe_obj = map()->GetFastElementsMap();
+ if (!maybe_obj->ToObject(&obj)) return maybe_obj;
+ }
set_map(Map::cast(obj));
initialize_elements();
return this;
@@ -1681,7 +1698,6 @@
CAST_ACCESSOR(ExternalTwoByteString)
CAST_ACCESSOR(JSObject)
CAST_ACCESSOR(Smi)
-CAST_ACCESSOR(Failure)
CAST_ACCESSOR(HeapObject)
CAST_ACCESSOR(HeapNumber)
CAST_ACCESSOR(Oddball)
@@ -1754,7 +1770,7 @@
}
-Object* String::TryFlatten(PretenureFlag pretenure) {
+MaybeObject* String::TryFlatten(PretenureFlag pretenure) {
if (!StringShape(this).IsCons()) return this;
ConsString* cons = ConsString::cast(this);
if (cons->second()->length() == 0) return cons->first();
@@ -1763,8 +1779,12 @@
String* String::TryFlattenGetString(PretenureFlag pretenure) {
- Object* flat = TryFlatten(pretenure);
- return flat->IsFailure() ? this : String::cast(flat);
+ MaybeObject* flat = TryFlatten(pretenure);
+ Object* successfully_flattened;
+ if (flat->ToObject(&successfully_flattened)) {
+ return String::cast(successfully_flattened);
+ }
+ return this;
}
@@ -2475,10 +2495,12 @@
}
-Object* Map::GetFastElementsMap() {
+MaybeObject* Map::GetFastElementsMap() {
if (has_fast_elements()) return this;
- Object* obj = CopyDropTransitions();
- if (obj->IsFailure()) return obj;
+ Object* obj;
+ { MaybeObject* maybe_obj = CopyDropTransitions();
+ if (!maybe_obj->ToObject(&obj)) return maybe_obj;
+ }
Map* new_map = Map::cast(obj);
new_map->set_has_fast_elements(true);
Counters::map_slow_to_fast_elements.Increment();
@@ -2486,10 +2508,12 @@
}
-Object* Map::GetSlowElementsMap() {
+MaybeObject* Map::GetSlowElementsMap() {
if (!has_fast_elements()) return this;
- Object* obj = CopyDropTransitions();
- if (obj->IsFailure()) return obj;
+ Object* obj;
+ { MaybeObject* maybe_obj = CopyDropTransitions();
+ if (!maybe_obj->ToObject(&obj)) return maybe_obj;
+ }
Map* new_map = Map::cast(obj);
new_map->set_has_fast_elements(false);
Counters::map_fast_to_slow_elements.Increment();
@@ -3189,13 +3213,17 @@
}
-Object* JSObject::EnsureWritableFastElements() {
+MaybeObject* JSObject::EnsureWritableFastElements() {
ASSERT(HasFastElements());
FixedArray* elems = FixedArray::cast(elements());
if (elems->map() != Heap::fixed_cow_array_map()) return elems;
- Object* writable_elems = Heap::CopyFixedArrayWithMap(elems,
- Heap::fixed_array_map());
- if (writable_elems->IsFailure()) return writable_elems;
+ Object* writable_elems;
+ { MaybeObject* maybe_writable_elems =
+ Heap::CopyFixedArrayWithMap(elems, Heap::fixed_array_map());
+ if (!maybe_writable_elems->ToObject(&writable_elems)) {
+ return maybe_writable_elems;
+ }
+ }
set_elements(FixedArray::cast(writable_elems));
Counters::cow_arrays_converted.Increment();
return writable_elems;
@@ -3340,13 +3368,18 @@
Object* JSObject::GetHiddenPropertiesObject() {
ASSERT(!IsJSGlobalProxy());
PropertyAttributes attributes;
- return GetLocalPropertyPostInterceptor(this,
- Heap::hidden_symbol(),
- &attributes);
+ // You can't install a getter on a property indexed by the hidden symbol,
+ // so we can be sure that GetLocalPropertyPostInterceptor returns a real
+ // object.
+ Object* result =
+ GetLocalPropertyPostInterceptor(this,
+ Heap::hidden_symbol(),
+ &attributes)->ToObjectUnchecked();
+ return result;
}
-Object* JSObject::SetHiddenPropertiesObject(Object* hidden_obj) {
+MaybeObject* JSObject::SetHiddenPropertiesObject(Object* hidden_obj) {
ASSERT(!IsJSGlobalProxy());
return SetPropertyPostInterceptor(Heap::hidden_symbol(),
hidden_obj,
@@ -3453,7 +3486,7 @@
}
-Object* FixedArray::Copy() {
+MaybeObject* FixedArray::Copy() {
if (length() == 0) return this;
return Heap::CopyFixedArray(this);
}
« no previous file with comments | « src/objects-debug.cc ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698