remove most remaining V8_ALLOW_ACCESS_TO* defines

R=svenpanne@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14870 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
dcarney@chromium.org 2013-05-29 08:39:37 +00:00
parent f8039eff6c
commit fec64cd698
7 changed files with 79 additions and 74 deletions

View File

@ -370,11 +370,11 @@ template <class T> class Handle {
#endif
private:
template<class F>
friend class Persistent;
template<class F>
friend class Local;
template<class F> friend class Persistent;
template<class F> friend class Local;
friend class Arguments;
template<class F> friend class FunctionCallbackInfo;
template<class F> friend class PropertyCallbackInfo;
friend class String;
friend class Object;
friend class AccessorInfo;
@ -385,6 +385,7 @@ template <class T> class Handle {
friend class Context;
friend class InternalHandleHelper;
friend class LocalContext;
friend class HandleScope;
#ifndef V8_USE_UNSAFE_HANDLES
V8_INLINE(static Handle<T> New(Isolate* isolate, T* that));
@ -458,17 +459,18 @@ template <class T> class Local : public Handle<T> {
#endif
private:
template<class F>
friend class Persistent;
template<class F>
friend class Handle;
template<class F> friend class Persistent;
template<class F> friend class Handle;
friend class Arguments;
template<class F> friend class FunctionCallbackInfo;
template<class F> friend class PropertyCallbackInfo;
friend class String;
friend class Object;
friend class AccessorInfo;
friend class Context;
friend class InternalHandleHelper;
friend class LocalContext;
friend class HandleScope;
V8_INLINE(static Local<T> New(Isolate* isolate, T* that));
};
@ -751,6 +753,10 @@ template <class T> class Persistent // NOLINT
*/
V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other));
#ifndef V8_USE_UNSAFE_HANDLES
V8_INLINE(void Reset(Isolate* isolate, const Persistent<T>& other));
#endif
/**
* Returns the underlying raw pointer and clears the handle. The caller is
* responsible of eventually destroying the underlying object (by creating a
@ -800,10 +806,8 @@ template <class T> class Persistent // NOLINT
#endif
private:
template<class F>
friend class Handle;
template<class F>
friend class Local;
template<class F> friend class Handle;
template<class F> friend class Local;
friend class ImplementationUtilities;
friend class ObjectTemplate;
friend class Context;
@ -5629,6 +5633,21 @@ void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) {
}
#ifndef V8_USE_UNSAFE_HANDLES
template <class T>
void Persistent<T>::Reset(Isolate* isolate, const Persistent<T>& other) {
Dispose(isolate);
if (other.IsEmpty()) {
this->val_ = NULL;
return;
}
internal::Object** p = reinterpret_cast<internal::Object**>(other.val_);
this->val_ = reinterpret_cast<T*>(
V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p));
}
#endif
template <class T>
T* Persistent<T>::ClearAndLeak() {
T* old;

View File

@ -25,10 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// TODO(dcarney): remove
#define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
#define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
#include <v8.h>
#ifdef ENABLE_DEBUGGER_SUPPORT
@ -222,8 +218,7 @@ int RunMain(int argc, char* argv[]) {
v8::Context::Scope context_scope(context);
#ifdef ENABLE_DEBUGGER_SUPPORT
debug_message_context =
v8::Persistent<v8::Context>::New(isolate, context);
debug_message_context.Reset(isolate, context);
v8::Locker locker(isolate);
@ -439,7 +434,7 @@ v8::Handle<v8::String> ReadLine() {
}
if (res == NULL) {
v8::Handle<v8::Primitive> t = v8::Undefined();
return v8::Handle<v8::String>(v8::String::Cast(*t));
return v8::Handle<v8::String>::Cast(t);
}
// Remove newline char
for (char* pos = buffer; *pos != '\0'; pos++) {

View File

@ -25,11 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// TODO(dcarney): remove this
#define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
#define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
#define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW
#include <v8.h>
#include <string>
@ -186,7 +181,7 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
// The script compiled and ran correctly. Now we fetch out the
// Process function from the global object.
Handle<String> process_name = String::New("Process");
Handle<Value> process_val = context_->Global()->Get(process_name);
Handle<Value> process_val = context->Global()->Get(process_name);
// If there is no Process function, or if it is not a function,
// bail out
@ -197,7 +192,7 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
// Store the function in a Persistent handle, since we also want
// that to remain after this call returns
process_ = Persistent<Function>::New(GetIsolate(), process_fun);
process_.Reset(GetIsolate(), process_fun);
// All done; all went well
return true;
@ -240,11 +235,14 @@ bool JsHttpRequestProcessor::InstallMaps(map<string, string>* opts,
// Wrap the map object in a JavaScript wrapper
Handle<Object> opts_obj = WrapMap(opts);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(GetIsolate(), context_);
// Set the options object as a property on the global object.
context_->Global()->Set(String::New("options"), opts_obj);
context->Global()->Set(String::New("options"), opts_obj);
Handle<Object> output_obj = WrapMap(output);
context_->Global()->Set(String::New("output"), output_obj);
context->Global()->Set(String::New("output"), output_obj);
return true;
}
@ -271,7 +269,9 @@ bool JsHttpRequestProcessor::Process(HttpRequest* request) {
// and one argument, the request.
const int argc = 1;
Handle<Value> argv[argc] = { request_obj };
Handle<Value> result = process_->Call(context_->Global(), argc, argv);
v8::Local<v8::Function> process =
v8::Local<v8::Function>::New(GetIsolate(), process_);
Handle<Value> result = process->Call(context->Global(), argc, argv);
if (result.IsEmpty()) {
String::Utf8Value error(try_catch.Exception());
Log(*error);
@ -310,7 +310,7 @@ Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) {
// It only has to be created once, which we do on demand.
if (map_template_.IsEmpty()) {
Handle<ObjectTemplate> raw_template = MakeMapTemplate(GetIsolate());
map_template_ = Persistent<ObjectTemplate>::New(GetIsolate(), raw_template);
map_template_.Reset(GetIsolate(), raw_template);
}
Handle<ObjectTemplate> templ =
Local<ObjectTemplate>::New(GetIsolate(), map_template_);
@ -417,8 +417,7 @@ Handle<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) {
// It only has to be created once, which we do on demand.
if (request_template_.IsEmpty()) {
Handle<ObjectTemplate> raw_template = MakeRequestTemplate(GetIsolate());
request_template_ =
Persistent<ObjectTemplate>::New(GetIsolate(), raw_template);
request_template_.Reset(GetIsolate(), raw_template);
}
Handle<ObjectTemplate> templ =
Local<ObjectTemplate>::New(GetIsolate(), request_template_);

View File

@ -25,11 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// TODO(dcarney): remove this
#define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
#define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
#define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW
#include <v8.h>
#include <assert.h>
#include <fcntl.h>

View File

@ -40,11 +40,6 @@
#include <string.h>
#include <sys/stat.h>
// TODO(dcarney): remove
#define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW
#define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
#define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
#ifdef V8_SHARED
#include <assert.h>
#endif // V8_SHARED
@ -246,7 +241,7 @@ bool Shell::ExecuteString(Isolate* isolate,
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(context);
Handle<Object> global = utility_context_->Global();
Handle<Object> global = context->Global();
Handle<Value> fun = global->Get(String::New("Stringify"));
Handle<Value> argv[1] = { result };
Handle<Value> s = Handle<Function>::Cast(fun)->Call(global, 1, argv);
@ -268,8 +263,7 @@ PerIsolateData::RealmScope::RealmScope(PerIsolateData* data) : data_(data) {
data_->realm_current_ = 0;
data_->realm_switch_ = 0;
data_->realms_ = new Persistent<Context>[1];
data_->realms_[0] =
Persistent<Context>::New(data_->isolate_, Context::GetEntered());
data_->realms_[0].Reset(data_->isolate_, Context::GetEntered());
data_->realm_shared_.Clear();
}
@ -326,7 +320,8 @@ Handle<Value> Shell::RealmGlobal(const Arguments& args) {
if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) {
return Throw("Invalid realm index");
}
return data->realms_[index]->Global();
return
Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global();
}
@ -337,10 +332,12 @@ Handle<Value> Shell::RealmCreate(const Arguments& args) {
Persistent<Context>* old_realms = data->realms_;
int index = data->realm_count_;
data->realms_ = new Persistent<Context>[++data->realm_count_];
for (int i = 0; i < index; ++i) data->realms_[i] = old_realms[i];
for (int i = 0; i < index; ++i) {
data->realms_[i].Reset(isolate, old_realms[i]);
}
delete[] old_realms;
Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
data->realms_[index] = Persistent<Context>::New(
data->realms_[index].Reset(
isolate, Context::New(isolate, NULL, global_template));
return Number::New(index);
}
@ -417,7 +414,7 @@ void Shell::RealmSharedSet(Local<String> property,
Isolate* isolate = info.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
if (!data->realm_shared_.IsEmpty()) data->realm_shared_.Dispose(isolate);
data->realm_shared_ = Persistent<Value>::New(isolate, value);
data->realm_shared_.Reset(isolate, value);
}
@ -546,8 +543,12 @@ Handle<Value> Shell::Version(const Arguments& args) {
void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
HandleScope handle_scope(isolate);
#if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
Handle<Context> utility_context;
bool enter_context = !Context::InContext();
if (enter_context) utility_context_->Enter();
if (enter_context) {
utility_context = Local<Context>::New(isolate, utility_context_);
utility_context->Enter();
}
#endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
v8::String::Utf8Value exception(try_catch->Exception());
const char* exception_string = ToCString(exception);
@ -584,7 +585,7 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
}
printf("\n");
#if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
if (enter_context) utility_context_->Exit();
if (enter_context) utility_context->Exit();
#endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
}
@ -594,13 +595,15 @@ Handle<Array> Shell::GetCompletions(Isolate* isolate,
Handle<String> text,
Handle<String> full) {
HandleScope handle_scope(isolate);
v8::Local<v8::Context> context =
v8::Local<v8::Context> utility_context =
v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(context);
Handle<Object> global = utility_context_->Global();
v8::Context::Scope context_scope(utility_context);
Handle<Object> global = utility_context->Global();
Handle<Value> fun = global->Get(String::New("GetCompletions"));
static const int kArgc = 3;
Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full };
v8::Local<v8::Context> evaluation_context =
v8::Local<v8::Context>::New(isolate, evaluation_context_);
Handle<Value> argv[kArgc] = { evaluation_context->Global(), text, full };
Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
return handle_scope.Close(Handle<Array>::Cast(val));
}
@ -613,7 +616,7 @@ Handle<Object> Shell::DebugMessageDetails(Isolate* isolate,
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(context);
Handle<Object> global = utility_context_->Global();
Handle<Object> global = context->Global();
Handle<Value> fun = global->Get(String::New("DebugMessageDetails"));
static const int kArgc = 1;
Handle<Value> argv[kArgc] = { message };
@ -628,7 +631,7 @@ Handle<Value> Shell::DebugCommandToJSONRequest(Isolate* isolate,
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(context);
Handle<Object> global = utility_context_->Global();
Handle<Object> global = context->Global();
Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest"));
static const int kArgc = 1;
Handle<Value> argv[kArgc] = { command };
@ -753,11 +756,13 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
HandleScope scope(isolate);
// If we use the utility context, we have to set the security tokens so that
// utility, evaluation and debug context can all access each other.
utility_context_->SetSecurityToken(Undefined(isolate));
evaluation_context_->SetSecurityToken(Undefined(isolate));
v8::Local<v8::Context> context =
v8::Local<v8::Context> utility_context =
v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(context);
v8::Local<v8::Context> evaluation_context =
v8::Local<v8::Context>::New(isolate, evaluation_context_);
utility_context->SetSecurityToken(Undefined(isolate));
evaluation_context->SetSecurityToken(Undefined(isolate));
v8::Context::Scope context_scope(utility_context);
#ifdef ENABLE_DEBUGGER_SUPPORT
if (i::FLAG_debugger) printf("JavaScript debugger enabled\n");
@ -766,7 +771,7 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
debug->Load();
i::Handle<i::JSObject> js_debug
= i::Handle<i::JSObject>(debug->debug_context()->global_object());
utility_context_->Global()->Set(String::New("$debug"),
utility_context->Global()->Set(String::New("$debug"),
Utils::ToLocal(js_debug));
debug->debug_context()->set_security_token(HEAP->undefined_value());
#endif // ENABLE_DEBUGGER_SUPPORT
@ -1086,8 +1091,7 @@ Handle<Value> Shell::ReadBuffer(const Arguments& args) {
return Throw("Error reading file");
}
Handle<v8::ArrayBuffer> buffer = ArrayBuffer::New(data, length);
v8::Persistent<v8::Value> weak_handle =
v8::Persistent<v8::Value>::New(isolate, buffer);
v8::Persistent<v8::Value> weak_handle(isolate, buffer);
weak_handle.MakeWeak(isolate, data, ReadBufferWeakCallback);
weak_handle.MarkIndependent();
isolate->AdjustAmountOfExternalAllocatedMemory(length);

View File

@ -32,10 +32,6 @@
#endif
#include <signal.h>
// TODO(dcarney): remove
#define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW
#define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
#include "v8.h"
#include "bootstrapper.h"
@ -341,10 +337,10 @@ int main(int argc, char** argv) {
exit(1);
}
if (i::FLAG_extra_code != NULL) {
context->Enter();
// Capture 100 frames if anything happens.
V8::SetCaptureStackTraceForUncaughtExceptions(true, 100);
HandleScope scope(isolate);
v8::Context::Scope(v8::Local<v8::Context>::New(isolate, context));
const char* name = i::FLAG_extra_code;
FILE* file = i::OS::FOpen(name, "rb");
if (file == NULL) {
@ -381,7 +377,6 @@ int main(int argc, char** argv) {
DumpException(try_catch.Message());
exit(1);
}
context->Exit();
}
// Make sure all builtin scripts are cached.
{ HandleScope scope(isolate);
@ -393,7 +388,7 @@ int main(int argc, char** argv) {
// context even after we have disposed of the context.
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags, "mksnapshot");
i::Object* raw_context = *(v8::Utils::OpenHandle(*context));
context.Dispose(context->GetIsolate());
context.Dispose(isolate);
CppByteSink sink(argv[1]);
// This results in a somewhat smaller snapshot, probably because it gets rid
// of some things that are cached between garbage collections.

View File

@ -28,8 +28,6 @@
#include <stdlib.h>
#include <limits>
#define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
#include "v8.h"
#include "accessors.h"
@ -708,7 +706,7 @@ bool Runtime::SetupArrayBufferAllocatingData(
SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length);
v8::Isolate* external_isolate = reinterpret_cast<v8::Isolate*>(isolate);
v8::Persistent<v8::Value> weak_handle = v8::Persistent<v8::Value>::New(
v8::Persistent<v8::Value> weak_handle(
external_isolate, v8::Utils::ToLocal(Handle<Object>::cast(array_buffer)));
weak_handle.MakeWeak(external_isolate, data, ArrayBufferWeakCallback);
weak_handle.MarkIndependent(external_isolate);