From: svenpanne@chromium.org Date: Thu, 16 Jan 2014 08:17:40 +0000 (+0000) Subject: Removed apiutils.h and related cleanup. X-Git-Tag: upstream/4.7.83~11137 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b25bb230cd12cfbc92b1f19ac25991c143a53672;p=platform%2Fupstream%2Fv8.git Removed apiutils.h and related cleanup. ExtensionConfiguration is just a simple container for extension names (in a perfect world we would use vector 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 --- diff --git a/include/v8.h b/include/v8.h index d910f1f9a..414fe6cb5 100644 --- a/include/v8.h +++ b/include/v8.h @@ -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_); + } + + 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 friend class Handle; + // Local::New uses CreateHandle with an Isolate* parameter. template 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_; }; diff --git a/src/api.cc b/src/api.cc index 0207eb57a..50879a137 100644 --- a/src/api.cc +++ b/src/api.cc @@ -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(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 v8::Context::New( LOG_API(isolate, "Context::New"); ON_BAILOUT(isolate, "v8::Context::New()", return Local()); i::HandleScope scope(isolate); + ExtensionConfiguration no_extensions; + if (extensions == NULL) extensions = &no_extensions; i::Handle env = CreateEnvironment(isolate, extensions, global_template, global_object); if (env.is_null()) return Local(); @@ -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); } diff --git a/src/api.h b/src/api.h index 2a43651ff..9d4dcf738 100644 --- 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 index 076558564..000000000 --- a/src/apiutils.h +++ /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_ diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 800b5b4c6..d039ac06a 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -2268,13 +2268,8 @@ bool Genesis::InstallExtensions(Handle 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; diff --git a/src/debug.cc b/src/debug.cc index 5c04efa19..c025c975b 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -854,11 +854,12 @@ bool Debug::Load() { // Create the debugger context. HandleScope scope(isolate_); + ExtensionConfiguration no_extensions; Handle context = isolate_->bootstrapper()->CreateEnvironment( Handle::null(), v8::Handle(), - NULL); + &no_extensions); // Fail if no context could be created. if (context.is_null()) return false; diff --git a/src/handles-inl.h b/src/handles-inl.h index ec69c3fdb..22bbd7cd7 100644 --- a/src/handles-inl.h +++ b/src/handles-inl.h @@ -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::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 Handle HandleScope::CloseAndEscape(Handle 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 HandleScope::CloseAndEscape(Handle handle_value) { template 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); diff --git a/src/handles.cc b/src/handles.cc index b3282faff..830eb0960 100644 --- a/src/handles.cc +++ b/src/handles.cc @@ -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 GetEnumPropertyKeys(Handle 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 diff --git a/src/handles.h b/src/handles.h index d42d1bdbc..853865804 100644 --- a/src/handles.h +++ b/src/handles.h @@ -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_ diff --git a/src/isolate.h b/src/isolate.h index 1323e2c4e..d6dff05f9 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -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_; diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 198c6df8a..9489ca7c7 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -3532,8 +3532,7 @@ TEST(DeferredHandles) { Isolate* isolate = CcTest::i_isolate(); Heap* heap = isolate->heap(); v8::HandleScope scope(reinterpret_cast(isolate)); - v8::ImplementationUtilities::HandleScopeData* data = - isolate->handle_scope_data(); + HandleScopeData* data = isolate->handle_scope_data(); Handle init(heap->empty_string(), isolate); while (data->next < data->limit) { Handle obj(heap->empty_string(), isolate); diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index 06060a546..124bd1b4c 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -253,7 +253,6 @@ '../../src/allocation-tracker.h', '../../src/api.cc', '../../src/api.h', - '../../src/apiutils.h', '../../src/arguments.cc', '../../src/arguments.h', '../../src/assembler.cc',