From fec64cd698f961e1d4868929e83a24b73109a4f1 Mon Sep 17 00:00:00 2001 From: "dcarney@chromium.org" Date: Wed, 29 May 2013 08:39:37 +0000 Subject: [PATCH] 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 --- include/v8.h | 43 ++++++++++++++++++++--------- samples/lineprocessor.cc | 9 ++----- samples/process.cc | 25 +++++++++-------- samples/shell.cc | 5 ---- src/d8.cc | 58 +++++++++++++++++++++------------------- src/mksnapshot.cc | 9 ++----- src/runtime.cc | 4 +-- 7 files changed, 79 insertions(+), 74 deletions(-) diff --git a/include/v8.h b/include/v8.h index 30ba24367..7481a8195 100644 --- a/include/v8.h +++ b/include/v8.h @@ -370,11 +370,11 @@ template class Handle { #endif private: - template - friend class Persistent; - template - friend class Local; + template friend class Persistent; + template friend class Local; friend class Arguments; + template friend class FunctionCallbackInfo; + template friend class PropertyCallbackInfo; friend class String; friend class Object; friend class AccessorInfo; @@ -385,6 +385,7 @@ template class Handle { friend class Context; friend class InternalHandleHelper; friend class LocalContext; + friend class HandleScope; #ifndef V8_USE_UNSAFE_HANDLES V8_INLINE(static Handle New(Isolate* isolate, T* that)); @@ -458,17 +459,18 @@ template class Local : public Handle { #endif private: - template - friend class Persistent; - template - friend class Handle; + template friend class Persistent; + template friend class Handle; friend class Arguments; + template friend class FunctionCallbackInfo; + template 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 New(Isolate* isolate, T* that)); }; @@ -751,6 +753,10 @@ template class Persistent // NOLINT */ V8_INLINE(void Reset(Isolate* isolate, const Handle& other)); +#ifndef V8_USE_UNSAFE_HANDLES + V8_INLINE(void Reset(Isolate* isolate, const Persistent& 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 Persistent // NOLINT #endif private: - template - friend class Handle; - template - friend class Local; + template friend class Handle; + template friend class Local; friend class ImplementationUtilities; friend class ObjectTemplate; friend class Context; @@ -5629,6 +5633,21 @@ void Persistent::Reset(Isolate* isolate, const Handle& other) { } +#ifndef V8_USE_UNSAFE_HANDLES +template +void Persistent::Reset(Isolate* isolate, const Persistent& other) { + Dispose(isolate); + if (other.IsEmpty()) { + this->val_ = NULL; + return; + } + internal::Object** p = reinterpret_cast(other.val_); + this->val_ = reinterpret_cast( + V8::GlobalizeReference(reinterpret_cast(isolate), p)); +} +#endif + + template T* Persistent::ClearAndLeak() { T* old; diff --git a/samples/lineprocessor.cc b/samples/lineprocessor.cc index 45e5dc30d..635691ec1 100644 --- a/samples/lineprocessor.cc +++ b/samples/lineprocessor.cc @@ -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 #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::New(isolate, context); + debug_message_context.Reset(isolate, context); v8::Locker locker(isolate); @@ -439,7 +434,7 @@ v8::Handle ReadLine() { } if (res == NULL) { v8::Handle t = v8::Undefined(); - return v8::Handle(v8::String::Cast(*t)); + return v8::Handle::Cast(t); } // Remove newline char for (char* pos = buffer; *pos != '\0'; pos++) { diff --git a/samples/process.cc b/samples/process.cc index 8a41faec9..1c1e7bec9 100644 --- a/samples/process.cc +++ b/samples/process.cc @@ -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 #include @@ -186,7 +181,7 @@ bool JsHttpRequestProcessor::Initialize(map* opts, // The script compiled and ran correctly. Now we fetch out the // Process function from the global object. Handle process_name = String::New("Process"); - Handle process_val = context_->Global()->Get(process_name); + Handle 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* opts, // Store the function in a Persistent handle, since we also want // that to remain after this call returns - process_ = Persistent::New(GetIsolate(), process_fun); + process_.Reset(GetIsolate(), process_fun); // All done; all went well return true; @@ -240,11 +235,14 @@ bool JsHttpRequestProcessor::InstallMaps(map* opts, // Wrap the map object in a JavaScript wrapper Handle opts_obj = WrapMap(opts); + v8::Local context = + v8::Local::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 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 argv[argc] = { request_obj }; - Handle result = process_->Call(context_->Global(), argc, argv); + v8::Local process = + v8::Local::New(GetIsolate(), process_); + Handle result = process->Call(context->Global(), argc, argv); if (result.IsEmpty()) { String::Utf8Value error(try_catch.Exception()); Log(*error); @@ -310,7 +310,7 @@ Handle JsHttpRequestProcessor::WrapMap(map* obj) { // It only has to be created once, which we do on demand. if (map_template_.IsEmpty()) { Handle raw_template = MakeMapTemplate(GetIsolate()); - map_template_ = Persistent::New(GetIsolate(), raw_template); + map_template_.Reset(GetIsolate(), raw_template); } Handle templ = Local::New(GetIsolate(), map_template_); @@ -417,8 +417,7 @@ Handle JsHttpRequestProcessor::WrapRequest(HttpRequest* request) { // It only has to be created once, which we do on demand. if (request_template_.IsEmpty()) { Handle raw_template = MakeRequestTemplate(GetIsolate()); - request_template_ = - Persistent::New(GetIsolate(), raw_template); + request_template_.Reset(GetIsolate(), raw_template); } Handle templ = Local::New(GetIsolate(), request_template_); diff --git a/samples/shell.cc b/samples/shell.cc index da18cc71d..430dd966e 100644 --- a/samples/shell.cc +++ b/samples/shell.cc @@ -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 #include #include diff --git a/src/d8.cc b/src/d8.cc index 149a65fe4..79244d77c 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -40,11 +40,6 @@ #include #include -// 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 #endif // V8_SHARED @@ -246,7 +241,7 @@ bool Shell::ExecuteString(Isolate* isolate, v8::Local context = v8::Local::New(isolate, utility_context_); v8::Context::Scope context_scope(context); - Handle global = utility_context_->Global(); + Handle global = context->Global(); Handle fun = global->Get(String::New("Stringify")); Handle argv[1] = { result }; Handle s = Handle::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[1]; - data_->realms_[0] = - Persistent::New(data_->isolate_, Context::GetEntered()); + data_->realms_[0].Reset(data_->isolate_, Context::GetEntered()); data_->realm_shared_.Clear(); } @@ -326,7 +320,8 @@ Handle 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::New(args.GetIsolate(), data->realms_[index])->Global(); } @@ -337,10 +332,12 @@ Handle Shell::RealmCreate(const Arguments& args) { Persistent* old_realms = data->realms_; int index = data->realm_count_; data->realms_ = new Persistent[++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 global_template = CreateGlobalTemplate(isolate); - data->realms_[index] = Persistent::New( + data->realms_[index].Reset( isolate, Context::New(isolate, NULL, global_template)); return Number::New(index); } @@ -417,7 +414,7 @@ void Shell::RealmSharedSet(Local property, Isolate* isolate = info.GetIsolate(); PerIsolateData* data = PerIsolateData::Get(isolate); if (!data->realm_shared_.IsEmpty()) data->realm_shared_.Dispose(isolate); - data->realm_shared_ = Persistent::New(isolate, value); + data->realm_shared_.Reset(isolate, value); } @@ -546,8 +543,12 @@ Handle 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 utility_context; bool enter_context = !Context::InContext(); - if (enter_context) utility_context_->Enter(); + if (enter_context) { + utility_context = Local::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 Shell::GetCompletions(Isolate* isolate, Handle text, Handle full) { HandleScope handle_scope(isolate); - v8::Local context = + v8::Local utility_context = v8::Local::New(isolate, utility_context_); - v8::Context::Scope context_scope(context); - Handle global = utility_context_->Global(); + v8::Context::Scope context_scope(utility_context); + Handle global = utility_context->Global(); Handle fun = global->Get(String::New("GetCompletions")); static const int kArgc = 3; - Handle argv[kArgc] = { evaluation_context_->Global(), text, full }; + v8::Local evaluation_context = + v8::Local::New(isolate, evaluation_context_); + Handle argv[kArgc] = { evaluation_context->Global(), text, full }; Handle val = Handle::Cast(fun)->Call(global, kArgc, argv); return handle_scope.Close(Handle::Cast(val)); } @@ -613,7 +616,7 @@ Handle Shell::DebugMessageDetails(Isolate* isolate, v8::Local context = v8::Local::New(isolate, utility_context_); v8::Context::Scope context_scope(context); - Handle global = utility_context_->Global(); + Handle global = context->Global(); Handle fun = global->Get(String::New("DebugMessageDetails")); static const int kArgc = 1; Handle argv[kArgc] = { message }; @@ -628,7 +631,7 @@ Handle Shell::DebugCommandToJSONRequest(Isolate* isolate, v8::Local context = v8::Local::New(isolate, utility_context_); v8::Context::Scope context_scope(context); - Handle global = utility_context_->Global(); + Handle global = context->Global(); Handle fun = global->Get(String::New("DebugCommandToJSONRequest")); static const int kArgc = 1; Handle 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 context = + v8::Local utility_context = v8::Local::New(isolate, utility_context_); - v8::Context::Scope context_scope(context); + v8::Local evaluation_context = + v8::Local::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 js_debug = i::Handle(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 Shell::ReadBuffer(const Arguments& args) { return Throw("Error reading file"); } Handle buffer = ArrayBuffer::New(data, length); - v8::Persistent weak_handle = - v8::Persistent::New(isolate, buffer); + v8::Persistent weak_handle(isolate, buffer); weak_handle.MakeWeak(isolate, data, ReadBufferWeakCallback); weak_handle.MarkIndependent(); isolate->AdjustAmountOfExternalAllocatedMemory(length); diff --git a/src/mksnapshot.cc b/src/mksnapshot.cc index 7592a8953..978ea217b 100644 --- a/src/mksnapshot.cc +++ b/src/mksnapshot.cc @@ -32,10 +32,6 @@ #endif #include -// 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::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. diff --git a/src/runtime.cc b/src/runtime.cc index 3e77584f8..e08ac57be 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -28,8 +28,6 @@ #include #include -#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(isolate); - v8::Persistent weak_handle = v8::Persistent::New( + v8::Persistent weak_handle( external_isolate, v8::Utils::ToLocal(Handle::cast(array_buffer))); weak_handle.MakeWeak(external_isolate, data, ArrayBufferWeakCallback); weak_handle.MarkIndependent(external_isolate); -- 2.34.1