Revert "deprecate Context::New which returns Persistent"
authormstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 7 May 2013 16:28:51 +0000 (16:28 +0000)
committermstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 7 May 2013 16:28:51 +0000 (16:28 +0000)
This reverts r14573 because of test failures in no-snapshot mode in the
cctest/test-debug/ScriptCollectedEventContext test case.

TBR=dcarney@chromium.org,svenpanne@chromium.org
TEST=cctest/test-debug/ScriptCollectedEventContext

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

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

18 files changed:
include/v8.h
samples/process.cc
src/d8.cc
src/d8.h
src/mksnapshot.cc
test/cctest/cctest.h
test/cctest/test-api.cc
test/cctest/test-debug.cc
test/cctest/test-decls.cc
test/cctest/test-hashing.cc
test/cctest/test-heap.cc
test/cctest/test-lockers.cc
test/cctest/test-log.cc
test/cctest/test-parsing.cc
test/cctest/test-profile-generator.cc
test/cctest/test-random.cc
test/cctest/test-regexp.cc
test/cctest/test-serialize.cc

index 24c5f261b8d8b6e5e8fbd349994565f13162dc93..3a86e86e020cbc9448c50f2ccd21476035a66c2e 100644 (file)
@@ -4609,11 +4609,11 @@ class V8EXPORT Context {
       Handle<Value> global_object = Handle<Value>());
 
   /** Deprecated. Use Isolate version instead. */
-  V8_DEPRECATED(
-      static Persistent<Context> New(
-          ExtensionConfiguration* extensions = NULL,
-          Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
-          Handle<Value> global_object = Handle<Value>()));
+  // TODO(mstarzinger): Put this behind the V8_DEPRECATED guard.
+  static Persistent<Context> New(
+      ExtensionConfiguration* extensions = NULL,
+      Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
+      Handle<Value> global_object = Handle<Value>());
 
   /** Returns the last entered context. */
   static Local<Context> GetEntered();
index fd3a82163904b376dc60a24a08298ff1c7a32a22..75d6582e82b8c69aecb8a707ee40f6b75ccf18bb 100644 (file)
@@ -168,7 +168,7 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
   // is what we need for the reference to remain after we return from
   // this method. That persistent handle has to be disposed in the
   // destructor.
-  context_.Reset(GetIsolate(), Context::New(GetIsolate(), NULL, global));
+  context_ = Context::New(NULL, global);
 
   // Enter the new context so all the following operations take place
   // within it.
index f0d30a98d3411487100c38c8135ee2069ff4a800..22f1671d10e210f94aa84d4349ef89f4e1df41c1 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1539,8 +1539,7 @@ void Shell::InitializeDebugger(Isolate* isolate) {
   Locker lock(isolate);
   HandleScope scope(isolate);
   Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
-  utility_context_.Reset(isolate,
-                         Context::New(isolate, NULL, global_template));
+  utility_context_ = Context::New(NULL, global_template);
 
 #ifdef ENABLE_DEBUGGER_SUPPORT
   // Start the debugger agent if requested.
@@ -1553,17 +1552,17 @@ void Shell::InitializeDebugger(Isolate* isolate) {
 }
 
 
-Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
+Persistent<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
 #ifndef V8_SHARED
   // This needs to be a critical section since this is not thread-safe
   i::ScopedLock lock(context_mutex_);
 #endif  // V8_SHARED
   // Initialize the global objects
   Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
-  HandleScope handle_scope(isolate);
-  Local<Context> context = Context::New(isolate, NULL, global_template);
+  Persistent<Context> context = Context::New(NULL, global_template);
   ASSERT(!context.IsEmpty());
-  Context::Scope scope(context);
+  HandleScope handle_scope(isolate);
+  Context::Scope scope(isolate, context);
 
 #ifndef V8_SHARED
   i::JSArguments js_args = i::FLAG_js_arguments;
@@ -1579,7 +1578,7 @@ Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
   context->Global()->Set(String::New("arguments"),
                          Utils::ToLocal(arguments_jsarray));
 #endif  // V8_SHARED
-  return handle_scope.Close(context);
+  return context;
 }
 
 
@@ -1810,9 +1809,9 @@ void ShellThread::Run() {
     // Prepare the context for this thread.
     Locker locker(isolate_);
     HandleScope outer_scope(isolate_);
-    Local<Context> thread_context =
+    Persistent<Context> thread_context =
         Shell::CreateEvaluationContext(isolate_);
-    Context::Scope context_scope(thread_context);
+    Context::Scope context_scope(isolate_, thread_context);
     PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate_));
 
     while ((ptr != NULL) && (*ptr != '\0')) {
@@ -1834,6 +1833,7 @@ void ShellThread::Run() {
       Shell::ExecuteString(isolate_, str, String::New(filename), false, false);
     }
 
+    thread_context.Dispose(thread_context->GetIsolate());
     ptr = next_line;
   }
 }
