diff --git a/test/cctest/cctest.h b/test/cctest/cctest.h index f489849bac..26d9972794 100644 --- a/test/cctest/cctest.h +++ b/test/cctest/cctest.h @@ -220,20 +220,19 @@ class RegisterThreadedTest { // A LocalContext holds a reference to a v8::Context. class LocalContext { public: + LocalContext(v8::Isolate* isolate, + v8::ExtensionConfiguration* extensions = 0, + v8::Handle global_template = + v8::Handle(), + v8::Handle global_object = v8::Handle()) { + Initialize(isolate, extensions, global_template, global_object); + } + LocalContext(v8::ExtensionConfiguration* extensions = 0, v8::Handle global_template = v8::Handle(), v8::Handle global_object = v8::Handle()) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::HandleScope scope(isolate); - v8::Local context = v8::Context::New(isolate, - extensions, - global_template, - global_object); - context_.Reset(isolate, context); - context->Enter(); - // We can't do this later perhaps because of a fatal error. - isolate_ = context->GetIsolate(); + Initialize(CcTest::isolate(), extensions, global_template, global_object); } virtual ~LocalContext() { @@ -253,6 +252,21 @@ class LocalContext { } private: + void Initialize(v8::Isolate* isolate, + v8::ExtensionConfiguration* extensions, + v8::Handle global_template, + v8::Handle global_object) { + v8::HandleScope scope(isolate); + v8::Local context = v8::Context::New(isolate, + extensions, + global_template, + global_object); + context_.Reset(isolate, context); + context->Enter(); + // We can't do this later perhaps because of a fatal error. + isolate_ = isolate; + } + v8::Persistent context_; v8::Isolate* isolate_; }; diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 37c2e975e8..c7ca9522ac 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -13364,7 +13364,7 @@ static void event_handler(const v8::JitCodeEvent* event) { } -TEST(SetJitCodeEventHandler) { +UNINITIALIZED_TEST(SetJitCodeEventHandler) { i::FLAG_stress_compaction = true; i::FLAG_incremental_marking = false; const char* script = @@ -13400,7 +13400,7 @@ TEST(SetJitCodeEventHandler) { // different fragmented code-space pages. const int kIterations = 10; for (int i = 0; i < kIterations; ++i) { - LocalContext env; + LocalContext env(isolate); i::AlwaysAllocateScope always_allocate; SimulateFullSpace(heap->code_space()); CompileRun(script); @@ -13438,7 +13438,7 @@ TEST(SetJitCodeEventHandler) { // request enumeration of existing code. { v8::HandleScope scope(isolate); - LocalContext env; + LocalContext env(isolate); CompileRun(script); // Now get code through initial iteration. @@ -18221,7 +18221,7 @@ UNINITIALIZED_TEST(DisposeIsolateWhenInUse) { CHECK(isolate); isolate->Enter(); v8::HandleScope scope(isolate); - LocalContext context; + LocalContext context(isolate); // Run something in this isolate. ExpectTrue("true"); v8::V8::SetFatalErrorHandler(StoringErrorCallback); @@ -18361,7 +18361,7 @@ TEST(RunTwoIsolatesOnSingleThread) { static int CalcFibonacci(v8::Isolate* isolate, int limit) { v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope scope(isolate); - LocalContext context; + LocalContext context(isolate); i::ScopedVector code(1024); i::OS::SNPrintF(code, "function fib(n) {" " if (n <= 2) return 1;" diff --git a/test/cctest/test-lockers.cc b/test/cctest/test-lockers.cc index dc2ab1c6c1..9c843ae3d4 100644 --- a/test/cctest/test-lockers.cc +++ b/test/cctest/test-lockers.cc @@ -183,7 +183,7 @@ class IsolateLockingThreadWithLocalContext : public JoinableThread { v8::Locker locker(isolate_); v8::Isolate::Scope isolate_scope(isolate_); v8::HandleScope handle_scope(isolate_); - LocalContext local_context; + LocalContext local_context(isolate_); CHECK_EQ(isolate_, v8::internal::Isolate::Current()); CalcFibAndCheck(); } @@ -267,7 +267,7 @@ class IsolateNestedLockingThread : public JoinableThread { v8::Locker lock(isolate_); v8::Isolate::Scope isolate_scope(isolate_); v8::HandleScope handle_scope(isolate_); - LocalContext local_context; + LocalContext local_context(isolate_); { v8::Locker another_lock(isolate_); CalcFibAndCheck(); @@ -311,7 +311,7 @@ class SeparateIsolatesLocksNonexclusiveThread : public JoinableThread { v8::Locker lock(isolate1_); v8::Isolate::Scope isolate_scope(isolate1_); v8::HandleScope handle_scope(isolate1_); - LocalContext local_context; + LocalContext local_context(isolate1_); IsolateLockingThreadWithLocalContext threadB(isolate2_); threadB.Start(); diff --git a/test/cctest/test-object-observe.cc b/test/cctest/test-object-observe.cc index 196636d5b1..5e11042452 100644 --- a/test/cctest/test-object-observe.cc +++ b/test/cctest/test-object-observe.cc @@ -58,7 +58,7 @@ class HarmonyIsolate { TEST(PerIsolateState) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context1; + LocalContext context1(isolate.GetIsolate()); CompileRun( "var count = 0;" "var calls = 0;" @@ -71,20 +71,20 @@ TEST(PerIsolateState) { "(function() { obj.foo = 'bar'; })"); Handle notify_fun2; { - LocalContext context2; + LocalContext context2(isolate.GetIsolate()); context2->Global()->Set(String::New("obj"), obj); notify_fun2 = CompileRun( "(function() { obj.foo = 'baz'; })"); } Handle notify_fun3; { - LocalContext context3; + LocalContext context3(isolate.GetIsolate()); context3->Global()->Set(String::New("obj"), obj); notify_fun3 = CompileRun( "(function() { obj.foo = 'bat'; })"); } { - LocalContext context4; + LocalContext context4(isolate.GetIsolate()); context4->Global()->Set(String::New("observer"), observer); context4->Global()->Set(String::New("fun1"), notify_fun1); context4->Global()->Set(String::New("fun2"), notify_fun2); @@ -99,7 +99,7 @@ TEST(PerIsolateState) { TEST(EndOfMicrotaskDelivery) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); CompileRun( "var obj = {};" "var count = 0;" @@ -113,7 +113,7 @@ TEST(EndOfMicrotaskDelivery) { TEST(DeliveryOrdering) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); CompileRun( "var obj1 = {};" "var obj2 = {};" @@ -145,7 +145,7 @@ TEST(DeliveryOrdering) { TEST(DeliveryOrderingReentrant) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); CompileRun( "var obj = {};" "var reentered = false;" @@ -177,7 +177,7 @@ TEST(DeliveryOrderingReentrant) { TEST(DeliveryOrderingDeliverChangeRecords) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); CompileRun( "var obj = {};" "var ordering = [];" @@ -203,14 +203,14 @@ TEST(ObjectHashTableGrowth) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); // Initializing this context sets up initial hash tables. - LocalContext context; + LocalContext context(isolate.GetIsolate()); Handle obj = CompileRun("obj = {};"); Handle observer = CompileRun( "var ran = false;" "(function() { ran = true })"); { // As does initializing this context. - LocalContext context2; + LocalContext context2(isolate.GetIsolate()); context2->Global()->Set(String::New("obj"), obj); context2->Global()->Set(String::New("observer"), observer); CompileRun( @@ -231,7 +231,7 @@ TEST(ObjectHashTableGrowth) { TEST(GlobalObjectObservation) { HarmonyIsolate isolate; - LocalContext context; + LocalContext context(isolate.GetIsolate()); HandleScope scope(isolate.GetIsolate()); Handle global_proxy = context->Global(); Handle inner_global = global_proxy->GetPrototype().As(); @@ -263,7 +263,7 @@ TEST(GlobalObjectObservation) { // to the old context. context->DetachGlobal(); { - LocalContext context2; + LocalContext context2(isolate.GetIsolate()); context2->DetachGlobal(); context2->ReattachGlobal(global_proxy); CompileRun( @@ -278,7 +278,8 @@ TEST(GlobalObjectObservation) { // Attaching by passing to Context::New { // Delegates to Context::New - LocalContext context3(NULL, Handle(), global_proxy); + LocalContext context3( + isolate.GetIsolate(), NULL, Handle(), global_proxy); CompileRun( "var records3 = [];" "Object.observe(this, function(r) { [].push.apply(records3, r) });" @@ -330,7 +331,7 @@ static void ExpectRecords(Handle records, TEST(APITestBasicMutation) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); Handle obj = Handle::Cast(CompileRun( "var records = [];" "var obj = {};" @@ -374,7 +375,7 @@ TEST(APITestBasicMutation) { TEST(HiddenPrototypeObservation) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); Handle tmpl = FunctionTemplate::New(); tmpl->SetHiddenPrototype(true); tmpl->InstanceTemplate()->Set(String::New("foo"), Number::New(75)); @@ -423,7 +424,7 @@ static int NumberOfElements(i::Handle map) { TEST(ObservationWeakMap) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); CompileRun( "var obj = {};" "Object.observe(obj, function(){});" @@ -517,7 +518,7 @@ TEST(NamedAccessCheck) { const AccessType types[] = { ACCESS_GET, ACCESS_HAS }; for (size_t i = 0; i < ARRAY_SIZE(types); ++i) { HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); g_access_block_type = types[i]; Handle instance = CreateAccessCheckedObject( NamedAccessAllowUnlessBlocked, IndexedAccessAlwaysAllowed); @@ -529,7 +530,7 @@ TEST(NamedAccessCheck) { "Object.observe(objNoCheck, observer);"); Handle obj_no_check = CompileRun("objNoCheck"); { - LocalContext context2; + LocalContext context2(isolate.GetIsolate()); context2->Global()->Set(String::New("obj"), instance); context2->Global()->Set(String::New("objNoCheck"), obj_no_check); CompileRun("var records2 = null;" @@ -564,7 +565,7 @@ TEST(IndexedAccessCheck) { const AccessType types[] = { ACCESS_GET, ACCESS_HAS }; for (size_t i = 0; i < ARRAY_SIZE(types); ++i) { HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); g_access_block_type = types[i]; Handle instance = CreateAccessCheckedObject( NamedAccessAlwaysAllowed, IndexedAccessAllowUnlessBlocked); @@ -576,7 +577,7 @@ TEST(IndexedAccessCheck) { "Object.observe(objNoCheck, observer);"); Handle obj_no_check = CompileRun("objNoCheck"); { - LocalContext context2; + LocalContext context2(isolate.GetIsolate()); context2->Global()->Set(String::New("obj"), instance); context2->Global()->Set(String::New("objNoCheck"), obj_no_check); CompileRun("var records2 = null;" @@ -609,7 +610,7 @@ TEST(IndexedAccessCheck) { TEST(SpliceAccessCheck) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); g_access_block_type = ACCESS_GET; Handle instance = CreateAccessCheckedObject( NamedAccessAlwaysAllowed, IndexedAccessAllowUnlessBlocked); @@ -623,7 +624,7 @@ TEST(SpliceAccessCheck) { "Array.observe(objNoCheck, observer);"); Handle obj_no_check = CompileRun("objNoCheck"); { - LocalContext context2; + LocalContext context2(isolate.GetIsolate()); context2->Global()->Set(String::New("obj"), instance); context2->Global()->Set(String::New("objNoCheck"), obj_no_check); CompileRun("var records2 = null;" @@ -654,7 +655,7 @@ TEST(SpliceAccessCheck) { TEST(DisallowAllForAccessKeys) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); Handle instance = CreateAccessCheckedObject( BlockAccessKeys, IndexedAccessAlwaysAllowed); CompileRun("var records = null;" @@ -665,7 +666,7 @@ TEST(DisallowAllForAccessKeys) { "Object.observe(objNoCheck, observer);"); Handle obj_no_check = CompileRun("objNoCheck"); { - LocalContext context2; + LocalContext context2(isolate.GetIsolate()); context2->Global()->Set(String::New("obj"), instance); context2->Global()->Set(String::New("objNoCheck"), obj_no_check); CompileRun("var records2 = null;" @@ -692,7 +693,7 @@ TEST(DisallowAllForAccessKeys) { TEST(AccessCheckDisallowApiModifications) { HarmonyIsolate isolate; HandleScope scope(isolate.GetIsolate()); - LocalContext context; + LocalContext context(isolate.GetIsolate()); Handle instance = CreateAccessCheckedObject( BlockAccessKeys, IndexedAccessAlwaysAllowed); CompileRun("var records = null;" @@ -700,7 +701,7 @@ TEST(AccessCheckDisallowApiModifications) { "var blacklist = {__block_access_keys: true};" "Object.observe(obj, observer);"); { - LocalContext context2; + LocalContext context2(isolate.GetIsolate()); context2->Global()->Set(String::New("obj"), instance); CompileRun("var records2 = null;" "var observer2 = function(r) { records2 = r };"