Commit 1964b196 authored by machenbach's avatar machenbach Committed by Commit bot

Revert of [handles] Sanitize Handle and friends. (patchset #5 id:180001 of...

Revert of [handles] Sanitize Handle and friends. (patchset #5 id:180001 of https://codereview.chromium.org/1128533002/)

Reason for revert:
[Sheriff] Still breaks mac asan:
http://build.chromium.org/p/client.v8/builders/V8%20Mac64%20ASAN/builds/2066

Original issue's description:
> [handles] Sanitize Handle and friends.
>
> Bunch of cleanups to allow us to get rid of handles-inl.h at some
> point (in the not so far future); but more importantly to sanitize uses
> of handles and prepare for handle canonicalization support.
>
> R=yangguo@chromium.org
>
> Committed: https://crrev.com/3283195d0408333cce552cf4087577e6f41054e5
> Cr-Commit-Position: refs/heads/master@{#28222}
>
> Committed: https://crrev.com/d940c6d3bcc227b459cb4123d9a8332d9ed0d5f8
> Cr-Commit-Position: refs/heads/master@{#29666}

TBR=yangguo@chromium.org,bmeurer@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

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

Cr-Commit-Position: refs/heads/master@{#29669}
parent edc61b26
......@@ -3797,8 +3797,7 @@ MaybeLocal<String> v8::Object::ObjectProtoToString(Local<Context> context) {
isolate, self, toStringTag).ToHandle(&tag);
RETURN_ON_FAILED_EXECUTION(String);
if (tag->IsString()) {
class_name = Utils::OpenHandle(*handle_scope.Escape(
Utils::ToLocal(i::Handle<i::String>::cast(tag))));
class_name = i::Handle<i::String>::cast(tag).EscapeFrom(&handle_scope);
}
}
const char* prefix = "[object ";
......
......@@ -308,6 +308,17 @@ OPEN_HANDLE_LIST(DECLARE_OPEN_HANDLE)
};
template <class T>
v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom(
v8::EscapableHandleScope* scope) {
v8::internal::Handle<T> handle;
if (!is_null()) {
handle = *this;
}
return Utils::OpenHandle(*scope->Escape(Utils::ToLocal(handle)), true);
}
template <class T>
inline T* ToApi(v8::internal::Handle<v8::internal::Object> obj) {
return reinterpret_cast<T*>(obj.location());
......
// Copyright 2006-2008 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef V8_HANDLES_INL_H_
#define V8_HANDLES_INL_H_
......@@ -13,8 +14,72 @@
namespace v8 {
namespace internal {
HandleBase::HandleBase(Object* object, Isolate* isolate)
: location_(HandleScope::CreateHandle(isolate, object)) {}
template<typename T>
Handle<T>::Handle(T* obj) {
location_ = HandleScope::CreateHandle(obj->GetIsolate(), obj);
}
template<typename T>
Handle<T>::Handle(T* obj, Isolate* isolate) {
location_ = HandleScope::CreateHandle(isolate, obj);
}
template <typename T>
inline bool Handle<T>::is_identical_to(const Handle<T> o) const {
// Dereferencing deferred handles to check object equality is safe.
SLOW_DCHECK(
(location_ == NULL || IsDereferenceAllowed(NO_DEFERRED_CHECK)) &&
(o.location_ == NULL || o.IsDereferenceAllowed(NO_DEFERRED_CHECK)));
if (location_ == o.location_) return true;
if (location_ == NULL || o.location_ == NULL) return false;
return *location_ == *o.location_;
}
template <typename T>
inline T* Handle<T>::operator*() const {
SLOW_DCHECK(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK));
return *bit_cast<T**>(location_);
}
template <typename T>
inline T** Handle<T>::location() const {
SLOW_DCHECK(location_ == NULL ||
IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK));
return location_;
}
#ifdef DEBUG
template <typename T>
bool Handle<T>::IsDereferenceAllowed(DereferenceCheckMode mode) const {
DCHECK(location_ != NULL);
Object* object = *bit_cast<T**>(location_);
if (object->IsSmi()) return true;
HeapObject* heap_object = HeapObject::cast(object);
Heap* heap = heap_object->GetHeap();
Object** handle = reinterpret_cast<Object**>(location_);
Object** roots_array_start = heap->roots_array_start();
if (roots_array_start <= handle &&
handle < roots_array_start + Heap::kStrongRootListLength &&
heap->RootCanBeTreatedAsConstant(
static_cast<Heap::RootListIndex>(handle - roots_array_start))) {
return true;
}
if (!AllowHandleDereference::IsAllowed()) return false;
if (mode == INCLUDE_DEFERRED_CHECK &&
!AllowDeferredHandleDereference::IsAllowed()) {
// Accessing cells, maps and internalized strings is safe.
if (heap_object->IsCell()) return true;
if (heap_object->IsMap()) return true;
if (heap_object->IsInternalizedString()) return true;
return !heap->isolate()->IsDeferredHandle(handle);
}
return true;
}
#endif
HandleScope::HandleScope(Isolate* isolate) {
......@@ -71,7 +136,7 @@ Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) {
CloseScope(isolate_, prev_next_, prev_limit_);
// Allocate one handle in the parent scope.
DCHECK(current->level > 0);
Handle<T> result(value, isolate_);
Handle<T> result(CreateHandle<T>(isolate_, value));
// Reinitialize the current scope (so that it's ready
// to be used or closed again).
prev_next_ = current->next;
......@@ -86,7 +151,7 @@ T** HandleScope::CreateHandle(Isolate* isolate, T* value) {
DCHECK(AllowHandleAllocation::IsAllowed());
HandleScopeData* current = isolate->handle_scope_data();
Object** cur = current->next;
internal::Object** cur = current->next;
if (cur == current->limit) cur = Extend(isolate);
// Update the current next field, set the value in the created
// handle, and return the result.
......@@ -125,7 +190,6 @@ inline SealHandleScope::~SealHandleScope() {
#endif
} // namespace internal
} // namespace v8
} } // namespace v8::internal
#endif // V8_HANDLES_INL_H_
......@@ -9,34 +9,6 @@
namespace v8 {
namespace internal {
#ifdef DEBUG
bool HandleBase::IsDereferenceAllowed(DereferenceCheckMode mode) const {
DCHECK_NOT_NULL(location_);
Object* object = *location_;
if (object->IsSmi()) return true;
HeapObject* heap_object = HeapObject::cast(object);
Heap* heap = heap_object->GetHeap();
Object** roots_array_start = heap->roots_array_start();
if (roots_array_start <= location_ &&
location_ < roots_array_start + Heap::kStrongRootListLength &&
heap->RootCanBeTreatedAsConstant(
static_cast<Heap::RootListIndex>(location_ - roots_array_start))) {
return true;
}
if (!AllowHandleDereference::IsAllowed()) return false;
if (mode == INCLUDE_DEFERRED_CHECK &&
!AllowDeferredHandleDereference::IsAllowed()) {
// Accessing cells, maps and internalized strings is safe.
if (heap_object->IsCell()) return true;
if (heap_object->IsMap()) return true;
if (heap_object->IsInternalizedString()) return true;
return !heap->isolate()->IsDeferredHandle(location_);
}
return true;
}
#endif
int HandleScope::NumberOfHandles(Isolate* isolate) {
HandleScopeImplementer* impl = isolate->handle_scope_implementer();
int n = impl->blocks()->length();
......@@ -95,7 +67,7 @@ void HandleScope::DeleteExtensions(Isolate* isolate) {
void HandleScope::ZapRange(Object** start, Object** end) {
DCHECK(end - start <= kHandleBlockSize);
for (Object** p = start; p != end; p++) {
*reinterpret_cast<Address*>(p) = kHandleZapValue;
*reinterpret_cast<Address*>(p) = v8::internal::kHandleZapValue;
}
}
#endif
......
This diff is collapsed.
......@@ -973,6 +973,22 @@ TEST(Iteration) {
}
TEST(EmptyHandleEscapeFrom) {
CcTest::InitializeVM();
v8::HandleScope scope(CcTest::isolate());
Handle<JSObject> runaway;
{
v8::EscapableHandleScope nested(CcTest::isolate());
Handle<JSObject> empty;
runaway = empty.EscapeFrom(&nested);
}
CHECK(runaway.is_null());
}
static int LenFromSize(int size) {
return (size - FixedArray::kHeaderSize) / 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