diff --git a/src/isolate.cc b/src/isolate.cc index 451a975a22..91b8e8371f 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -893,7 +893,6 @@ Failure* Isolate::ReThrow(Object* exception) { // Set the exception being re-thrown. set_pending_exception(exception); - if (exception->IsFailure()) return exception->ToFailureUnchecked(); return Failure::Exception(); } diff --git a/src/objects-inl.h b/src/objects-inl.h index e38c2852b4..046c569805 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -673,16 +673,6 @@ bool MaybeObject::IsException() { } -bool MaybeObject::IsTheHole() { - return !IsFailure() && ToObjectUnchecked()->IsTheHole(); -} - - -bool MaybeObject::IsUninitialized() { - return !IsFailure() && ToObjectUnchecked()->IsUninitialized(); -} - - Failure* Failure::cast(MaybeObject* obj) { ASSERT(HAS_FAILURE_TAG(obj)); return reinterpret_cast(obj); @@ -1301,11 +1291,6 @@ Failure::Type Failure::type() const { } -bool Failure::IsInternalError() const { - return type() == INTERNAL_ERROR; -} - - AllocationSpace Failure::allocation_space() const { ASSERT_EQ(RETRY_AFTER_GC, type()); return static_cast((value() >> kFailureTypeTagSize) diff --git a/src/objects.h b/src/objects.h index 6fe4f3a79c..71bd97a625 100644 --- a/src/objects.h +++ b/src/objects.h @@ -924,17 +924,11 @@ class MaybeObject BASE_EMBEDDED { inline bool IsFailure(); inline bool IsRetryAfterGC(); inline bool IsException(); - INLINE(bool IsTheHole()); - INLINE(bool IsUninitialized()); inline bool ToObject(Object** obj) { if (IsFailure()) return false; *obj = reinterpret_cast(this); return true; } - inline Failure* ToFailureUnchecked() { - ASSERT(IsFailure()); - return reinterpret_cast(this); - } inline Object* ToObjectUnchecked() { // TODO(jkummerow): Turn this back into an ASSERT when we can be certain // that it never fires in Release mode in the wild. @@ -953,13 +947,6 @@ class MaybeObject BASE_EMBEDDED { return true; } - template - inline bool ToHandle(Handle* obj, Isolate* isolate) { - if (IsFailure()) return false; - *obj = handle(T::cast(reinterpret_cast(this)), isolate); - return true; - } - #ifdef OBJECT_PRINT // Prints this object with details. void Print(); @@ -1710,8 +1697,6 @@ class Failure: public MaybeObject { // Returns the space that needs to be collected for RetryAfterGC failures. inline AllocationSpace allocation_space() const; - inline bool IsInternalError() const; - static inline Failure* RetryAfterGC(AllocationSpace space); static inline Failure* RetryAfterGC(); // NEW_SPACE static inline Failure* Exception(); diff --git a/src/runtime.cc b/src/runtime.cc index 5cd4806646..551b048411 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -7272,6 +7272,7 @@ static void JoinSparseArrayWithSeparator(FixedArray* elements, uint32_t array_length, String* separator, Vector buffer) { + DisallowHeapAllocation no_gc; int previous_separator_position = 0; int separator_length = separator->length(); int cursor = 0; @@ -7310,10 +7311,10 @@ static void JoinSparseArrayWithSeparator(FixedArray* elements, RUNTIME_FUNCTION(MaybeObject*, Runtime_SparseJoinWithSeparator) { HandleScope scope(isolate); ASSERT(args.length() == 3); - CONVERT_ARG_CHECKED(JSArray, elements_array, 0); + CONVERT_ARG_HANDLE_CHECKED(JSArray, elements_array, 0); RUNTIME_ASSERT(elements_array->HasFastSmiOrObjectElements()); CONVERT_NUMBER_CHECKED(uint32_t, array_length, Uint32, args[1]); - CONVERT_ARG_CHECKED(String, separator, 2); + CONVERT_ARG_HANDLE_CHECKED(String, separator, 2); // elements_array is fast-mode JSarray of alternating positions // (increasing order) and strings. // array_length is length of original array (used to add separators); @@ -7323,25 +7324,28 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SparseJoinWithSeparator) { int string_length = 0; bool is_ascii = separator->IsOneByteRepresentation(); bool overflow = false; - CONVERT_NUMBER_CHECKED(int, elements_length, - Int32, elements_array->length()); + CONVERT_NUMBER_CHECKED(int, elements_length, Int32, elements_array->length()); RUNTIME_ASSERT((elements_length & 1) == 0); // Even length. - FixedArray* elements = FixedArray::cast(elements_array->elements()); - for (int i = 0; i < elements_length; i += 2) { - RUNTIME_ASSERT(elements->get(i)->IsNumber()); - RUNTIME_ASSERT(elements->get(i + 1)->IsString()); - String* string = String::cast(elements->get(i + 1)); - int length = string->length(); - if (is_ascii && !string->IsOneByteRepresentation()) { - is_ascii = false; + + { DisallowHeapAllocation no_gc; + FixedArray* elements = FixedArray::cast(elements_array->elements()); + for (int i = 0; i < elements_length; i += 2) { + RUNTIME_ASSERT(elements->get(i)->IsNumber()); + RUNTIME_ASSERT(elements->get(i + 1)->IsString()); + String* string = String::cast(elements->get(i + 1)); + int length = string->length(); + if (is_ascii && !string->IsOneByteRepresentation()) { + is_ascii = false; + } + if (length > String::kMaxLength || + String::kMaxLength - length < string_length) { + overflow = true; + break; + } + string_length += length; } - if (length > String::kMaxLength || - String::kMaxLength - length < string_length) { - overflow = true; - break; - } - string_length += length; } + int separator_length = separator->length(); if (!overflow && separator_length > 0) { if (array_length <= 0x7fffffffu) { @@ -7368,32 +7372,25 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SparseJoinWithSeparator) { } if (is_ascii) { - MaybeObject* result_allocation = - isolate->heap()->AllocateRawOneByteString(string_length); - if (result_allocation->IsFailure()) return result_allocation; - SeqOneByteString* result_string = - SeqOneByteString::cast(result_allocation->ToObjectUnchecked()); - JoinSparseArrayWithSeparator(elements, - elements_length, - array_length, - separator, - Vector( - result_string->GetChars(), - string_length)); - return result_string; + Handle result = isolate->factory()->NewRawOneByteString( + string_length).ToHandleChecked(); + JoinSparseArrayWithSeparator( + FixedArray::cast(elements_array->elements()), + elements_length, + array_length, + *separator, + Vector(result->GetChars(), string_length)); + return *result; } else { - MaybeObject* result_allocation = - isolate->heap()->AllocateRawTwoByteString(string_length); - if (result_allocation->IsFailure()) return result_allocation; - SeqTwoByteString* result_string = - SeqTwoByteString::cast(result_allocation->ToObjectUnchecked()); - JoinSparseArrayWithSeparator(elements, - elements_length, - array_length, - separator, - Vector(result_string->GetChars(), - string_length)); - return result_string; + Handle result = isolate->factory()->NewRawTwoByteString( + string_length).ToHandleChecked(); + JoinSparseArrayWithSeparator( + FixedArray::cast(elements_array->elements()), + elements_length, + array_length, + *separator, + Vector(result->GetChars(), string_length)); + return *result; } } @@ -9171,15 +9168,6 @@ static inline ObjectPair MakePair(MaybeObject* x, MaybeObject* y) { #endif -static inline MaybeObject* Unhole(Heap* heap, - MaybeObject* x, - PropertyAttributes attributes) { - ASSERT(!x->IsTheHole() || (attributes & READ_ONLY) != 0); - USE(attributes); - return x->IsTheHole() ? heap->undefined_value() : x; -} - - static Object* ComputeReceiverForNonGlobal(Isolate* isolate, JSObject* holder) { ASSERT(!holder->IsGlobalObject()); @@ -9249,7 +9237,11 @@ static ObjectPair LoadContextSlotHelper(Arguments args, ASSERT(!value->IsTheHole()); return MakePair(value, *receiver); case IMMUTABLE_CHECK_INITIALIZED: - return MakePair(Unhole(isolate->heap(), value, attributes), *receiver); + if (value->IsTheHole()) { + ASSERT((attributes & READ_ONLY) != 0); + value = isolate->heap()->undefined_value(); + } + return MakePair(value, *receiver); case MISSING_BINDING: UNREACHABLE(); return MakePair(NULL, NULL); diff --git a/test/cctest/test-global-handles.cc b/test/cctest/test-global-handles.cc index 48b6655bbc..1ab90ec5ec 100644 --- a/test/cctest/test-global-handles.cc +++ b/test/cctest/test-global-handles.cc @@ -86,19 +86,19 @@ class TestObjectVisitor : public ObjectVisitor { TEST(IterateObjectGroupsOldApi) { CcTest::InitializeVM(); - GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); - Heap* heap = CcTest::heap(); + Isolate* isolate = CcTest::i_isolate(); + GlobalHandles* global_handles = isolate->global_handles(); v8::HandleScope handle_scope(CcTest::isolate()); Handle g1s1 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g1s2 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g2s1 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g2s2 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); TestRetainedObjectInfo info1; TestRetainedObjectInfo info2; @@ -181,20 +181,20 @@ TEST(IterateObjectGroupsOldApi) { TEST(IterateObjectGroups) { CcTest::InitializeVM(); - GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); - Heap* heap = CcTest::heap(); + Isolate* isolate = CcTest::i_isolate(); + GlobalHandles* global_handles = isolate->global_handles(); v8::HandleScope handle_scope(CcTest::isolate()); Handle g1s1 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g1s2 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g2s1 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g2s2 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); TestRetainedObjectInfo info1; TestRetainedObjectInfo info2; @@ -276,25 +276,25 @@ TEST(IterateObjectGroups) { TEST(ImplicitReferences) { CcTest::InitializeVM(); - GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); - Heap* heap = CcTest::heap(); + Isolate* isolate = CcTest::i_isolate(); + GlobalHandles* global_handles = isolate->global_handles(); v8::HandleScope handle_scope(CcTest::isolate()); Handle g1s1 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g1c1 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g1c2 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g2s1 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g2s2 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); Handle g2c1 = - global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); + global_handles->Create(*isolate->factory()->NewFixedArray(1)); global_handles->SetObjectGroupId(g1s1.location(), UniqueId(1)); global_handles->SetObjectGroupId(g2s1.location(), UniqueId(2)); diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc index d4dc51692d..0574c69590 100644 --- a/test/cctest/test-strings.cc +++ b/test/cctest/test-strings.cc @@ -1087,7 +1087,7 @@ TEST(CachedHashOverflow) { CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined()); CHECK_EQ(results[i]->IsNumber(), result->IsNumber()); if (result->IsNumber()) { - CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), + CHECK_EQ(Handle::cast(Object::ToSmi(isolate, results[i]))->value(), result->ToInt32()->Value()); } }