Removed apiutils.h and related cleanup.
authorsvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 16 Jan 2014 08:17:40 +0000 (08:17 +0000)
committersvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 16 Jan 2014 08:17:40 +0000 (08:17 +0000)
ExtensionConfiguration is just a simple container for extension names
(in a perfect world we would use vector<string> and range-based for
loops), and HandleScopeData was in the totally wrong place. Some
additional cleanup on the way, e.g. using the null pattern behind our
external API.

R=dcarney@chromium.org

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

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

12 files changed:
include/v8.h
src/api.cc
src/api.h
src/apiutils.h [deleted file]
src/bootstrapper.cc
src/debug.cc
src/handles-inl.h
src/handles.cc
src/handles.h
src/isolate.h
test/cctest/test-heap.cc
tools/gyp/v8.gyp

index d910f1f9a3e2a642ab7795424fce15cc99a751a7..414fe6cb5bea90c48ba5194a90c9da2fbf82ad3b 100644 (file)
@@ -825,19 +825,23 @@ class V8_EXPORT HandleScope {
    */
   static int NumberOfHandles(Isolate* isolate);
 
- private:
-  /**
-   * Creates a new handle with the given value.
-   */
+  V8_INLINE Isolate* GetIsolate() const {
+    return reinterpret_cast<Isolate*>(isolate_);
+  }
+
+ protected:
+  V8_INLINE HandleScope() {}
+
+  void Initialize(Isolate* isolate);
+
   static internal::Object** CreateHandle(internal::Isolate* isolate,
                                          internal::Object* value);
-  // Uses HeapObject to obtain the current Isolate.
+
+ private:
+  // Uses heap_object to obtain the current Isolate.
   static internal::Object** CreateHandle(internal::HeapObject* heap_object,
                                          internal::Object* value);
 
-  V8_INLINE HandleScope() {}
-  void Initialize(Isolate* isolate);
-
   // Make it hard to create heap-allocated or illegal handle scopes by
   // disallowing certain operations.
   HandleScope(const HandleScope&);
@@ -845,27 +849,15 @@ class V8_EXPORT HandleScope {
   void* operator new(size_t size);
   void operator delete(void*, size_t);
 
-  // This Data class is accessible internally as HandleScopeData through a
-  // typedef in the ImplementationUtilities class.
-  class V8_EXPORT Data {
-   public:
-    internal::Object** next;
-    internal::Object** limit;
-    int level;
-    V8_INLINE void Initialize() {
-      next = limit = NULL;
-      level = 0;
-    }
-  };
-
   internal::Isolate* isolate_;
   internal::Object** prev_next_;
   internal::Object** prev_limit_;
 
-  friend class ImplementationUtilities;
-  friend class EscapableHandleScope;
-  template<class F> friend class Handle;
+  // Local::New uses CreateHandle with an Isolate* parameter.
   template<class F> friend class Local;
+
+  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
+  // a HeapObject* in their shortcuts.
   friend class Object;
   friend class Context;
 };
@@ -4923,15 +4915,19 @@ class V8_EXPORT TryCatch {
 
 
 /**
- * Ignore
+ * A container for extension names.
  */
 class V8_EXPORT ExtensionConfiguration {
  public:
+  ExtensionConfiguration() : name_count_(0), names_(NULL) { }
   ExtensionConfiguration(int name_count, const char* names[])
       : name_count_(name_count), names_(names) { }
+
+  const char** begin() const { return &names_[0]; }
+  const char** end()  const { return &names_[name_count_]; }
+
  private:
-  friend class ImplementationUtilities;
-  int name_count_;
+  const int name_count_;
   const char** names_;
 };
 
index 0207eb57a6f55bfe7d16b6a0bf126a0ef2b3a99e..50879a13766eb660d58d530299706801812550f7 100644 (file)
@@ -600,8 +600,7 @@ void HandleScope::Initialize(Isolate* isolate) {
                   internal_isolate->thread_manager()->IsLockedByCurrentThread(),
                   "HandleScope::HandleScope",
                   "Entering the V8 API without proper locking in place");
-  v8::ImplementationUtilities::HandleScopeData* current =
-      internal_isolate->handle_scope_data();
+  i::HandleScopeData* current = internal_isolate->handle_scope_data();
   isolate_ = internal_isolate;
   prev_next_ = current->next;
   prev_limit_ = current->limit;
@@ -640,11 +639,12 @@ EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) {
 
 
 i::Object** EscapableHandleScope::Escape(i::Object** escape_value) {
-  Utils::ApiCheck(*escape_slot_ == isolate_->heap()->the_hole_value(),
+  i::Heap* heap = reinterpret_cast<i::Isolate*>(GetIsolate())->heap();
+  Utils::ApiCheck(*escape_slot_ == heap->the_hole_value(),
                   "EscapeableHandleScope::Escape",
                   "Escape value set twice");
   if (escape_value == NULL) {
-    *escape_slot_ = isolate_->heap()->undefined_value();
+    *escape_slot_ = heap->undefined_value();
     return NULL;
   }
   *escape_slot_ = *escape_value;
@@ -5151,6 +5151,8 @@ Local<Context> v8::Context::New(
   LOG_API(isolate, "Context::New");
   ON_BAILOUT(isolate, "v8::Context::New()", return Local<Context>());
   i::HandleScope scope(isolate);
+  ExtensionConfiguration no_extensions;
+  if (extensions == NULL) extensions = &no_extensions;
   i::Handle<i::Context> env =
       CreateEnvironment(isolate, extensions, global_template, global_object);
   if (env.is_null()) return Local<Context>();
@@ -7267,8 +7269,7 @@ void HandleScopeImplementer::FreeThreadResources() {
 
 
 char* HandleScopeImplementer::ArchiveThread(char* storage) {
-  v8::ImplementationUtilities::HandleScopeData* current =
-      isolate_->handle_scope_data();
+  HandleScopeData* current = isolate_->handle_scope_data();
   handle_scope_data_ = *current;
   OS::MemCopy(storage, this, sizeof(*this));
 
@@ -7329,8 +7330,7 @@ void HandleScopeImplementer::IterateThis(ObjectVisitor* v) {
 
 
 void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
-  v8::ImplementationUtilities::HandleScopeData* current =
-      isolate_->handle_scope_data();
+  HandleScopeData* current = isolate_->handle_scope_data();
   handle_scope_data_ = *current;
   IterateThis(v);
 }
index 2a43651ff3f0d2cb1b4574314debd968a538b248..9d4dcf7385472c8e6ce18b8c39e64091bac725c7 100644 (file)
--- a/src/api.h
+++ b/src/api.h
@@ -31,7 +31,6 @@
 #include "v8.h"
 
 #include "../include/v8-testing.h"
-#include "apiutils.h"
 #include "contexts.h"
 #include "factory.h"
 #include "isolate.h"
@@ -608,7 +607,7 @@ class HandleScopeImplementer {
   int call_depth_;
   Object** last_handle_before_deferred_block_;
   // This is only used for threading support.
-  v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
+  HandleScopeData handle_scope_data_;
 
   void IterateThis(ObjectVisitor* v);
   char* RestoreThreadHelper(char* from);
diff --git a/src/apiutils.h b/src/apiutils.h
deleted file mode 100644 (file)
index 0765585..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2012 the V8 project authors. All rights reserved.
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//     * Redistributions of source code must retain the above copyright
-//       notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-//       copyright notice, this list of conditions and the following
-//       disclaimer in the documentation and/or other materials provided
-//       with the distribution.
-//     * Neither the name of Google Inc. nor the names of its
-//       contributors may be used to endorse or promote products derived
-//       from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef V8_APIUTILS_H_
-#define V8_APIUTILS_H_
-
-namespace v8 {
-class ImplementationUtilities {
- public:
-  static int GetNameCount(ExtensionConfiguration* that) {
-    return that->name_count_;
-  }
-
-  static const char** GetNames(ExtensionConfiguration* that) {
-    return that->names_;
-  }
-
-  // Introduce an alias for the handle scope data to allow non-friends
-  // to access the HandleScope data.
-  typedef v8::HandleScope::Data HandleScopeData;
-};
-
-}  // namespace v8
-
-#endif  // V8_APIUTILS_H_
index 800b5b4c642462e18d389238e6c1141b7f5c68f3..d039ac06ad7606224549f8b268c32e8dc52e91fc 100644 (file)
@@ -2268,13 +2268,8 @@ bool Genesis::InstallExtensions(Handle<Context> native_context,
     InstallExtension(isolate, "v8/trigger-failure", &extension_states);
   }
 
-  if (extensions == NULL) return true;
-  // Install required extensions
-  int count = v8::ImplementationUtilities::GetNameCount(extensions);
-  const char** names = v8::ImplementationUtilities::GetNames(extensions);
-  for (int i = 0; i < count; i++) {
-    if (!InstallExtension(isolate, names[i], &extension_states))
-      return false;
+  for (const char** it = extensions->begin(); it != extensions->end(); ++it) {
+    if (!InstallExtension(isolate, *it, &extension_states)) return false;
   }
 
   return true;
index 5c04efa19d41c2f4f08a12f48aade6802b2b0b49..c025c975b0511edcc66b994ed8bb36276d41726a 100644 (file)
@@ -854,11 +854,12 @@ bool Debug::Load() {
 
   // Create the debugger context.
   HandleScope scope(isolate_);
+  ExtensionConfiguration no_extensions;
   Handle<Context> context =
       isolate_->bootstrapper()->CreateEnvironment(
           Handle<Object>::null(),
           v8::Handle<ObjectTemplate>(),
-          NULL);
+          &no_extensions);
 
   // Fail if no context could be created.
   if (context.is_null()) return false;
index ec69c3fdbe61dc7283a8d075942faa2eaa1394bb..22bbd7cd7c13fc10a4645407317ea65debf05769 100644 (file)
@@ -30,7 +30,6 @@
 #define V8_HANDLES_INL_H_
 
 #include "api.h"
-#include "apiutils.h"
 #include "handles.h"
 #include "heap.h"
 #include "isolate.h"
@@ -110,8 +109,7 @@ bool Handle<T>::IsDereferenceAllowed(DereferenceCheckMode mode) const {
 
 
 HandleScope::HandleScope(Isolate* isolate) {
-  v8::ImplementationUtilities::HandleScopeData* current =
-      isolate->handle_scope_data();
+  HandleScopeData* current = isolate->handle_scope_data();
   isolate_ = isolate;
   prev_next_ = current->next;
   prev_limit_ = current->limit;
@@ -127,8 +125,7 @@ HandleScope::~HandleScope() {
 void HandleScope::CloseScope(Isolate* isolate,
                              Object** prev_next,
                              Object** prev_limit) {
-  v8::ImplementationUtilities::HandleScopeData* current =
-      isolate->handle_scope_data();
+  HandleScopeData* current = isolate->handle_scope_data();
 
   std::swap(current->next, prev_next);
   current->level--;
@@ -146,8 +143,7 @@ void HandleScope::CloseScope(Isolate* isolate,
 
 template <typename T>
 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) {
-  v8::ImplementationUtilities::HandleScopeData* current =
-      isolate_->handle_scope_data();
+  HandleScopeData* current = isolate_->handle_scope_data();
 
   T* value = *handle_value;
   // Throw away all handles in the current scope.
@@ -167,8 +163,7 @@ Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) {
 template <typename T>
 T** HandleScope::CreateHandle(Isolate* isolate, T* value) {
   ASSERT(AllowHandleAllocation::IsAllowed());
-  v8::ImplementationUtilities::HandleScopeData* current =
-      isolate->handle_scope_data();
+  HandleScopeData* current = isolate->handle_scope_data();
 
   internal::Object** cur = current->next;
   if (cur == current->limit) cur = Extend(isolate);
@@ -187,8 +182,7 @@ T** HandleScope::CreateHandle(Isolate* isolate, T* value) {
 inline SealHandleScope::SealHandleScope(Isolate* isolate) : isolate_(isolate) {
   // Make sure the current thread is allowed to create handles to begin with.
   CHECK(AllowHandleAllocation::IsAllowed());
-  v8::ImplementationUtilities::HandleScopeData* current =
-      isolate_->handle_scope_data();
+  HandleScopeData* current = isolate_->handle_scope_data();
   // Shrink the current handle scope to make it impossible to do
   // handle allocations without an explicit handle scope.
   limit_ = current->limit;
@@ -201,8 +195,7 @@ inline SealHandleScope::SealHandleScope(Isolate* isolate) : isolate_(isolate) {
 inline SealHandleScope::~SealHandleScope() {
   // Restore state in current handle scope to re-enable handle
   // allocations.
-  v8::ImplementationUtilities::HandleScopeData* current =
-      isolate_->handle_scope_data();
+  HandleScopeData* current = isolate_->handle_scope_data();
   ASSERT_EQ(0, current->level);
   current->level = level_;
   ASSERT_EQ(current->next, current->limit);
index b3282faffecbe3da69eff779c0f45b6b6e112ab6..830eb096027452956aef5c9d0cc49c151affb756 100644 (file)
@@ -55,8 +55,7 @@ int HandleScope::NumberOfHandles(Isolate* isolate) {
 
 
 Object** HandleScope::Extend(Isolate* isolate) {
-  v8::ImplementationUtilities::HandleScopeData* current =
-      isolate->handle_scope_data();
+  HandleScopeData* current = isolate->handle_scope_data();
 
   Object** result = current->next;
 
@@ -95,8 +94,7 @@ Object** HandleScope::Extend(Isolate* isolate) {
 
 
 void HandleScope::DeleteExtensions(Isolate* isolate) {
-  v8::ImplementationUtilities::HandleScopeData* current =
-      isolate->handle_scope_data();
+  HandleScopeData* current = isolate->handle_scope_data();
   isolate->handle_scope_implementer()->DeleteExtensions(current->limit);
 }
 
@@ -751,8 +749,7 @@ Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
 DeferredHandleScope::DeferredHandleScope(Isolate* isolate)
     : impl_(isolate->handle_scope_implementer()) {
   impl_->BeginDeferredScope();
-  v8::ImplementationUtilities::HandleScopeData* data =
-      impl_->isolate()->handle_scope_data();
+  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]);
@@ -778,8 +775,7 @@ DeferredHandleScope::~DeferredHandleScope() {
 
 DeferredHandles* DeferredHandleScope::Detach() {
   DeferredHandles* deferred = impl_->Detach(prev_limit_);
-  v8::ImplementationUtilities::HandleScopeData* data =
-      impl_->isolate()->handle_scope_data();
+  HandleScopeData* data = impl_->isolate()->handle_scope_data();
   data->next = prev_next_;
   data->limit = prev_limit_;
 #ifdef DEBUG
index d42d1bdbc5c26725eea8fdb4b95c64e3d0107478..85386580478cc7c183374f94e60515740955dd5e 100644 (file)
@@ -29,7 +29,6 @@
 #define V8_HANDLES_H_
 
 #include "allocation.h"
-#include "apiutils.h"
 #include "objects.h"
 
 namespace v8 {
@@ -317,6 +316,17 @@ class SealHandleScope BASE_EMBEDDED {
 #endif
 };
 
+struct HandleScopeData {
+  internal::Object** next;
+  internal::Object** limit;
+  int level;
+
+  void Initialize() {
+    next = limit = NULL;
+    level = 0;
+  }
+};
+
 } }  // namespace v8::internal
 
 #endif  // V8_HANDLES_H_
index 1323e2c4e8d3ee03c96ac52de14645ea0e6b5de9..d6dff05f9131e2122878fae542ba2c42bc96bdae 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "../include/v8-debug.h"
 #include "allocation.h"
-#include "apiutils.h"
 #include "assert-scope.h"
 #include "atomicops.h"
 #include "builtins.h"
@@ -887,9 +886,8 @@ class Isolate {
     return descriptor_lookup_cache_;
   }
 
-  v8::ImplementationUtilities::HandleScopeData* handle_scope_data() {
-    return &handle_scope_data_;
-  }
+  HandleScopeData* handle_scope_data() { return &handle_scope_data_; }
+
   HandleScopeImplementer* handle_scope_implementer() {
     ASSERT(handle_scope_implementer_);
     return handle_scope_implementer_;
@@ -1284,7 +1282,7 @@ class Isolate {
   KeyedLookupCache* keyed_lookup_cache_;
   ContextSlotCache* context_slot_cache_;
   DescriptorLookupCache* descriptor_lookup_cache_;
-  v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
+  HandleScopeData handle_scope_data_;
   HandleScopeImplementer* handle_scope_implementer_;
   UnicodeCache* unicode_cache_;
   Zone runtime_zone_;
index 198c6df8a37734182c765c822e3d0c28c18c7862..9489ca7c72c5439b602d5a5488269fbee5db4b9f 100644 (file)
@@ -3532,8 +3532,7 @@ TEST(DeferredHandles) {
   Isolate* isolate = CcTest::i_isolate();
   Heap* heap = isolate->heap();
   v8::HandleScope scope(reinterpret_cast<v8::Isolate*>(isolate));
-  v8::ImplementationUtilities::HandleScopeData* data =
-      isolate->handle_scope_data();
+  HandleScopeData* data = isolate->handle_scope_data();
   Handle<Object> init(heap->empty_string(), isolate);
   while (data->next < data->limit) {
     Handle<Object> obj(heap->empty_string(), isolate);
index 06060a546f96ab133fd6833dc3be51c8de00e832..124bd1b4c0a2f54c802d4a2862d9634ac5ae0392 100644 (file)
         '../../src/allocation-tracker.h',
         '../../src/api.cc',
         '../../src/api.h',
-        '../../src/apiutils.h',
         '../../src/arguments.cc',
         '../../src/arguments.h',
         '../../src/assembler.cc',