From 99d9712bb0fbc6e6dfab9f483a36e097ac253b2e Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Tue, 29 Apr 2014 13:18:27 +0000 Subject: [PATCH] Return MaybeHandle from Object::ToSmi. R=ulan@chromium.org Review URL: https://codereview.chromium.org/260083011 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21047 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/elements.cc | 5 +++-- src/ic.cc | 5 ++--- src/objects-inl.h | 6 +++--- src/objects.h | 5 ++--- test/cctest/test-strings.cc | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/elements.cc b/src/elements.cc index 26b722b..580a718 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -1848,9 +1848,10 @@ MaybeHandle ElementsAccessorBase array = Handle::cast(obj); // Fast case: The new length fits into a Smi. - Handle smi_length = Object::ToSmi(isolate, length); + Handle smi_length; - if (!smi_length.is_null() && smi_length->IsSmi()) { + if (Object::ToSmi(isolate, length).ToHandle(&smi_length) && + smi_length->IsSmi()) { const int value = Handle::cast(smi_length)->value(); if (value >= 0) { Handle new_length = ElementsAccessorSubclass:: diff --git a/src/ic.cc b/src/ic.cc index 475db79..f442427 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -1614,9 +1614,8 @@ bool IsOutOfBoundsAccess(Handle receiver, KeyedAccessStoreMode KeyedStoreIC::GetStoreMode(Handle receiver, Handle key, Handle value) { - Handle smi_key = Object::ToSmi(isolate(), key); - ASSERT(!smi_key.is_null() && smi_key->IsSmi()); - int index = Handle::cast(smi_key)->value(); + Handle smi_key = Object::ToSmi(isolate(), key).ToHandleChecked(); + int index = 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. diff --git a/src/objects-inl.h b/src/objects-inl.h index 3939802..de77da0 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -1037,8 +1037,8 @@ bool Object::IsNaN() { } -Handle Object::ToSmi(Isolate* isolate, Handle object) { - if (object->IsSmi()) return object; +MaybeHandle Object::ToSmi(Isolate* isolate, Handle object) { + if (object->IsSmi()) return Handle::cast(object); if (object->IsHeapNumber()) { double value = Handle::cast(object)->value(); int int_value = FastD2I(value); @@ -1046,7 +1046,7 @@ Handle Object::ToSmi(Isolate* isolate, Handle object) { return handle(Smi::FromInt(int_value), isolate); } } - return Handle(); + return Handle(); } diff --git a/src/objects.h b/src/objects.h index 86042ac..5347309 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1490,9 +1490,8 @@ class Object : public MaybeObject { Handle context); // Converts this to a Smi if possible. - // Failure is returned otherwise. - static MUST_USE_RESULT inline Handle ToSmi(Isolate* isolate, - Handle object); + static MUST_USE_RESULT inline MaybeHandle ToSmi(Isolate* isolate, + Handle object); void Lookup(Name* name, LookupResult* result); diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc index f95000e..81294e8 100644 --- a/test/cctest/test-strings.cc +++ b/test/cctest/test-strings.cc @@ -1078,7 +1078,7 @@ TEST(CachedHashOverflow) { CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined()); CHECK_EQ(results[i]->IsNumber(), result->IsNumber()); if (result->IsNumber()) { - CHECK_EQ(Handle::cast(Object::ToSmi(isolate, results[i]))->value(), + CHECK_EQ(Object::ToSmi(isolate, results[i]).ToHandleChecked()->value(), result->ToInt32()->Value()); } } -- 2.7.4