Commit 2c394ad0 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Introduce exception object and remove some uses of MaybeObject::IsFailure().

R=bmeurer@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20871 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent eccda7f0
......@@ -5545,7 +5545,7 @@ class Internals {
static const int kNullValueRootIndex = 7;
static const int kTrueValueRootIndex = 8;
static const int kFalseValueRootIndex = 9;
static const int kEmptyStringRootIndex = 160;
static const int kEmptyStringRootIndex = 162;
static const int kNodeClassIdOffset = 1 * kApiPointerSize;
static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
......
......@@ -62,7 +62,7 @@ Handle<AllocationSite> AllocationSiteCreationContext::EnterNewScope() {
void AllocationSiteCreationContext::ExitScope(
Handle<AllocationSite> scope_site,
Handle<JSObject> object) {
if (!object.is_null() && !object->IsFailure()) {
if (!object.is_null()) {
bool top_level = !scope_site.is_null() &&
top().is_identical_to(scope_site);
......
......@@ -596,8 +596,6 @@ class ElementsAccessorBase : public ElementsAccessor {
static void ValidateImpl(Handle<JSObject> holder) {
Handle<FixedArrayBase> fixed_array_base(holder->elements());
// When objects are first allocated, its elements are Failures.
if (fixed_array_base->IsFailure()) return;
if (!fixed_array_base->IsHeapObject()) return;
// Arrays that have been shifted in place can't be verified.
if (fixed_array_base->IsFiller()) return;
......
......@@ -2578,6 +2578,7 @@ bool Heap::CreateInitialMaps() {
ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, uninitialized);
ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, arguments_marker);
ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, no_interceptor_result_sentinel);
ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, exception);
ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, termination_exception);
for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) {
......@@ -2882,6 +2883,12 @@ bool Heap::CreateInitialObjects() {
handle(Smi::FromInt(-3), isolate()),
Oddball::kOther));
set_exception(
*factory->NewOddball(factory->exception_map(),
"exception",
handle(Smi::FromInt(-5), isolate()),
Oddball::kException));
for (unsigned i = 0; i < ARRAY_SIZE(constant_string_table); i++) {
Handle<String> str =
factory->InternalizeUtf8String(constant_string_table[i].contents);
......
......@@ -60,6 +60,7 @@ namespace internal {
V(Oddball, true_value, TrueValue) \
V(Oddball, false_value, FalseValue) \
V(Oddball, uninitialized_value, UninitializedValue) \
V(Oddball, exception, Exception) \
V(Map, cell_map, CellMap) \
V(Map, global_property_cell_map, GlobalPropertyCellMap) \
V(Map, shared_function_info_map, SharedFunctionInfoMap) \
......@@ -187,6 +188,7 @@ namespace internal {
V(Map, uninitialized_map, UninitializedMap) \
V(Map, arguments_marker_map, ArgumentsMarkerMap) \
V(Map, no_interceptor_result_sentinel_map, NoInterceptorResultSentinelMap) \
V(Map, exception_map, ExceptionMap) \
V(Map, termination_exception_map, TerminationExceptionMap) \
V(Map, message_object_map, JSMessageObjectMap) \
V(Map, foreign_map, ForeignMap) \
......
......@@ -1161,7 +1161,7 @@ MaybeHandle<Object> KeyedLoadIC::Load(Handle<Object> object,
stub = sloppy_arguments_stub();
} else if (receiver->HasIndexedInterceptor()) {
stub = indexed_interceptor_stub();
} else if (!key->ToSmi()->IsFailure() &&
} else if (!Object::ToSmi(isolate(), key).is_null() &&
(!target().is_identical_to(sloppy_arguments_stub()))) {
stub = LoadElementStub(receiver);
}
......@@ -1655,10 +1655,9 @@ bool IsOutOfBoundsAccess(Handle<JSObject> receiver,
KeyedAccessStoreMode KeyedStoreIC::GetStoreMode(Handle<JSObject> receiver,
Handle<Object> key,
Handle<Object> value) {
ASSERT(!key->ToSmi()->IsFailure());
Smi* smi_key = NULL;
key->ToSmi()->To(&smi_key);
int index = smi_key->value();
Handle<Object> smi_key = Object::ToSmi(isolate(), key);
ASSERT(!smi_key.is_null() && smi_key->IsSmi());
int index = Handle<Smi>::cast(smi_key)->value();
bool oob_access = IsOutOfBoundsAccess(receiver, index);
// Don't consider this a growing store if the store would send the receiver to
// dictionary mode.
......@@ -1780,7 +1779,7 @@ MaybeHandle<Object> KeyedStoreIC::Store(Handle<Object> object,
if (object->IsJSObject()) {
Handle<JSObject> receiver = Handle<JSObject>::cast(object);
bool key_is_smi_like = key->IsSmi() || !key->ToSmi()->IsFailure();
bool key_is_smi_like = !Object::ToSmi(isolate(), key).is_null();
if (receiver->elements()->map() ==
isolate()->heap()->sloppy_arguments_elements_map()) {
if (strict_mode() == SLOPPY) {
......
......@@ -588,17 +588,17 @@ class Isolate {
// Interface to pending exception.
Object* pending_exception() {
ASSERT(has_pending_exception());
ASSERT(!thread_local_top_.pending_exception_->IsFailure());
ASSERT(!thread_local_top_.pending_exception_->IsException());
return thread_local_top_.pending_exception_;
}
void set_pending_exception(Object* exception) {
ASSERT(!exception->IsFailure());
thread_local_top_.pending_exception_ = exception;
void set_pending_exception(Object* exception_obj) {
ASSERT(!exception_obj->IsException());
thread_local_top_.pending_exception_ = exception_obj;
}
void clear_pending_exception() {
ASSERT(!thread_local_top_.pending_exception_->IsFailure());
ASSERT(!thread_local_top_.pending_exception_->IsException());
thread_local_top_.pending_exception_ = heap_.the_hole_value();
}
......@@ -607,7 +607,7 @@ class Isolate {
}
bool has_pending_exception() {
ASSERT(!thread_local_top_.pending_exception_->IsFailure());
ASSERT(!thread_local_top_.pending_exception_->IsException());
return !thread_local_top_.pending_exception_->IsTheHole();
}
......@@ -649,15 +649,15 @@ class Isolate {
Object* scheduled_exception() {
ASSERT(has_scheduled_exception());
ASSERT(!thread_local_top_.scheduled_exception_->IsFailure());
ASSERT(!thread_local_top_.scheduled_exception_->IsException());
return thread_local_top_.scheduled_exception_;
}
bool has_scheduled_exception() {
ASSERT(!thread_local_top_.scheduled_exception_->IsFailure());
ASSERT(!thread_local_top_.scheduled_exception_->IsException());
return thread_local_top_.scheduled_exception_ != heap_.the_hole_value();
}
void clear_scheduled_exception() {
ASSERT(!thread_local_top_.scheduled_exception_->IsFailure());
ASSERT(!thread_local_top_.scheduled_exception_->IsException());
thread_local_top_.scheduled_exception_ = heap_.the_hole_value();
}
......
......@@ -618,7 +618,7 @@ void Oddball::OddballVerify() {
CHECK(number->IsSmi());
int value = Smi::cast(number)->value();
// Hidden oddballs have negative smis.
const int kLeastHiddenOddballNumber = -4;
const int kLeastHiddenOddballNumber = -5;
CHECK_LE(value, 1);
CHECK(value >= kLeastHiddenOddballNumber);
}
......@@ -639,6 +639,8 @@ void Oddball::OddballVerify() {
CHECK(this == heap->arguments_marker());
} else if (map() == heap->termination_exception_map()) {
CHECK(this == heap->termination_exception());
} else if (map() == heap->exception_map()) {
CHECK(this == heap->exception());
} else {
UNREACHABLE();
}
......
......@@ -1002,6 +1002,11 @@ bool Object::IsTheHole() {
}
bool Object::IsException() {
return IsOddball() && Oddball::cast(this)->kind() == Oddball::kException;
}
bool Object::IsUninitialized() {
return IsOddball() && Oddball::cast(this)->kind() == Oddball::kUninitialized;
}
......@@ -1048,20 +1053,6 @@ Handle<Object> Object::ToSmi(Isolate* isolate, Handle<Object> object) {
}
// TODO(ishell): Use handlified version instead.
MaybeObject* Object::ToSmi() {
if (IsSmi()) return this;
if (IsHeapNumber()) {
double value = HeapNumber::cast(this)->value();
int int_value = FastD2I(value);
if (value == FastI2D(int_value) && Smi::IsValid(int_value)) {
return Smi::FromInt(int_value);
}
}
return Failure::Exception();
}
MaybeHandle<JSReceiver> Object::ToObject(Isolate* isolate,
Handle<Object> object) {
return ToObject(
......
......@@ -1450,7 +1450,8 @@ class Object : public MaybeObject {
// Oddball testing.
INLINE(bool IsUndefined());
INLINE(bool IsNull());
INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation.
INLINE(bool IsTheHole());
INLINE(bool IsException());
INLINE(bool IsUninitialized());
INLINE(bool IsTrue());
INLINE(bool IsFalse());
......@@ -1531,7 +1532,6 @@ class Object : public MaybeObject {
// Failure is returned otherwise.
static MUST_USE_RESULT inline Handle<Object> ToSmi(Isolate* isolate,
Handle<Object> object);
MUST_USE_RESULT inline MaybeObject* ToSmi();
void Lookup(Name* name, LookupResult* result);
......@@ -9814,6 +9814,7 @@ class Oddball: public HeapObject {
static const byte kUndefined = 5;
static const byte kUninitialized = 6;
static const byte kOther = 7;
static const byte kException = 8;
typedef FixedBodyDescriptor<kToStringOffset,
kToNumberOffset + kPointerSize,
......
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