Removed apiutils.h and related cleanup.

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
This commit is contained in:
svenpanne@chromium.org 2014-01-16 08:17:40 +00:00
parent fbf0fe177e
commit b25bb230cd
12 changed files with 61 additions and 124 deletions

View 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_;
};

View 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);
}

View File

@ -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);

View File

@ -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_

View 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;

View 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;

View 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);

View 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

View 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_

View 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_;

View 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);

View File

@ -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',