@@ -1910,16 +1910,15 @@ void SourceGroup::ExecuteInThread() {
     {
       Isolate::Scope iscope(isolate);
       Locker lock(isolate);
+      HandleScope scope(isolate);
+      PerIsolateData data(isolate);
+      Persistent<Context> context = Shell::CreateEvaluationContext(isolate);
       {
-        HandleScope scope(isolate);
-        PerIsolateData data(isolate);
-        Local<Context> context = Shell::CreateEvaluationContext(isolate);
-        {
-          Context::Scope cscope(context);
-          PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
-          Execute(isolate);
-        }
+        Context::Scope cscope(isolate, context);
+        PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
+        Execute(isolate);
       }
+      context.Dispose(isolate);
       if (Shell::options.send_idle_notification) {
         const int kLongIdlePauseInMs = 1000;
         V8::ContextDisposedNotification();
@@ -2110,27 +2109,26 @@ int Shell::RunMain(Isolate* isolate, int argc, char* argv[]) {
 #endif  // V8_SHARED
   {  // NOLINT
     Locker lock(isolate);
-    {
-      HandleScope scope(isolate);
-      Local<Context> context = CreateEvaluationContext(isolate);
-      if (options.last_run) {
-        // Keep using the same context in the interactive shell.
-        evaluation_context_.Reset(isolate, context);
+    HandleScope scope(isolate);
+    Persistent<Context> context = CreateEvaluationContext(isolate);
+    if (options.last_run) {
+      // Keep using the same context in the interactive shell.
+      evaluation_context_ = context;
 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
-        // If the interactive debugger is enabled make sure to activate
-        // it before running the files passed on the command line.
-        if (i::FLAG_debugger) {
-          InstallUtilityScript(isolate);
-        }
-#endif  // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
-      }
-      {
-        Context::Scope cscope(context);
-        PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
-        options.isolate_sources[0].Execute(isolate);
+      // If the interactive debugger is enabled make sure to activate
+      // it before running the files passed on the command line.
+      if (i::FLAG_debugger) {
+        InstallUtilityScript(isolate);
       }
+#endif  // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
+    }
+    {
+      Context::Scope cscope(isolate, context);
+      PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
+      options.isolate_sources[0].Execute(isolate);
     }
     if (!options.last_run) {
+      context.Dispose(isolate);
       if (options.send_idle_notification) {
         const int kLongIdlePauseInMs = 1000;
         V8::ContextDisposedNotification();
index c068dd9db1a0d6a31b97ee4cda008866ca9538b9..77646c288070eac6d9e5e1b94937895239cb440a 100644 (file)
--- a/src/d8.h
+++ b/src/d8.h
@@ -273,7 +273,7 @@ class Shell : public i::AllStatic {
   static const char* ToCString(const v8::String::Utf8Value& value);
   static void ReportException(Isolate* isolate, TryCatch* try_catch);
   static Handle<String> ReadFile(Isolate* isolate, const char* name);
-  static Local<Context> CreateEvaluationContext(Isolate* isolate);
+  static Persistent<Context> CreateEvaluationContext(Isolate* isolate);
   static int RunMain(Isolate* isolate, int argc, char* argv[]);
   static int Main(int argc, char* argv[]);
   static void Exit(int exit_code);
index 7592a8953110683c83c8f7e8942a57cd32555df7..b3c6097c859249439185907a9357423f49596c05 100644 (file)
@@ -328,18 +328,13 @@ int main(int argc, char** argv) {
   }
 #endif
   i::Serializer::Enable();
-  Isolate* isolate = Isolate::GetCurrent();
-  Persistent<Context> context;
-  {
-    HandleScope handle_scope(isolate);
-    context.Reset(isolate, Context::New(isolate));
-  }
-
+  Persistent<Context> context = v8::Context::New();
   if (context.IsEmpty()) {
     fprintf(stderr,
             "\nException thrown while compiling natives - see above.\n\n");
     exit(1);
   }
+  Isolate* isolate = context->GetIsolate();
   if (i::FLAG_extra_code != NULL) {
     context->Enter();
     // Capture 100 frames if anything happens.
index c249b5e92127c0adff760758a3470cc9644db95c..5a376c778864fd454466199a4c805fe61dfc4059 100644 (file)
@@ -207,14 +207,8 @@ class LocalContext {
   LocalContext(v8::ExtensionConfiguration* extensions = 0,
                v8::Handle<v8::ObjectTemplate> global_template =
                    v8::Handle<v8::ObjectTemplate>(),
-               v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    HandleScope scope(isolate);
-    context_.Reset(isolate,
-                   Context::New(isolate,
-                                extensions,
-                                global_template,
-                                global_object));
+               v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>())
+    : context_(v8::Context::New(extensions, global_template, global_object)) {
     context_->Enter();
     // We can't do this later perhaps because of a fatal error.
     isolate_ = context_->GetIsolate();
index c9685f8f4c07fa07914b68b4f15196543f29e815..1c17e8c9b3ca913923b98ba914f747ff2284e6aa 100644 (file)
@@ -4688,9 +4688,9 @@ THREADED_TEST(NamedInterceptorDictionaryIC) {
 
 
 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope scope(isolate);
-  v8::Local<Context> context1 = Context::New(isolate);
+  v8::HandleScope scope(v8::Isolate::GetCurrent());
+
+  v8::Persistent<Context> context1 = Context::New();
 
   context1->Enter();
   Local<ObjectTemplate> templ = ObjectTemplate::New();
@@ -4725,6 +4725,8 @@ THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) {
   context1->Enter();
   CompileRun("var obj = { x : 0 }; delete obj.x;");
   context1->Exit();
+
+  context1.Dispose(context1->GetIsolate());
 }
 
 
@@ -5499,14 +5501,14 @@ static v8::Handle<Value> HandleLogDelegator(const v8::Arguments& args) {
 
 
 THREADED_TEST(GlobalObjectTemplate) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
   Local<ObjectTemplate> global_template = ObjectTemplate::New();
   global_template->Set(v8_str("JSNI_Log"),
                        v8::FunctionTemplate::New(HandleLogDelegator));
-  v8::Local<Context> context = Context::New(isolate, 0, global_template);
-  Context::Scope context_scope(context);
+  v8::Persistent<Context> context = Context::New(0, global_template);
+  Context::Scope context_scope(v8::Isolate::GetCurrent(), context);
   Script::Compile(v8_str("JSNI_Log('LOG')"))->Run();
+  context.Dispose(context->GetIsolate());
 }
 
 
@@ -7674,8 +7676,7 @@ static void UnreachableSetter(Local<String>, Local<Value>,
 
 
 TEST(AccessControl) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
   v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
 
   global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
@@ -7695,7 +7696,7 @@ TEST(AccessControl) {
                                v8::DEFAULT);
 
   // Create an environment
-  v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
+  v8::Persistent<Context> context0 = Context::New(NULL, global_template);
   context0->Enter();
 
   v8::Handle<v8::Object> global0 = context0->Global();
@@ -7721,9 +7722,9 @@ TEST(AccessControl) {
   Local<Value> el_getter = global0->Get(v8_str("el_getter"));
   Local<Value> el_setter = global0->Get(v8_str("el_setter"));
 
-  v8::HandleScope scope1(isolate);
+  v8::HandleScope scope1(v8::Isolate::GetCurrent());
 
-  v8::Local<Context> context1 = Context::New(isolate);
+  v8::Persistent<Context> context1 = Context::New();
   context1->Enter();
 
   v8::Handle<v8::Object> global1 = context1->Global();
@@ -7913,12 +7914,13 @@ TEST(AccessControl) {
 
   context1->Exit();
   context0->Exit();
+  context1.Dispose(context1->GetIsolate());
+  context0.Dispose(context0->GetIsolate());
 }
 
 
 TEST(AccessControlES5) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
   v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
 
   global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
@@ -7939,12 +7941,12 @@ TEST(AccessControlES5) {
                                v8::DEFAULT);
 
   // Create an environment
-  v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
+  v8::Persistent<Context> context0 = Context::New(NULL, global_template);
   context0->Enter();
 
   v8::Handle<v8::Object> global0 = context0->Global();
 
-  v8::Local<Context> context1 = Context::New(isolate);
+  v8::Persistent<Context> context1 = Context::New();
   context1->Enter();
   v8::Handle<v8::Object> global1 = context1->Global();
   global1->Set(v8_str("other"), global0);
@@ -8004,8 +8006,7 @@ static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global,
 
 
 THREADED_TEST(AccessControlGetOwnPropertyNames) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
   v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
 
   obj_template->Set(v8_str("x"), v8::Integer::New(42));
@@ -8013,14 +8014,14 @@ THREADED_TEST(AccessControlGetOwnPropertyNames) {
                                         GetOwnPropertyNamesIndexedBlocker);
 
   // Create an environment
-  v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
+  v8::Persistent<Context> context0 = Context::New(NULL, obj_template);
   context0->Enter();
 
   v8::Handle<v8::Object> global0 = context0->Global();
 
   v8::HandleScope scope1(v8::Isolate::GetCurrent());
 
-  v8::Local<Context> context1 = Context::New(isolate);
+  v8::Persistent<Context> context1 = Context::New();
   context1->Enter();
 
   v8::Handle<v8::Object> global1 = context1->Global();
@@ -8042,6 +8043,8 @@ THREADED_TEST(AccessControlGetOwnPropertyNames) {
 
   context1->Exit();
   context0->Exit();
+  context1.Dispose(context1->GetIsolate());
+  context0.Dispose(context0->GetIsolate());
 }
 
 
@@ -8097,8 +8100,7 @@ static v8::Handle<Value> ConstTenGetter(Local<String> name,
 
 
 THREADED_TEST(CrossDomainAccessors) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
 
   v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
 
@@ -8120,7 +8122,7 @@ THREADED_TEST(CrossDomainAccessors) {
                                v8::Handle<Value>(),
                                v8::DEFAULT);
 
-  v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
+  v8::Persistent<Context> context0 = Context::New(NULL, global_template);
   context0->Enter();
 
   Local<v8::Object> global = context0->Global();
@@ -8129,7 +8131,7 @@ THREADED_TEST(CrossDomainAccessors) {
 
   // Enter a new context.
   v8::HandleScope scope1(v8::Isolate::GetCurrent());
-  v8::Local<Context> context1 = Context::New(isolate);
+  v8::Persistent<Context> context1 = Context::New();
   context1->Enter();
 
   v8::Handle<v8::Object> global1 = context1->Global();
@@ -8145,6 +8147,8 @@ THREADED_TEST(CrossDomainAccessors) {
 
   context1->Exit();
   context0->Exit();
+  context1.Dispose(context1->GetIsolate());
+  context0.Dispose(context0->GetIsolate());
 }
 
 
@@ -8174,11 +8178,10 @@ TEST(AccessControlIC) {
   named_access_count = 0;
   indexed_access_count = 0;
 
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
 
   // Create an environment.
-  v8::Local<Context> context0 = Context::New(isolate);
+  v8::Persistent<Context> context0 = Context::New();
   context0->Enter();
 
   // Create an object that requires access-check functions to be
@@ -8188,10 +8191,10 @@ TEST(AccessControlIC) {
                                            IndexedAccessCounter);
   Local<v8::Object> object = object_template->NewInstance();
 
-  v8::HandleScope scope1(isolate);
+  v8::HandleScope scope1(v8::Isolate::GetCurrent());
 
   // Create another environment.
-  v8::Local<Context> context1 = Context::New(isolate);
+  v8::Persistent<Context> context1 = Context::New();
   context1->Enter();
 
   // Make easy access to the object from the other environment.
@@ -8279,6 +8282,8 @@ TEST(AccessControlIC) {
 
   context1->Exit();
   context0->Exit();
+  context1.Dispose(context1->GetIsolate());
+  context0.Dispose(context0->GetIsolate());
 }
 
 
@@ -8322,11 +8327,10 @@ THREADED_TEST(AccessControlFlatten) {
   named_access_count = 0;
   indexed_access_count = 0;
 
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
 
   // Create an environment.
-  v8::Local<Context> context0 = Context::New(isolate);
+  v8::Persistent<Context> context0 = Context::New();
   context0->Enter();
 
   // Create an object that requires access-check functions to be
@@ -8336,10 +8340,10 @@ THREADED_TEST(AccessControlFlatten) {
                                            IndexedAccessFlatten);
   Local<v8::Object> object = object_template->NewInstance();
 
-  v8::HandleScope scope1(isolate);
+  v8::HandleScope scope1(v8::Isolate::GetCurrent());
 
   // Create another environment.
-  v8::Local<Context> context1 = Context::New(isolate);
+  v8::Persistent<Context> context1 = Context::New();
   context1->Enter();
 
   // Make easy access to the object from the other environment.
@@ -8353,6 +8357,8 @@ THREADED_TEST(AccessControlFlatten) {
 
   context1->Exit();
   context0->Exit();
+  context1.Dispose(context1->GetIsolate());
+  context0.Dispose(context0->GetIsolate());
 }
 
 
@@ -8385,11 +8391,10 @@ THREADED_TEST(AccessControlInterceptorIC) {
   named_access_count = 0;
   indexed_access_count = 0;
 
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
 
   // Create an environment.
-  v8::Local<Context> context0 = Context::New(isolate);
+  v8::Persistent<Context> context0 = Context::New();
   context0->Enter();
 
   // Create an object that requires access-check functions to be
@@ -8404,10 +8409,10 @@ THREADED_TEST(AccessControlInterceptorIC) {
                                              AccessControlIndexedSetter);
   Local<v8::Object> object = object_template->NewInstance();
 
-  v8::HandleScope scope1(isolate);
+  v8::HandleScope scope1(v8::Isolate::GetCurrent());
 
   // Create another environment.
-  v8::Local<Context> context1 = Context::New(isolate);
+  v8::Persistent<Context> context1 = Context::New();
   context1->Enter();
 
   // Make easy access to the object from the other environment.
@@ -8444,6 +8449,8 @@ THREADED_TEST(AccessControlInterceptorIC) {
 
   context1->Exit();
   context0->Exit();
+  context1.Dispose(context1->GetIsolate());
+  context0.Dispose(context0->GetIsolate());
 }
 
 
@@ -9304,11 +9311,10 @@ THREADED_TEST(CrossEval) {
 // its global throws an exception.  This behavior is consistent with
 // other JavaScript implementations.
 THREADED_TEST(EvalInDetachedGlobal) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope scope(isolate);
+  v8::HandleScope scope(v8::Isolate::GetCurrent());
 
-  v8::Local<Context> context0 = Context::New(isolate);
-  v8::Local<Context> context1 = Context::New(isolate);
+  v8::Persistent<Context> context0 = Context::New();
+  v8::Persistent<Context> context1 = Context::New();
 
   // Set up function in context0 that uses eval from context0.
   context0->Enter();
@@ -9333,6 +9339,9 @@ THREADED_TEST(EvalInDetachedGlobal) {
   CHECK(x_value.IsEmpty());
   CHECK(catcher.HasCaught());
   context1->Exit();
+
+  context1.Dispose(context1->GetIsolate());
+  context0.Dispose(context0->GetIsolate());
 }
 
 
@@ -11965,7 +11974,7 @@ THREADED_TEST(CheckForCrossContextObjectLiterals) {
 }
 
 
-static v8::Handle<Value> NestedScope(v8::Local<Context> env) {
+static v8::Handle<Value> NestedScope(v8::Persistent<Context> env) {
   v8::HandleScope inner(env->GetIsolate());
   env->Enter();
   v8::Handle<Value> three = v8_num(3);
@@ -11976,14 +11985,14 @@ static v8::Handle<Value> NestedScope(v8::Local<Context> env) {
 
 
 THREADED_TEST(NestedHandleScopeAndContexts) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope outer(isolate);
-  v8::Local<Context> env = Context::New(isolate);
+  v8::HandleScope outer(v8::Isolate::GetCurrent());
+  v8::Persistent<Context> env = Context::New();
   env->Enter();
   v8::Handle<Value> value = NestedScope(env);
   v8::Handle<String> str(value->ToString());
   CHECK(!str.IsEmpty());
   env->Exit();
+  env.Dispose(env->GetIsolate());
 }
 
 
@@ -12015,9 +12024,8 @@ static void RunLoopInNewEnv() {
   bar_ptr = NULL;
   foo_ptr = NULL;
 
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope outer(isolate);
-  v8::Local<Context> env = Context::New(isolate);
+  v8::HandleScope outer(v8::Isolate::GetCurrent());
+  v8::Persistent<Context> env = Context::New();
   env->Enter();
 
   const char* script =
@@ -12343,11 +12351,11 @@ static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); }
 
 
 THREADED_TEST(ExternalAllocatedMemory) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope outer(isolate);
-  v8::Local<Context> env(Context::New(isolate));
+  v8::HandleScope outer(v8::Isolate::GetCurrent());
+  v8::Persistent<Context> env(Context::New());
   CHECK(!env.IsEmpty());
   const intptr_t kSize = 1024*1024;
+  v8::Isolate* isolate = env->GetIsolate();
   int64_t baseline = cast(isolate->AdjustAmountOfExternalAllocatedMemory(0));
   CHECK_EQ(baseline + cast(kSize),
            cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize)));
@@ -12358,14 +12366,8 @@ THREADED_TEST(ExternalAllocatedMemory) {
 
 THREADED_TEST(DisposeEnteredContext) {
   LocalContext outer;
-  v8::Isolate* isolate = outer->GetIsolate();
-  v8::Persistent<v8::Context> inner;
-  {
-    v8::HandleScope scope(isolate);
-    inner.Reset(isolate, v8::Context::New(isolate));
-  }
-  v8::HandleScope scope(isolate);
-  {
+  v8::HandleScope scope(outer->GetIsolate());
+  { v8::Persistent<v8::Context> inner = v8::Context::New();
     inner->Enter();
     inner.Dispose(inner->GetIsolate());
     inner.Clear();
@@ -12685,8 +12687,7 @@ THREADED_TEST(AccessChecksReenabledCorrectly) {
 // This tests that access check information remains on the global
 // object template when creating contexts.
 THREADED_TEST(AccessControlRepeatedContextCreation) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
   v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
   global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker,
                                            IndexedSetAccessBlocker);
@@ -12696,15 +12697,14 @@ THREADED_TEST(AccessControlRepeatedContextCreation) {
   i::Handle<i::FunctionTemplateInfo> constructor(
       i::FunctionTemplateInfo::cast(internal_template->constructor()));
   CHECK(!constructor->access_check_info()->IsUndefined());
-  v8::Local<Context> context0(Context::New(isolate, NULL, global_template));
+  v8::Persistent<Context> context0(Context::New(NULL, global_template));
   CHECK(!context0.IsEmpty());
   CHECK(!constructor->access_check_info()->IsUndefined());
 }
 
 
 THREADED_TEST(TurnOnAccessCheck) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
 
   // Create an environment with access check to the global object disabled by
   // default.
@@ -12713,8 +12713,8 @@ THREADED_TEST(TurnOnAccessCheck) {
                                            IndexedGetAccessBlocker,
                                            v8::Handle<v8::Value>(),
                                            false);
-  v8::Local<Context> context = Context::New(isolate, NULL, global_template);
-  Context::Scope context_scope(context);
+  v8::Persistent<Context> context = Context::New(NULL, global_template);
+  Context::Scope context_scope(v8::Isolate::GetCurrent(), context);
 
   // Set up a property and a number of functions.
   context->Global()->Set(v8_str("a"), v8_num(1));
@@ -12784,8 +12784,7 @@ static bool NamedGetAccessBlockAandH(Local<v8::Object> obj,
 
 
 THREADED_TEST(TurnOnAccessCheckAndRecompile) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
 
   // Create an environment with access check to the global object disabled by
   // default. When the registered access checker will block access to properties
@@ -12795,8 +12794,8 @@ THREADED_TEST(TurnOnAccessCheckAndRecompile) {
                                            IndexedGetAccessBlocker,
                                            v8::Handle<v8::Value>(),
                                            false);
-  v8::Local<Context> context = Context::New(isolate, NULL, global_template);
-  Context::Scope context_scope(context);
+  v8::Persistent<Context> context = Context::New(NULL, global_template);
+  Context::Scope context_scope(v8::Isolate::GetCurrent(), context);
 
   // Set up a property and a number of functions.
   context->Global()->Set(v8_str("a"), v8_num(1));
@@ -13054,10 +13053,9 @@ THREADED_TEST(DictionaryICLoadedFunction) {
 // Test that cross-context new calls use the context of the callee to
 // create the new JavaScript object.
 THREADED_TEST(CrossContextNew) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope scope(isolate);
-  v8::Local<Context> context0 = Context::New(isolate);
-  v8::Local<Context> context1 = Context::New(isolate);
+  v8::HandleScope scope(v8::Isolate::GetCurrent());
+  v8::Persistent<Context> context0 = Context::New();
+  v8::Persistent<Context> context1 = Context::New();
 
   // Allow cross-domain access.
   Local<String> token = v8_str("<security token>");
@@ -13078,6 +13076,10 @@ THREADED_TEST(CrossContextNew) {
   CHECK(value->IsInt32());
   CHECK_EQ(42, value->Int32Value());
   context1->Exit();
+
+  // Dispose the contexts to allow them to be garbage collected.
+  context0.Dispose(context0->GetIsolate());
+  context1.Dispose(context1->GetIsolate());
 }
 
 
@@ -13858,10 +13860,9 @@ THREADED_TEST(ForceDeleteIC) {
 
 TEST(InlinedFunctionAcrossContexts) {
   i::FLAG_allow_natives_syntax = true;
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope outer_scope(isolate);
-  v8::Local<v8::Context> ctx1 = v8::Context::New(isolate);
-  v8::Local<v8::Context> ctx2 = v8::Context::New(isolate);
+  v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
+  v8::Persistent<v8::Context> ctx1 = v8::Context::New();
+  v8::Persistent<v8::Context> ctx2 = v8::Context::New();
   ctx1->Enter();
 
   {
@@ -13891,13 +13892,15 @@ TEST(InlinedFunctionAcrossContexts) {
         "ReferenceError: G is not defined");
     ctx2->Exit();
     ctx1->Exit();
+    ctx1.Dispose(ctx1->GetIsolate());
   }
+  ctx2.Dispose(ctx2->GetIsolate());
 }
 
 
-static v8::Local<Context> calling_context0;
-static v8::Local<Context> calling_context1;
-static v8::Local<Context> calling_context2;
+v8::Persistent<Context> calling_context0;
+v8::Persistent<Context> calling_context1;
+v8::Persistent<Context> calling_context2;
 
 
 // Check that the call to the callback is initiated in
@@ -13914,15 +13917,11 @@ static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments& args) {
 
 
 THREADED_TEST(GetCallingContext) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope scope(isolate);
+  v8::HandleScope scope(v8::Isolate::GetCurrent());
 
-  Local<Context> calling_context0(Context::New(isolate));
-  Local<Context> calling_context1(Context::New(isolate));
-  Local<Context> calling_context2(Context::New(isolate));
-  ::calling_context0 = calling_context0;
-  ::calling_context1 = calling_context1;
-  ::calling_context2 = calling_context2;
+  calling_context0 = Context::New();
+  calling_context1 = Context::New();
+  calling_context2 = Context::New();
 
   // Allow cross-domain access.
   Local<String> token = v8_str("<security token>");
@@ -13953,9 +13952,14 @@ THREADED_TEST(GetCallingContext) {
                                   calling_context1->Global());
   CompileRun("context1.f()");
   calling_context2->Exit();
-  ::calling_context0.Clear();
-  ::calling_context1.Clear();
-  ::calling_context2.Clear();
+
+  // Dispose the contexts to allow them to be garbage collected.
+  calling_context0.Dispose(calling_context0->GetIsolate());
+  calling_context1.Dispose(calling_context1->GetIsolate());
+  calling_context2.Dispose(calling_context2->GetIsolate());
+  calling_context0.Clear();
+  calling_context1.Clear();
+  calling_context2.Clear();
 }
 
 
@@ -15800,20 +15804,17 @@ TEST(Regress2107) {
   const int kShortIdlePauseInMs = 100;
   const int kLongIdlePauseInMs = 1000;
   LocalContext env;
-  v8::Isolate* isolate = env->GetIsolate();
   v8::HandleScope scope(env->GetIsolate());
   intptr_t initial_size = HEAP->SizeOfObjects();
   // Send idle notification to start a round of incremental GCs.
   v8::V8::IdleNotification(kShortIdlePauseInMs);
   // Emulate 7 page reloads.
   for (int i = 0; i < 7; i++) {
-    {
-      v8::HandleScope inner_scope(env->GetIsolate());
-      v8::Local<v8::Context> ctx = v8::Context::New(isolate);
-      ctx->Enter();
-      CreateGarbageInOldSpace();
-      ctx->Exit();
-    }
+    v8::Persistent<v8::Context> ctx = v8::Context::New();
+    ctx->Enter();
+    CreateGarbageInOldSpace();
+    ctx->Exit();
+    ctx.Dispose(ctx->GetIsolate());
     v8::V8::ContextDisposedNotification();
     v8::V8::IdleNotification(kLongIdlePauseInMs);
   }
@@ -16142,21 +16143,22 @@ THREADED_TEST(SpaghettiStackReThrow) {
 
 TEST(Regress528) {
   v8::V8::Initialize();
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope scope(isolate);
-  v8::Local<Context> other_context;
+
+  v8::HandleScope scope(v8::Isolate::GetCurrent());
+  v8::Persistent<Context> context;
+  v8::Persistent<Context> other_context;
   int gc_count;
 
   // Create a context used to keep the code from aging in the compilation
   // cache.
-  other_context = Context::New(isolate);
+  other_context = Context::New();
 
   // Context-dependent context data creates reference from the compilation
   // cache to the global object.
   const char* source_simple = "1";
+  context = Context::New();
   {
-    v8::HandleScope scope(isolate);
-    v8::Local<Context> context = Context::New(isolate);
+    v8::HandleScope scope(v8::Isolate::GetCurrent());
 
     context->Enter();
     Local<v8::String> obj = v8::String::New("");
@@ -16164,6 +16166,7 @@ TEST(Regress528) {
     CompileRun(source_simple);
     context->Exit();
   }
+  context.Dispose(context->GetIsolate());
   v8::V8::ContextDisposedNotification();
   for (gc_count = 1; gc_count < 10; gc_count++) {
     other_context->Enter();
@@ -16178,14 +16181,15 @@ TEST(Regress528) {
   // Eval in a function creates reference from the compilation cache to the
   // global object.
   const char* source_eval = "function f(){eval('1')}; f()";
+  context = Context::New();
   {
-    v8::HandleScope scope(isolate);
-    v8::Local<Context> context = Context::New(isolate);
+    v8::HandleScope scope(v8::Isolate::GetCurrent());
 
     context->Enter();
     CompileRun(source_eval);
     context->Exit();
   }
+  context.Dispose(context->GetIsolate());
   v8::V8::ContextDisposedNotification();
   for (gc_count = 1; gc_count < 10; gc_count++) {
     other_context->Enter();
@@ -16200,9 +16204,9 @@ TEST(Regress528) {
   // Looking up the line number for an exception creates reference from the
   // compilation cache to the global object.
   const char* source_exception = "function f(){throw 1;} f()";
+  context = Context::New();
   {
-    v8::HandleScope scope(isolate);
-    v8::Local<Context> context = Context::New(isolate);
+    v8::HandleScope scope(v8::Isolate::GetCurrent());
 
     context->Enter();
     v8::TryCatch try_catch;
@@ -16213,6 +16217,7 @@ TEST(Regress528) {
     CHECK_EQ(1, message->GetLineNumber());
     context->Exit();
   }
+  context.Dispose(context->GetIsolate());
   v8::V8::ContextDisposedNotification();
   for (gc_count = 1; gc_count < 10; gc_count++) {
     other_context->Enter();
@@ -16224,6 +16229,7 @@ TEST(Regress528) {
   CHECK_GE(2, gc_count);
   CHECK_EQ(1, GetGlobalObjectsCount());
 
+  other_context.Dispose(other_context->GetIsolate());
   v8::V8::ContextDisposedNotification();
 }
 
@@ -16940,11 +16946,7 @@ TEST(RunTwoIsolatesOnSingleThread) {
   // Run isolate 1.
   v8::Isolate* isolate1 = v8::Isolate::New();
   isolate1->Enter();
-  v8::Persistent<v8::Context> context1;
-  {
-    v8::HandleScope scope(isolate1);
-    context1.Reset(isolate1, Context::New(isolate1));
-  }
+  v8::Persistent<v8::Context> context1 = v8::Context::New();
 
   {
     v8::HandleScope scope(isolate1);
@@ -16960,8 +16962,8 @@ TEST(RunTwoIsolatesOnSingleThread) {
 
   {
     v8::Isolate::Scope iscope(isolate2);
+    context2 = v8::Context::New();
     v8::HandleScope scope(isolate2);
-    context2.Reset(isolate2, Context::New(isolate2));
     v8::Context::Scope cscope(isolate2, context2);
 
     // Run something in new isolate.
@@ -16979,13 +16981,7 @@ TEST(RunTwoIsolatesOnSingleThread) {
   isolate1->Exit();
 
   // Run some stuff in default isolate.
-  v8::Persistent<v8::Context> context_default;
-  {
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    v8::Isolate::Scope iscope(isolate);
-    v8::HandleScope scope(isolate);
-    context_default.Reset(isolate, Context::New(isolate));
-  }
+  v8::Persistent<v8::Context> context_default = v8::Context::New();
 
   {
     v8::HandleScope scope(v8::Isolate::GetCurrent());
@@ -17111,12 +17107,12 @@ TEST(MultipleIsolatesOnIndividualThreads) {
 
 TEST(IsolateDifferentContexts) {
   v8::Isolate* isolate = v8::Isolate::New();
-  Local<v8::Context> context;
+  Persistent<v8::Context> context;
   {
     v8::Isolate::Scope isolate_scope(isolate);
     v8::HandleScope handle_scope(isolate);
-    context = v8::Context::New(isolate);
-    v8::Context::Scope context_scope(context);
+    context = v8::Context::New();
+    v8::Context::Scope context_scope(isolate, context);
     Local<Value> v = CompileRun("2");
     CHECK(v->IsNumber());
     CHECK_EQ(2, static_cast<int>(v->NumberValue()));
@@ -17124,12 +17120,13 @@ TEST(IsolateDifferentContexts) {
   {
     v8::Isolate::Scope isolate_scope(isolate);
     v8::HandleScope handle_scope(isolate);
-    context = v8::Context::New(isolate);
-    v8::Context::Scope context_scope(context);
+    context = v8::Context::New();
+    v8::Context::Scope context_scope(isolate, context);
     Local<Value> v = CompileRun("22");
     CHECK(v->IsNumber());
     CHECK_EQ(22, static_cast<int>(v->NumberValue()));
   }
+  isolate->Dispose();
 }
 
 class InitDefaultIsolateThread : public v8::internal::Thread {
@@ -18018,8 +18015,7 @@ static bool BlockProtoNamedSecurityTestCallback(Local<v8::Object> global,
 
 
 THREADED_TEST(Regress93759) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  HandleScope scope(isolate);
+  HandleScope scope(v8::Isolate::GetCurrent());
 
   // Template for object with security check.
   Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New();
@@ -18040,7 +18036,7 @@ THREADED_TEST(Regress93759) {
   protected_hidden_proto_template->SetHiddenPrototype(true);
 
   // Context for "foreign" objects used in test.
-  Local<Context> context = v8::Context::New(isolate);
+  Persistent<Context> context = v8::Context::New();
   context->Enter();
 
   // Plain object, no security check.
@@ -18104,6 +18100,8 @@ THREADED_TEST(Regress93759) {
 
   Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)");
   CHECK(result6->Equals(Undefined()));
+
+  context.Dispose(context->GetIsolate());
 }
 
 
@@ -18142,15 +18140,14 @@ static void TestReceiver(Local<Value> expected_result,
 
 
 THREADED_TEST(ForeignFunctionReceiver) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  HandleScope scope(isolate);
+  HandleScope scope(v8::Isolate::GetCurrent());
 
   // Create two contexts with different "id" properties ('i' and 'o').
   // Call a function both from its own context and from a the foreign
   // context, and see what "this" is bound to (returning both "this"
   // and "this.id" for comparison).
 
-  Local<Context> foreign_context = v8::Context::New(isolate);
+  Persistent<Context> foreign_context = v8::Context::New();
   foreign_context->Enter();
   Local<Value> foreign_function =
     CompileRun("function func() { return { 0: this.id, "
@@ -18231,6 +18228,8 @@ THREADED_TEST(ForeignFunctionReceiver) {
   TestReceiver(o, context->Global(), "func()");
   // Calling with no base.
   TestReceiver(o, context->Global(), "(1,func)()");
+
+  foreign_context.Dispose(foreign_context->GetIsolate());
 }
 
 
index 0d47fe522c86e72cd76459cb54e2e043cbdba4f6..4d2cb0485fceb957b3bacf52ddedd804b199e4ea 100644 (file)
@@ -136,16 +136,12 @@ class DebugLocalContext {
       v8::Handle<v8::ObjectTemplate> global_template =
           v8::Handle<v8::ObjectTemplate>(),
       v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>())
-      : scope_(v8::Isolate::GetCurrent()),
-        context_(
-          v8::Context::New(v8::Isolate::GetCurrent(),
-                           extensions,
-                           global_template,
-                           global_object)) {
+      : context_(v8::Context::New(extensions, global_template, global_object)) {
     context_->Enter();
   }
   inline ~DebugLocalContext() {
     context_->Exit();
+    context_.Dispose(context_->GetIsolate());
   }
   inline v8::Context* operator->() { return *context_; }
   inline v8::Context* operator*() { return *context_; }
@@ -170,8 +166,7 @@ class DebugLocalContext {
   }
 
  private:
-  v8::HandleScope scope_;
-  v8::Local<v8::Context> context_;
+  v8::Persistent<v8::Context> context_;
 };
 
 
@@ -4239,8 +4234,7 @@ static const char* kSimpleExtensionSource =
 // http://crbug.com/28933
 // Test that debug break is disabled when bootstrapper is active.
 TEST(NoBreakWhenBootstrapping) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope scope(isolate);
+  v8::HandleScope scope(v8::Isolate::GetCurrent());
 
   // Register a debug event listener which sets the break flag and counts.
   v8::Debug::SetDebugEventListener(DebugEventCounter);
@@ -4255,8 +4249,8 @@ TEST(NoBreakWhenBootstrapping) {
                                             kSimpleExtensionSource));
     const char* extension_names[] = { "simpletest" };
     v8::ExtensionConfiguration extensions(1, extension_names);
-    v8::HandleScope handle_scope(isolate);
-    v8::Context::New(isolate, &extensions);
+    v8::Persistent<v8::Context> context = v8::Context::New(&extensions);
+    context.Dispose(context->GetIsolate());
   }
   // Check that no DebugBreak events occured during the context creation.
   CHECK_EQ(0, break_point_hit_count);
@@ -6241,7 +6235,7 @@ TEST(ScriptNameAndData) {
 }
 
 
-static v8::Handle<v8::Context> expected_context;
+static v8::Persistent<v8::Context> expected_context;
 static v8::Handle<v8::Value> expected_context_data;
 
 
@@ -6299,7 +6293,7 @@ TEST(ContextData) {
   // Enter and run function in the first context.
   {
     v8::Context::Scope context_scope(context_1);
-    expected_context = context_1;
+    expected_context = v8::Persistent<v8::Context>(*context_1);
     expected_context_data = data_1;
     v8::Local<v8::Function> f = CompileFunction(source, "f");
     f->Call(context_1->Global(), 0, NULL);
@@ -6309,7 +6303,7 @@ TEST(ContextData) {
   // Enter and run function in the second context.
   {
     v8::Context::Scope context_scope(context_2);
-    expected_context = context_2;
+    expected_context = v8::Persistent<v8::Context>(*context_2);
     expected_context_data = data_2;
     v8::Local<v8::Function> f = CompileFunction(source, "f");
     f->Call(context_2->Global(), 0, NULL);
@@ -6460,7 +6454,7 @@ static void ExecuteScriptForContextCheck() {
   // Enter and run function in the context.
   {
     v8::Context::Scope context_scope(context_1);
-    expected_context = v8::Local<v8::Context>(*context_1);
+    expected_context = v8::Persistent<v8::Context>(*context_1);
     expected_context_data = data_1;
     v8::Local<v8::Function> f = CompileFunction(source, "f");
     f->Call(context_1->Global(), 0, NULL);
@@ -6619,6 +6613,7 @@ TEST(ScriptCollectedEventContext) {
   v8::internal::Debug* debug =
       reinterpret_cast<v8::internal::Isolate*>(isolate)->debug();
   script_collected_message_count = 0;
+  v8::HandleScope scope(isolate);
 
   { // Scope for the DebugLocalContext.
     DebugLocalContext env;
@@ -6631,15 +6626,17 @@ TEST(ScriptCollectedEventContext) {
     HEAP->CollectAllGarbage(Heap::kNoGCFlags);
 
     v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler);
-    v8::Script::Compile(v8::String::New("eval('a=1')"))->Run();
-    v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
+    {
+      v8::Script::Compile(v8::String::New("eval('a=1')"))->Run();
+      v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
+    }
   }
 
   // Do garbage collection to collect the script above which is no longer
   // referenced.
   HEAP->CollectAllGarbage(Heap::kNoGCFlags);
 
-  CHECK_EQ(4, script_collected_message_count);
+  CHECK_EQ(2, script_collected_message_count);
 
   v8::Debug::SetMessageHandler2(NULL);
 }
@@ -7092,14 +7089,15 @@ static void DebugEventContextChecker(const v8::Debug::EventDetails& details) {
 
 // Check that event details contain context where debug event occured.
 TEST(DebugEventContext) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope scope(isolate);
+  v8::HandleScope scope(v8::Isolate::GetCurrent());
   expected_callback_data = v8::Int32::New(2010);
   v8::Debug::SetDebugEventListener2(DebugEventContextChecker,
                                     expected_callback_data);
-  expected_context = v8::Context::New(isolate);
-  v8::Context::Scope context_scope(expected_context);
+  expected_context = v8::Context::New();
+  v8::Context::Scope context_scope(
+      v8::Isolate::GetCurrent(), expected_context);
   v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run();
+  expected_context.Dispose(expected_context->GetIsolate());
   expected_context.Clear();
   v8::Debug::SetDebugEventListener(NULL);
   expected_context_data = v8::Handle<v8::Value>();
index 6be5303cde4643fd85b75b362d40f7905652f063..6216d67bd8889e183bfc60447fdb94198341688a 100644 (file)
@@ -118,8 +118,7 @@ DeclarationContext::DeclarationContext()
 
 void DeclarationContext::InitializeIfNeeded() {
   if (is_initialized_) return;
-  Isolate* isolate = Isolate::GetCurrent();
-  HandleScope scope(isolate);
+  HandleScope scope(Isolate::GetCurrent());
   Local<FunctionTemplate> function = FunctionTemplate::New();
   Local<Value> data = External::New(this);
   GetHolder(function)->SetNamedPropertyHandler(&HandleGet,
@@ -127,14 +126,10 @@ void DeclarationContext::InitializeIfNeeded() {
                                                &HandleQuery,
                                                0, 0,
                                                data);
-  context_.Reset(isolate,
-                 Context::New(isolate,
-                              0,
-                              function->InstanceTemplate(),
-                              Local<Value>()));
+  context_ = Context::New(0, function->InstanceTemplate(), Local<Value>());
   context_->Enter();
   is_initialized_ = true;
-  PostInitializeContext(Local<Context>::New(isolate, context_));
+  PostInitializeContext(Local<Context>::New(Isolate::GetCurrent(), context_));
 }
 
 
@@ -704,14 +699,14 @@ TEST(ExistsInHiddenPrototype) {
 
 class SimpleContext {
  public:
-  SimpleContext()
-      : handle_scope_(Isolate::GetCurrent()),
-        context_(Context::New(Isolate::GetCurrent())) {
+  SimpleContext() {
+    context_ = Context::New();
     context_->Enter();
   }
 
-  ~SimpleContext() {
+  virtual ~SimpleContext() {
     context_->Exit();
+    context_.Dispose(context_->GetIsolate());
   }
 
   void Check(const char* source,
@@ -742,8 +737,7 @@ class SimpleContext {
   }
 
  private:
-  HandleScope handle_scope_;
-  Local<Context> context_;
+  Persistent<Context> context_;
 };
 
 
index 154761313935d7fce15d4decdcb64e3dbdef01a7..6cf63d9fbbb95eb7d0cd81be057e8df14e6ecdde 100644 (file)
@@ -47,6 +47,8 @@ using namespace v8::internal;
 
 typedef uint32_t (*HASH_FUNCTION)();
 
+static v8::Persistent<v8::Context> env;
+
 #define __ masm->
 
 
@@ -233,10 +235,7 @@ static uint32_t PseudoRandom(uint32_t i, uint32_t j) {
 
 
 TEST(StringHash) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
-  v8::Context::Scope context_scope(v8::Context::New(isolate));
-
+  if (env.IsEmpty()) env = v8::Context::New();
   for (uint8_t a = 0; a < String::kMaxOneByteCharCode; a++) {
     // Numbers are hashed differently.
     if (a >= '0' && a <= '9') continue;
@@ -254,9 +253,7 @@ TEST(StringHash) {
 
 
 TEST(NumberHash) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handle_scope(isolate);
-  v8::Context::Scope context_scope(v8::Context::New(isolate));
+  if (env.IsEmpty()) env = v8::Context::New();
 
   // Some specific numbers
   for (uint32_t key = 0; key < 42; key += 7) {
index 069ba2d5b19adc61c78f81c0b5761e905ffb343c..1de24ce88d4b62857859757698590d06133bf312 100644 (file)
@@ -1661,15 +1661,9 @@ static int NumberOfGlobalObjects() {
 // optimized code.
 TEST(LeakNativeContextViaMap) {
   i::FLAG_allow_natives_syntax = true;
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope outer_scope(isolate);
-  v8::Persistent<v8::Context> ctx1;
-  v8::Persistent<v8::Context> ctx2;
-  {
-    v8::HandleScope scope(isolate);
-    ctx1.Reset(isolate, v8::Context::New(isolate));
-    ctx2.Reset(isolate, v8::Context::New(isolate));
-  }
+  v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
+  v8::Persistent<v8::Context> ctx1 = v8::Context::New();
+  v8::Persistent<v8::Context> ctx2 = v8::Context::New();
   ctx1->Enter();
 
   HEAP->CollectAllAvailableGarbage();
@@ -1705,15 +1699,9 @@ TEST(LeakNativeContextViaMap) {
 // optimized code.
 TEST(LeakNativeContextViaFunction) {
   i::FLAG_allow_natives_syntax = true;
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope outer_scope(isolate);
-  v8::Persistent<v8::Context> ctx1;
-  v8::Persistent<v8::Context> ctx2;
-  {
-    v8::HandleScope scope(isolate);
-    ctx1.Reset(isolate, v8::Context::New(isolate));
-    ctx2.Reset(isolate, v8::Context::New(isolate));
-  }
+  v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
+  v8::Persistent<v8::Context> ctx1 = v8::Context::New();
+  v8::Persistent<v8::Context> ctx2 = v8::Context::New();
   ctx1->Enter();
 
   HEAP->CollectAllAvailableGarbage();
@@ -1747,15 +1735,9 @@ TEST(LeakNativeContextViaFunction) {
 
 TEST(LeakNativeContextViaMapKeyed) {
   i::FLAG_allow_natives_syntax = true;
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope outer_scope(isolate);
-  v8::Persistent<v8::Context> ctx1;
-  v8::Persistent<v8::Context> ctx2;
-  {
-    v8::HandleScope scope(isolate);
-    ctx1.Reset(isolate, v8::Context::New(isolate));
-    ctx2.Reset(isolate, v8::Context::New(isolate));
-  }
+  v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
+  v8::Persistent<v8::Context> ctx1 = v8::Context::New();
+  v8::Persistent<v8::Context> ctx2 = v8::Context::New();
   ctx1->Enter();
 
   HEAP->CollectAllAvailableGarbage();
@@ -1789,15 +1771,9 @@ TEST(LeakNativeContextViaMapKeyed) {
 
 TEST(LeakNativeContextViaMapProto) {
   i::FLAG_allow_natives_syntax = true;
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope outer_scope(isolate);
-  v8::Persistent<v8::Context> ctx1;
-  v8::Persistent<v8::Context> ctx2;
-  {
-    v8::HandleScope scope(isolate);
-    ctx1.Reset(isolate, v8::Context::New(isolate));
-    ctx2.Reset(isolate, v8::Context::New(isolate));
-  }
+  v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
+  v8::Persistent<v8::Context> ctx1 = v8::Context::New();
+  v8::Persistent<v8::Context> ctx2 = v8::Context::New();
   ctx1->Enter();
 
   HEAP->CollectAllAvailableGarbage();
index ca0f0731332a2c42a195e3a27063a1aabfb8e2f5..8486e21af6a1a15ba27adc9bc06e3342c2365733 100644 (file)
@@ -622,14 +622,15 @@ TEST(LockUnlockLockDefaultIsolateMultithreaded) {
 #else
   const int kNThreads = 100;
 #endif
-  Local<v8::Context> context;
+  Persistent<v8::Context> context;
   i::List<JoinableThread*> threads(kNThreads);
   {
     v8::Locker locker_(CcTest::default_isolate());
     v8::HandleScope handle_scope(CcTest::default_isolate());
-    context = v8::Context::New(CcTest::default_isolate());
+    context = v8::Context::New();
     for (int i = 0; i < kNThreads; i++) {
-      threads.Add(new LockUnlockLockDefaultIsolateThread(context));
+      threads.Add(new LockUnlockLockDefaultIsolateThread(
+          v8::Local<v8::Context>::New(CcTest::default_isolate(), context)));
     }
   }
   StartJoinAndDeleteThreads(threads);
@@ -674,9 +675,9 @@ class IsolateGenesisThread : public JoinableThread {
       v8::Isolate::Scope isolate_scope(isolate);
       CHECK(!i::Isolate::Current()->has_installed_extensions());
       v8::ExtensionConfiguration extensions(count_, extension_names_);
-      v8::HandleScope handle_scope(isolate);
-      v8::Context::New(isolate, &extensions);
+      v8::Persistent<v8::Context> context = v8::Context::New(&extensions);
       CHECK(i::Isolate::Current()->has_installed_extensions());
+      context.Dispose(isolate);
     }
     isolate->Dispose();
   }
index 3288fc8a61bb51f4bb7cb850c1450d7d35c2539f..b49bb828e27d04b0b4959ffbbe6a5808ac52ea4d 100644 (file)
@@ -67,7 +67,7 @@ class ScopedLoggerInitializer {
         // Need to run this prior to creating the scope.
         trick_to_run_init_flags_(init_flags_(prof_lazy)),
         scope_(v8::Isolate::GetCurrent()),
-        env_(v8::Context::New(v8::Isolate::GetCurrent())),
+        env_(*v8::Context::New()),
         logger_(i::Isolate::Current()->logger()) {
     env_->Enter();
   }
index 05fea0bbb617ba0a9b06f140f8a144df122fd712..f74c0799b4f52ae5680e301eae61baa0aee0a884 100644 (file)
@@ -176,10 +176,9 @@ class ScriptResource : public v8::String::ExternalAsciiStringResource {
 
 
 TEST(Preparsing) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handles(isolate);
-  v8::Local<v8::Context> context = v8::Context::New(isolate);
-  v8::Context::Scope context_scope(context);
+  v8::HandleScope handles(v8::Isolate::GetCurrent());
+  v8::Persistent<v8::Context> context = v8::Context::New();
+  v8::Context::Scope context_scope(v8::Isolate::GetCurrent(), context);
   int marker;
   i::Isolate::Current()->stack_guard()->SetStackLimit(
       reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
@@ -543,10 +542,9 @@ void TestCharacterStream(const char* ascii_source,
 
 
 TEST(CharacterStreams) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope handles(isolate);
-  v8::Local<v8::Context> context = v8::Context::New(isolate);
-  v8::Context::Scope context_scope(context);
+  v8::HandleScope handles(v8::Isolate::GetCurrent());
+  v8::Persistent<v8::Context> context = v8::Context::New();
+  v8::Context::Scope context_scope(v8::Isolate::GetCurrent(), context);
 
   TestCharacterStream("abc\0\n\r\x7f", 7);
   static const unsigned kBigStringSize = 4096;
index 70b34e3d7c276688c27a49755d1081899f5ec499..a18422a748a160a3a56b2885b434aafa3f2800f6 100644 (file)
@@ -855,6 +855,7 @@ v8::Handle<v8::Value> ProfilerExtension::StopProfiling(
 
 static ProfilerExtension kProfilerExtension;
 v8::DeclareExtension kProfilerExtensionDeclaration(&kProfilerExtension);
+static v8::Persistent<v8::Context> env;
 
 static const ProfileNode* PickChild(const ProfileNode* parent,
                                     const char* name) {
@@ -871,12 +872,14 @@ TEST(RecordStackTraceAtStartProfiling) {
   // don't appear in the stack trace.
   i::FLAG_use_inlining = false;
 
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope scope(isolate);
-  const char* extensions[] = { "v8/profiler" };
-  v8::ExtensionConfiguration config(1, extensions);
-  v8::Local<v8::Context> context = v8::Context::New(isolate);
-  context->Enter();
+  if (env.IsEmpty()) {
+    v8::HandleScope scope(v8::Isolate::GetCurrent());
+    const char* extensions[] = { "v8/profiler" };
+    v8::ExtensionConfiguration config(1, extensions);
+    env = v8::Context::New(&config);
+  }
+  v8::HandleScope scope(v8::Isolate::GetCurrent());
+  (*env)->Enter();
 
   CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
   CHECK_EQ(0, profiler->GetProfilesCount());
index 0837ab3e360307febecf069582a8914da89e6b04..6b6e0e0ff1a101292703b0b3799650a38094d29c 100644 (file)
@@ -39,6 +39,8 @@
 
 using namespace v8::internal;
 
+static v8::Persistent<v8::Context> env;
+
 
 void SetSeeds(Handle<ByteArray> seeds, uint32_t state0, uint32_t state1) {
   for (int i = 0; i < 4; i++) {
@@ -71,12 +73,11 @@ void TestSeeds(Handle<JSFunction> fun,
 
 
 TEST(CrankshaftRandom) {
-  v8::V8::Initialize();
+  if (env.IsEmpty()) env = v8::Context::New();
   // Skip test if crankshaft is disabled.
   if (!V8::UseCrankshaft()) return;
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::HandleScope scope(isolate);
-  v8::Context::Scope context_scope(v8::Context::New(isolate));
+  v8::HandleScope scope(env->GetIsolate());
+  env->Enter();
 
   Handle<Context> context(Isolate::Current()->context());
   Handle<JSObject> global(context->global_object());
index f311dcc578c0df66a65c409c96772c210203951b..4c05aa59385b26510d87135dd56a66c78accd36f 100644 (file)
@@ -711,17 +711,19 @@ typedef RegExpMacroAssemblerMIPS ArchRegExpMacroAssembler;
 class ContextInitializer {
  public:
   ContextInitializer()
-      : scope_(v8::Isolate::GetCurrent()),
-        env_(v8::Context::New(v8::Isolate::GetCurrent())),
+      : env_(),
+        scope_(v8::Isolate::GetCurrent()),
         zone_(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT) {
+    env_ = v8::Context::New();
     env_->Enter();
   }
   ~ContextInitializer() {
     env_->Exit();
+    env_.Dispose(env_->GetIsolate());
   }
  private:
+  v8::Persistent<v8::Context> env_;
   v8::HandleScope scope_;
-  v8::Handle<v8::Context> env_;
   v8::internal::ZoneScope zone_;
 };
 
index 0cf80440f6dafe823dcbbfcb4bf2dadacb1c39a9..d236cf1fa8a8f927d833ab90107ed49b7a031cc8 100644 (file)
@@ -251,11 +251,8 @@ static void Serialize() {
   // can be loaded from v8natives.js and their addresses can be processed.  This
   // will clear the pending fixups array, which would otherwise contain GC roots
   // that would confuse the serialization/deserialization process.
-  {
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    v8::HandleScope scope(isolate);
-    v8::Context::New(isolate);
-  }
+  v8::Persistent<v8::Context> env = v8::Context::New();
+  env.Dispose(env->GetIsolate());
   WriteToFile(FLAG_testing_serialization_file);
 }
 
@@ -307,11 +304,10 @@ DEPENDENT_TEST(Deserialize, Serialize) {
   // serialization.  That doesn't matter.  We don't need to be able to
   // serialize a snapshot in a VM that is booted from a snapshot.
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    v8::HandleScope scope(isolate);
+    v8::HandleScope scope(v8::Isolate::GetCurrent());
     Deserialize();
 
-    v8::Local<v8::Context> env = v8::Context::New(isolate);
+    v8::Persistent<v8::Context> env = v8::Context::New();
     env->Enter();
 
     SanityCheck();
@@ -321,11 +317,10 @@ DEPENDENT_TEST(Deserialize, Serialize) {
 
 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    v8::HandleScope scope(isolate);
+    v8::HandleScope scope(v8::Isolate::GetCurrent());
     Deserialize();
 
-    v8::Local<v8::Context> env = v8::Context::New(isolate);
+    v8::Persistent<v8::Context> env = v8::Context::New();
     env->Enter();
 
     SanityCheck();
@@ -335,11 +330,10 @@ DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) {
 
 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    v8::HandleScope scope(isolate);
+    v8::HandleScope scope(v8::Isolate::GetCurrent());
     Deserialize();
 
-    v8::Local<v8::Context> env = v8::Context::New(isolate);
+    v8::Persistent<v8::Context> env = v8::Context::New();
     env->Enter();
 
     const char* c_source = "\"1234\".length";
@@ -353,11 +347,10 @@ DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2,
                SerializeTwice) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    v8::HandleScope scope(isolate);
+    v8::HandleScope scope(v8::Isolate::GetCurrent());
     Deserialize();
 
-    v8::Local<v8::Context> env = v8::Context::New(isolate);
+    v8::Persistent<v8::Context> env = v8::Context::New();
     env->Enter();
 
     const char* c_source = "\"1234\".length";
@@ -375,12 +368,7 @@ TEST(PartialSerialization) {
     Isolate* isolate = Isolate::Current();
     Heap* heap = isolate->heap();
 
-    v8::Persistent<v8::Context> env;
-    {
-      HandleScope scope(isolate);
-      env.Reset(v8::Isolate::GetCurrent(),
-                v8::Context::New(v8::Isolate::GetCurrent()));
-    }
+    v8::Persistent<v8::Context> env = v8::Context::New();
     ASSERT(!env.IsEmpty());
     env->Enter();
     // Make sure all builtin scripts are cached.
@@ -514,12 +502,7 @@ TEST(ContextSerialization) {
     Isolate* isolate = Isolate::Current();
     Heap* heap = isolate->heap();
 
-    v8::Persistent<v8::Context> env;
-    {
-      HandleScope scope(isolate);
-      env.Reset(v8::Isolate::GetCurrent(),
-                v8::Context::New(v8::Isolate::GetCurrent()));
-    }
+    v8::Persistent<v8::Context> env = v8::Context::New();
     ASSERT(!env.IsEmpty());
     env->Enter();
     // Make sure all builtin scripts are cached.