Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Unified Diff: src/handles-inl.h

Issue 1128533002: [handles] Sanitize Handle and friends. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Lower kTargetRecursionDepth. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/handles.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/handles-inl.h
diff --git a/src/handles-inl.h b/src/handles-inl.h
index 3022f288a3919230c955c01c90d5773d731fac6d..b905c16a04f4e1f33342243aef9a77c01a268b2c 100644
--- a/src/handles-inl.h
+++ b/src/handles-inl.h
@@ -1,7 +1,6 @@
// 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_
@@ -14,72 +13,8 @@
namespace v8 {
namespace internal {
-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
-
+HandleBase::HandleBase(Object* object, Isolate* isolate)
+ : location_(HandleScope::CreateHandle(isolate, object)) {}
HandleScope::HandleScope(Isolate* isolate) {
@@ -136,7 +71,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(CreateHandle<T>(isolate_, value));
+ Handle<T> result(value, isolate_);
// Reinitialize the current scope (so that it's ready
// to be used or closed again).
prev_next_ = current->next;
@@ -151,7 +86,7 @@ T** HandleScope::CreateHandle(Isolate* isolate, T* value) {
DCHECK(AllowHandleAllocation::IsAllowed());
HandleScopeData* current = isolate->handle_scope_data();
- internal::Object** cur = current->next;
+ 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.
@@ -190,6 +125,7 @@ inline SealHandleScope::~SealHandleScope() {
#endif
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_HANDLES_INL_H_
« no previous file with comments | « src/handles.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698