Fix bug in compilation-handlescope.
authorsanjoy@chromium.org <sanjoy@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 6 Jul 2012 14:09:11 +0000 (14:09 +0000)
committersanjoy@chromium.org <sanjoy@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 6 Jul 2012 14:09:11 +0000 (14:09 +0000)
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com/10696125

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12003 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/api.cc
src/api.h
src/handles.cc

index 376b29616b8b59fa02d391e153c680ed618ed062..4b1a3a1618228faa480cb0cd686042e359e85472 100644 (file)
@@ -6457,6 +6457,12 @@ DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) {
     blocks_.RemoveLast();
   }
 
+  // deferred->blocks_ now contains the blocks installed on the
+  // HandleScope stack since BeginDeferredScope was called, but in
+  // reverse order.
+
+  ASSERT(prev_limit == NULL || !blocks_.is_empty());
+
   ASSERT(!blocks_.is_empty() && prev_limit != NULL);
   deferred_handles_head_ = deferred;
   ASSERT(last_handle_before_deferred_block_ != NULL);
@@ -6466,6 +6472,13 @@ DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) {
 
 
 void HandleScopeImplementer::DestroyDeferredHandles(DeferredHandles* deferred) {
+#ifdef DEBUG
+  DeferredHandles* deferred_iterator = deferred;
+  while (deferred_iterator->previous_ != NULL) {
+    deferred_iterator = deferred_iterator->previous_;
+  }
+  ASSERT(deferred_handles_head_ == deferred_iterator);
+#endif
   if (deferred_handles_head_ == deferred) {
     deferred_handles_head_ = deferred_handles_head_->next_;
   }
@@ -6500,14 +6513,14 @@ DeferredHandles::~DeferredHandles() {
 void DeferredHandles::Iterate(ObjectVisitor* v) {
   ASSERT(!blocks_.is_empty());
 
-  for (int i = 0; i < (blocks_.length() - 1); i++) {
-    v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
-  }
+  ASSERT((first_block_limit_ >= blocks_.first()) &&
+         (first_block_limit_ < &(blocks_.first())[kHandleBlockSize]));
 
-  ASSERT((last_block_limit_ >= blocks_.last()) &&
-         (last_block_limit_ < &(blocks_.last())[kHandleBlockSize]));
+  v->VisitPointers(blocks_.first(), first_block_limit_);
 
-  v->VisitPointers(blocks_.last(), last_block_limit_);
+  for (int i = 1; i < blocks_.length(); i++) {
+    v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
+  }
 }
 
 
index cd6c3da078af24b0a83bf640e950ca33c60ec884..2341c4c8fc59d809e708e04337ccdb97c2401152 100644 (file)
--- a/src/api.h
+++ b/src/api.h
@@ -397,9 +397,9 @@ class DeferredHandles {
   ~DeferredHandles();
 
  private:
-  DeferredHandles(DeferredHandles* next, Object** last_block_limit,
+  DeferredHandles(DeferredHandles* next, Object** first_block_limit,
                   HandleScopeImplementer* impl)
-      : next_(next), previous_(NULL), last_block_limit_(last_block_limit),
+      : next_(next), previous_(NULL), first_block_limit_(first_block_limit),
         impl_(impl) {}
 
   void Iterate(ObjectVisitor* v);
@@ -407,7 +407,7 @@ class DeferredHandles {
   List<Object**> blocks_;
   DeferredHandles* next_;
   DeferredHandles* previous_;
-  Object** last_block_limit_;
+  Object** first_block_limit_;
   HandleScopeImplementer* impl_;
 
   friend class HandleScopeImplementer;
@@ -477,6 +477,8 @@ class HandleScopeImplementer {
     entered_contexts_.Initialize(0);
     saved_contexts_.Initialize(0);
     spare_ = NULL;
+    deferred_handles_head_ = NULL;
+    last_handle_before_deferred_block_ = NULL;
     call_depth_ = 0;
   }
 
@@ -484,6 +486,7 @@ class HandleScopeImplementer {
     ASSERT(blocks_.length() == 0);
     ASSERT(entered_contexts_.length() == 0);
     ASSERT(saved_contexts_.length() == 0);
+    ASSERT(deferred_handles_head_ == NULL);
     blocks_.Free();
     entered_contexts_.Free();
     saved_contexts_.Free();
index 946c1008aae1975ce143aaaee9c2cbb3c0f88b6e..e98e8433b60ea3f230751fefbb0683439ac5eee3 100644 (file)
@@ -961,13 +961,15 @@ int Utf8Length(Handle<String> str) {
 
 DeferredHandleScope::DeferredHandleScope(Isolate* isolate)
     : impl_(isolate->handle_scope_implementer()) {
+  ASSERT(impl_->isolate() == Isolate::Current());
   impl_->BeginDeferredScope();
+  v8::ImplementationUtilities::HandleScopeData* data =
+      impl_->isolate()->handle_scope_data();
   Object** new_next = impl_->GetSpareOrNewBlock();
   Object** new_limit = &new_next[kHandleBlockSize];
+  ASSERT(data->limit == &impl_->blocks()->last()[kHandleBlockSize]);
   impl_->blocks()->Add(new_next);
 
-  v8::ImplementationUtilities::HandleScopeData* data =
-      impl_->isolate()->handle_scope_data();
 #ifdef DEBUG
   prev_level_ = data->level;
 #endif