From 77a28b731d704c5786e52cabae5fc14b4d875db3 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Thu, 20 Mar 2014 12:22:13 +0000 Subject: [PATCH] Handlify callers to GetElementNoException. R=ishell@chromium.org Review URL: https://codereview.chromium.org/204693002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20117 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/api.cc | 7 +++-- src/execution.cc | 8 +++--- src/factory.cc | 3 +- src/liveedit.cc | 75 ++++++++++++++++++++++++------------------------- src/log.cc | 4 +-- src/objects-inl.h | 19 +++++++++---- src/objects.cc | 16 ++++------- src/objects.h | 5 +++- test/cctest/test-api.cc | 5 ++-- 9 files changed, 74 insertions(+), 68 deletions(-) diff --git a/src/api.cc b/src/api.cc index d0c9d26..b94a9d5 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2203,9 +2203,10 @@ Local StackTrace::GetFrame(uint32_t index) const { ENTER_V8(isolate); EscapableHandleScope scope(reinterpret_cast(isolate)); i::Handle self = Utils::OpenHandle(this); - i::Object* raw_object = self->GetElementNoExceptionThrown(isolate, index); - i::Handle obj(i::JSObject::cast(raw_object)); - return scope.Escape(Utils::StackFrameToLocal(obj)); + i::Handle obj = + i::Object::GetElementNoExceptionThrown(isolate, self, index); + i::Handle jsobj = i::Handle::cast(obj); + return scope.Escape(Utils::StackFrameToLocal(jsobj)); } diff --git a/src/execution.cc b/src/execution.cc index 924814c..1e0a6a8 100644 --- a/src/execution.cc +++ b/src/execution.cc @@ -819,10 +819,10 @@ Handle Execution::InstantiateFunction( if (!data->do_not_cache()) { // Fast case: see if the function has already been instantiated int serial_number = Smi::cast(data->serial_number())->value(); - Object* elm = - isolate->native_context()->function_cache()-> - GetElementNoExceptionThrown(isolate, serial_number); - if (elm->IsJSFunction()) return Handle(JSFunction::cast(elm)); + Handle cache(isolate->native_context()->function_cache()); + Handle elm = + Object::GetElementNoExceptionThrown(isolate, cache, serial_number); + if (elm->IsJSFunction()) return Handle::cast(elm); } // The function has not yet been instantiated in this context; do it. Handle args[] = { data }; diff --git a/src/factory.cc b/src/factory.cc index 57574d1..55529e5 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1132,8 +1132,7 @@ Handle Factory::EmergencyNewError(const char* message, space--; if (space > 0) { Handle arg_str = Handle::cast( - Object::GetElement(isolate(), args, i)); - CHECK_NOT_EMPTY_HANDLE(isolate(), arg_str); + Object::GetElementNoExceptionThrown(isolate(), args, i)); SmartArrayPointer arg = arg_str->ToCString(); Vector v2(p, static_cast(space)); OS::StrNCpy(v2, arg.get(), space); diff --git a/src/liveedit.cc b/src/liveedit.cc index aa906b2..a812b75 100644 --- a/src/liveedit.cc +++ b/src/liveedit.cc @@ -669,13 +669,13 @@ class JSArrayBasedStruct { field_position, Handle(Smi::FromInt(value), isolate())); } - Object* GetField(int field_position) { - return array_->GetElementNoExceptionThrown(isolate(), field_position); + Handle GetField(int field_position) { + return Object::GetElementNoExceptionThrown( + isolate(), array_, field_position); } int GetSmiValueField(int field_position) { - Object* res = GetField(field_position); - CHECK(res->IsSmi()); - return Smi::cast(res)->value(); + Handle res = GetField(field_position); + return Handle::cast(res)->value(); } private: @@ -724,17 +724,15 @@ class FunctionInfoWrapper : public JSArrayBasedStruct { return this->GetSmiValueField(kParentIndexOffset_); } Handle GetFunctionCode() { - Object* element = this->GetField(kCodeOffset_); - CHECK(element->IsJSValue()); - Handle value_wrapper(JSValue::cast(element)); + Handle element = this->GetField(kCodeOffset_); + Handle value_wrapper = Handle::cast(element); Handle raw_result = UnwrapJSValue(value_wrapper); CHECK(raw_result->IsCode()); return Handle::cast(raw_result); } Handle GetCodeScopeInfo() { - Object* element = this->GetField(kCodeScopeInfoOffset_); - CHECK(element->IsJSValue()); - return UnwrapJSValue(Handle(JSValue::cast(element))); + Handle element = this->GetField(kCodeScopeInfoOffset_); + return UnwrapJSValue(Handle::cast(element)); } int GetStartPosition() { return this->GetSmiValueField(kStartPositionOffset_); @@ -767,8 +765,8 @@ class SharedInfoWrapper : public JSArrayBasedStruct { public: static bool IsInstance(Handle array) { return array->length() == Smi::FromInt(kSize_) && - array->GetElementNoExceptionThrown( - array->GetIsolate(), kSharedInfoOffset_)->IsJSValue(); + Object::GetElementNoExceptionThrown( + array->GetIsolate(), array, kSharedInfoOffset_)->IsJSValue(); } explicit SharedInfoWrapper(Handle array) @@ -785,9 +783,8 @@ class SharedInfoWrapper : public JSArrayBasedStruct { this->SetSmiValueField(kEndPositionOffset_, end_position); } Handle GetInfo() { - Object* element = this->GetField(kSharedInfoOffset_); - CHECK(element->IsJSValue()); - Handle value_wrapper(JSValue::cast(element)); + Handle element = this->GetField(kSharedInfoOffset_); + Handle value_wrapper = Handle::cast(element); return UnwrapSharedFunctionInfoFromJSValue(value_wrapper); } @@ -826,8 +823,8 @@ class FunctionInfoListener { HandleScope scope(isolate()); FunctionInfoWrapper info = FunctionInfoWrapper::cast( - result_->GetElementNoExceptionThrown( - isolate(), current_parent_index_)); + *Object::GetElementNoExceptionThrown( + isolate(), result_, current_parent_index_)); current_parent_index_ = info.GetParentIndex(); } @@ -836,8 +833,8 @@ class FunctionInfoListener { void FunctionCode(Handle function_code) { FunctionInfoWrapper info = FunctionInfoWrapper::cast( - result_->GetElementNoExceptionThrown( - isolate(), current_parent_index_)); + *Object::GetElementNoExceptionThrown( + isolate(), result_, current_parent_index_)); info.SetFunctionCode(function_code, Handle(isolate()->heap()->null_value())); } @@ -851,8 +848,8 @@ class FunctionInfoListener { } FunctionInfoWrapper info = FunctionInfoWrapper::cast( - result_->GetElementNoExceptionThrown( - isolate(), current_parent_index_)); + *Object::GetElementNoExceptionThrown( + isolate(), result_, current_parent_index_)); info.SetFunctionCode(Handle(shared->code()), Handle(shared->scope_info())); info.SetSharedFunctionInfo(shared); @@ -987,7 +984,7 @@ void LiveEdit::WrapSharedFunctionInfos(Handle array) { for (int i = 0; i < len; i++) { Handle info( SharedFunctionInfo::cast( - array->GetElementNoExceptionThrown(isolate, i))); + *Object::GetElementNoExceptionThrown(isolate, array, i))); SharedInfoWrapper info_wrapper = SharedInfoWrapper::Create(isolate); Handle name_handle(String::cast(info->name())); info_wrapper.SetProperties(name_handle, info->start_position(), @@ -1361,23 +1358,24 @@ static int TranslatePosition(int original_position, Isolate* isolate = position_change_array->GetIsolate(); // TODO(635): binary search may be used here for (int i = 0; i < array_len; i += 3) { - Object* element = - position_change_array->GetElementNoExceptionThrown(isolate, i); + HandleScope scope(isolate); + Handle element = Object::GetElementNoExceptionThrown( + isolate, position_change_array, i); CHECK(element->IsSmi()); - int chunk_start = Smi::cast(element)->value(); + int chunk_start = Handle::cast(element)->value(); if (original_position < chunk_start) { break; } - element = position_change_array->GetElementNoExceptionThrown(isolate, - i + 1); + element = Object::GetElementNoExceptionThrown( + isolate, position_change_array, i + 1); CHECK(element->IsSmi()); - int chunk_end = Smi::cast(element)->value(); + int chunk_end = Handle::cast(element)->value(); // Position mustn't be inside a chunk. ASSERT(original_position >= chunk_end); - element = position_change_array->GetElementNoExceptionThrown(isolate, - i + 2); + element = Object::GetElementNoExceptionThrown( + isolate, position_change_array, i + 2); CHECK(element->IsSmi()); - int chunk_changed_end = Smi::cast(element)->value(); + int chunk_changed_end = Handle::cast(element)->value(); position_diff = chunk_changed_end - chunk_end; } @@ -1472,7 +1470,6 @@ static Handle PatchPositionsInCode( code->instruction_start()); { - DisallowHeapAllocation no_allocation; for (RelocIterator it(*code); !it.done(); it.next()) { RelocInfo* rinfo = it.rinfo(); if (RelocInfo::IsPosition(rinfo->rmode())) { @@ -1631,10 +1628,10 @@ static bool CheckActivation(Handle shared_info_array, Isolate* isolate = shared_info_array->GetIsolate(); int len = GetArrayLength(shared_info_array); for (int i = 0; i < len; i++) { - Object* element = - shared_info_array->GetElementNoExceptionThrown(isolate, i); - CHECK(element->IsJSValue()); - Handle jsvalue(JSValue::cast(element)); + HandleScope scope(isolate); + Handle element = + Object::GetElementNoExceptionThrown(isolate, shared_info_array, i); + Handle jsvalue = Handle::cast(element); Handle shared = UnwrapSharedFunctionInfoFromJSValue(jsvalue); @@ -1949,8 +1946,8 @@ static const char* DropActivationsInActiveThread( // Replace "blocked on active" with "replaced on active" status. for (int i = 0; i < array_len; i++) { - Handle obj = Object::GetElement(isolate, result, i); - CHECK_NOT_EMPTY_HANDLE(isolate, obj); + Handle obj = + Object::GetElementNoExceptionThrown(isolate, result, i); if (*obj == Smi::FromInt(LiveEdit::FUNCTION_BLOCKED_ON_ACTIVE_STACK)) { Handle replaced( Smi::FromInt(LiveEdit::FUNCTION_REPLACED_ON_ACTIVE_STACK), isolate); diff --git a/src/log.cc b/src/log.cc index e01692e..942170c 100644 --- a/src/log.cc +++ b/src/log.cc @@ -1206,9 +1206,9 @@ void Logger::LogRuntime(Vector format, if (c == '%' && i <= format.length() - 2) { i++; ASSERT('0' <= format[i] && format[i] <= '9'); - Handle obj = Object::GetElement(isolate_, args, format[i] - '0'); // No exception expected when getting an element from an array literal. - CHECK_NOT_EMPTY_HANDLE(isolate_, obj); + Handle obj = + Object::GetElementNoExceptionThrown(isolate_, args, format[i] - '0'); i++; switch (format[i]) { case 's': diff --git a/src/objects-inl.h b/src/objects-inl.h index 83f11e7..811b2f9 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -1077,11 +1077,20 @@ Handle Object::GetElement(Isolate* isolate, } -Object* Object::GetElementNoExceptionThrown(Isolate* isolate, uint32_t index) { - MaybeObject* maybe = GetElementWithReceiver(isolate, this, index); - ASSERT(!maybe->IsFailure()); - Object* result = NULL; // Initialization to please compiler. - maybe->ToObject(&result); +static Handle GetElementNoExceptionThrownHelper(Isolate* isolate, + Handle object, + uint32_t index) { + CALL_HEAP_FUNCTION(isolate, + object->GetElementWithReceiver(isolate, *object, index), + Object); +} + +Handle Object::GetElementNoExceptionThrown(Isolate* isolate, + Handle object, + uint32_t index) { + Handle result = + GetElementNoExceptionThrownHelper(isolate, object, index); + CHECK_NOT_EMPTY_HANDLE(isolate, result); return result; } diff --git a/src/objects.cc b/src/objects.cc index 5d36a63..88e7234 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -5179,8 +5179,7 @@ Handle JSObject::DeleteElement(Handle object, if (object->GetLocalElementAccessorPair(index) != NULL) { old_value = Handle::cast(factory->the_hole_value()); } else { - old_value = Object::GetElement(isolate, object, index); - CHECK_NOT_EMPTY_HANDLE(isolate, old_value); + old_value = Object::GetElementNoExceptionThrown(isolate, object, index); } } } @@ -6349,8 +6348,7 @@ void JSObject::DefineAccessor(Handle object, if (is_element) { preexists = HasLocalElement(object, index); if (preexists && object->GetLocalElementAccessorPair(index) == NULL) { - old_value = Object::GetElement(isolate, object, index); - CHECK_NOT_EMPTY_HANDLE(isolate, old_value); + old_value = Object::GetElementNoExceptionThrown(isolate, object, index); } } else { LookupResult lookup(isolate); @@ -11332,8 +11330,7 @@ static bool GetOldValue(Isolate* isolate, if (object->GetLocalElementAccessorPair(index) != NULL) { value = Handle::cast(isolate->factory()->the_hole_value()); } else { - value = Object::GetElement(isolate, object, index); - CHECK_NOT_EMPTY_HANDLE(isolate, value); + value = Object::GetElementNoExceptionThrown(isolate, object, index); } old_values->Add(value); indices->Add(index); @@ -12553,8 +12550,7 @@ Handle JSObject::SetElement(Handle object, if (old_attributes != ABSENT) { if (object->GetLocalElementAccessorPair(index) == NULL) { - old_value = Object::GetElement(isolate, object, index); - CHECK_NOT_EMPTY_HANDLE(isolate, old_value); + old_value = Object::GetElementNoExceptionThrown(isolate, object, index); } } else if (object->IsJSArray()) { // Store old array length in case adding an element grows the array. @@ -12600,8 +12596,8 @@ Handle JSObject::SetElement(Handle object, } else if (old_value->IsTheHole()) { EnqueueChangeRecord(object, "reconfigure", name, old_value); } else { - Handle new_value = Object::GetElement(isolate, object, index); - CHECK_NOT_EMPTY_HANDLE(isolate, new_value); + Handle new_value = + Object::GetElementNoExceptionThrown(isolate, object, index); bool value_changed = !old_value->SameValue(*new_value); if (old_attributes != new_attributes) { if (!value_changed) old_value = isolate->factory()->the_hole_value(); diff --git a/src/objects.h b/src/objects.h index a87e389..25dbcbb 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1586,7 +1586,10 @@ class Object : public MaybeObject { uint32_t index); // For use when we know that no exception can be thrown. - inline Object* GetElementNoExceptionThrown(Isolate* isolate, uint32_t index); + static inline Handle GetElementNoExceptionThrown( + Isolate* isolate, + Handle object, + uint32_t index); MUST_USE_RESULT MaybeObject* GetElementWithReceiver(Isolate* isolate, Object* receiver, uint32_t index); diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 6173e35..818b984 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -21982,8 +21982,9 @@ THREADED_TEST(FunctionNew) { i::Smi::cast(v8::Utils::OpenHandle(*func) ->shared()->get_api_func_data()->serial_number())->value(); i::Isolate* i_isolate = reinterpret_cast(isolate); - i::Object* elm = i_isolate->native_context()->function_cache() - ->GetElementNoExceptionThrown(i_isolate, serial_number); + i::Handle cache(i_isolate->native_context()->function_cache()); + i::Handle elm = + i::Object::GetElementNoExceptionThrown(i_isolate, cache, serial_number); CHECK(elm->IsUndefined()); // Verify that each Function::New creates a new function instance Local data2 = v8::Object::New(isolate); -- 2.7.4