From 86a2e4849a288efa6f35f8bf931d336ffc7b9703 Mon Sep 17 00:00:00 2001 From: "dcarney@chromium.org" Date: Mon, 23 Sep 2013 11:25:52 +0000 Subject: [PATCH] remove Isolate::GetCurrent from Context api functions R=mstarzinger@chromium.org BUG= Review URL: https://codereview.chromium.org/24345003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16877 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 34 +++++---- samples/lineprocessor.cc | 4 +- src/api.cc | 106 +++++++++++------------------ src/api.h | 6 +- src/d8.cc | 5 +- test/cctest/cctest.h | 4 ++ test/cctest/test-api.cc | 45 ++++-------- test/cctest/test-debug.cc | 10 +-- test/cctest/test-heap.cc | 54 +++++++-------- test/cctest/test-object-observe.cc | 12 +++- 10 files changed, 129 insertions(+), 151 deletions(-) diff --git a/include/v8.h b/include/v8.h index 79f4478ea..b38627573 100644 --- a/include/v8.h +++ b/include/v8.h @@ -4018,9 +4018,22 @@ class V8_EXPORT Isolate { */ CpuProfiler* GetCpuProfiler(); + /** Returns true if this isolate has a current context. */ + bool InContext(); + /** Returns the context that is on the top of the stack. */ Local GetCurrentContext(); + /** + * Returns the context of the calling JavaScript code. That is the + * context of the top-most JavaScript frame. If there are no + * JavaScript frames an empty handle is returned. + */ + Local GetCallingContext(); + + /** Returns the last entered context. */ + Local GetEnteredContext(); + /** * Allows the host application to group objects together. If one * object in the group is alive, all objects in the group are alive. @@ -4923,24 +4936,16 @@ class V8_EXPORT Context { Handle global_template = Handle(), Handle global_object = Handle()); - /** Deprecated. Use Isolate version instead. */ - V8_DEPRECATED(static Persistent New( - ExtensionConfiguration* extensions = NULL, - Handle global_template = Handle(), - Handle global_object = Handle())); - - /** Returns the last entered context. */ + // TODO(dcarney): Remove this function. + /** Deprecated. Use Isolate::GetEnteredContext */ static Local GetEntered(); - // TODO(svenpanne) Actually deprecate this. + // TODO(dcarney) Remove this function. /** Deprecated. Use Isolate::GetCurrentContext instead. */ static Local GetCurrent(); - /** - * Returns the context of the calling JavaScript code. That is the - * context of the top-most JavaScript frame. If there are no - * JavaScript frames an empty handle is returned. - */ + // TODO(dcarney) Remove this function. + /** Deprecated. Use Isolate::GetCallingContext instead. */ static Local GetCalling(); /** @@ -4972,7 +4977,8 @@ class V8_EXPORT Context { /** Returns true if the context has experienced an out of memory situation. */ bool HasOutOfMemoryException(); - /** Returns true if V8 has a current context. */ + // TODO(dcarney) Remove this function. + /** Deprecated. Use Isolate::InContext instead. */ static bool InContext(); /** Returns an isolate associated with a current context. */ diff --git a/samples/lineprocessor.cc b/samples/lineprocessor.cc index 42048202f..b4ffb44e8 100644 --- a/samples/lineprocessor.cc +++ b/samples/lineprocessor.cc @@ -259,7 +259,7 @@ int RunMain(int argc, char* argv[]) { if (cycle_type == CycleInCpp) { bool res = RunCppCycle(script, - v8::Context::GetCurrent(), + isolate->GetCurrentContext(), report_exceptions); return !res; } else { @@ -306,7 +306,7 @@ bool RunCppCycle(v8::Handle script, v8::Handle result; { v8::TryCatch try_catch; - result = process_fun->Call(v8::Context::GetCurrent()->Global(), + result = process_fun->Call(isolate->GetCurrentContext()->Global(), argc, argv); if (try_catch.HasCaught()) { if (report_exceptions) diff --git a/src/api.cc b/src/api.cc index 415bd41bb..9756874f6 100644 --- a/src/api.cc +++ b/src/api.cc @@ -750,29 +750,22 @@ i::Object** HandleScope::CreateHandle(i::HeapObject* value) { void Context::Enter() { i::Handle env = Utils::OpenHandle(this); i::Isolate* isolate = env->GetIsolate(); - if (IsDeadCheck(isolate, "v8::Context::Enter()")) return; ENTER_V8(isolate); - isolate->handle_scope_implementer()->EnterContext(env); - isolate->handle_scope_implementer()->SaveContext(isolate->context()); isolate->set_context(*env); } void Context::Exit() { - // Exit is essentially a static function and doesn't use the - // receiver, so we have to get the current isolate from the thread - // local. - i::Isolate* isolate = i::Isolate::Current(); - if (!isolate->IsInitialized()) return; - - if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(), + i::Handle context = Utils::OpenHandle(this); + i::Isolate* isolate = context->GetIsolate(); + ENTER_V8(isolate); + if (!ApiCheck(isolate->handle_scope_implementer()->LeaveContext(context), "v8::Context::Exit()", "Cannot exit non-entered context")) { return; } - // Content of 'last_context' could be NULL. i::Context* last_context = isolate->handle_scope_implementer()->RestoreContext(); @@ -5494,11 +5487,7 @@ v8::Local Context::GetEntered() { if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) { return Local(); } - i::Handle last = - isolate->handle_scope_implementer()->LastEnteredContext(); - if (last.is_null()) return Local(); - i::Handle context = i::Handle::cast(last); - return Utils::ToLocal(context); + return reinterpret_cast(isolate)->GetEnteredContext(); } @@ -5516,45 +5505,30 @@ v8::Local Context::GetCalling() { if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) { return Local(); } - i::Handle calling = - isolate->GetCallingNativeContext(); - if (calling.is_null()) return Local(); - i::Handle context = i::Handle::cast(calling); - return Utils::ToLocal(context); + return reinterpret_cast(isolate)->GetCallingContext(); } v8::Local Context::Global() { - i::Isolate* isolate = i::Isolate::Current(); - if (IsDeadCheck(isolate, "v8::Context::Global()")) { - return Local(); - } - i::Object** ctx = reinterpret_cast(this); - i::Handle context = - i::Handle::cast(i::Handle(ctx)); + i::Handle context = Utils::OpenHandle(this); + i::Isolate* isolate = context->GetIsolate(); i::Handle global(context->global_proxy(), isolate); return Utils::ToLocal(i::Handle::cast(global)); } void Context::DetachGlobal() { - i::Isolate* isolate = i::Isolate::Current(); - if (IsDeadCheck(isolate, "v8::Context::DetachGlobal()")) return; + i::Handle context = Utils::OpenHandle(this); + i::Isolate* isolate = context->GetIsolate(); ENTER_V8(isolate); - i::Object** ctx = reinterpret_cast(this); - i::Handle context = - i::Handle::cast(i::Handle(ctx)); isolate->bootstrapper()->DetachGlobal(context); } void Context::ReattachGlobal(Handle global_object) { - i::Isolate* isolate = i::Isolate::Current(); - if (IsDeadCheck(isolate, "v8::Context::ReattachGlobal()")) return; + i::Handle context = Utils::OpenHandle(this); + i::Isolate* isolate = context->GetIsolate(); ENTER_V8(isolate); - i::Object** ctx = reinterpret_cast(this); - i::Handle context = - i::Handle::cast(i::Handle(ctx)); i::Handle global_proxy = i::Handle::cast(Utils::OpenHandle(*global_object)); isolate->bootstrapper()->ReattachGlobal(context, global_proxy); @@ -5562,44 +5536,23 @@ void Context::ReattachGlobal(Handle global_object) { void Context::AllowCodeGenerationFromStrings(bool allow) { - i::Isolate* isolate = i::Isolate::Current(); - if (IsDeadCheck(isolate, "v8::Context::AllowCodeGenerationFromStrings()")) { - return; - } + i::Handle context = Utils::OpenHandle(this); + i::Isolate* isolate = context->GetIsolate(); ENTER_V8(isolate); - i::Object** ctx = reinterpret_cast(this); - i::Handle context = - i::Handle::cast(i::Handle(ctx)); context->set_allow_code_gen_from_strings( allow ? isolate->heap()->true_value() : isolate->heap()->false_value()); } bool Context::IsCodeGenerationFromStringsAllowed() { - i::Isolate* isolate = i::Isolate::Current(); - if (IsDeadCheck(isolate, - "v8::Context::IsCodeGenerationFromStringsAllowed()")) { - return false; - } - ENTER_V8(isolate); - i::Object** ctx = reinterpret_cast(this); - i::Handle context = - i::Handle::cast(i::Handle(ctx)); + i::Handle context = Utils::OpenHandle(this); return !context->allow_code_gen_from_strings()->IsFalse(); } void Context::SetErrorMessageForCodeGenerationFromStrings( Handle error) { - i::Isolate* isolate = i::Isolate::Current(); - if (IsDeadCheck(isolate, - "v8::Context::SetErrorMessageForCodeGenerationFromStrings()")) { - return; - } - ENTER_V8(isolate); - i::Object** ctx = reinterpret_cast(this); - i::Handle context = - i::Handle::cast(i::Handle(ctx)); + i::Handle context = Utils::OpenHandle(this); i::Handle error_handle = Utils::OpenHandle(*error); context->set_error_message_for_code_gen_from_strings(*error_handle); } @@ -6647,9 +6600,15 @@ CpuProfiler* Isolate::GetCpuProfiler() { } +bool Isolate::InContext() { + i::Isolate* isolate = reinterpret_cast(this); + return isolate->context() != NULL; +} + + v8::Local Isolate::GetCurrentContext() { - i::Isolate* internal_isolate = reinterpret_cast(this); - i::Context* context = internal_isolate->context(); + i::Isolate* isolate = reinterpret_cast(this); + i::Context* context = isolate->context(); if (context == NULL) return Local(); i::Context* native_context = context->global_object()->native_context(); if (native_context == NULL) return Local(); @@ -6657,6 +6616,23 @@ v8::Local Isolate::GetCurrentContext() { } +v8::Local Isolate::GetCallingContext() { + i::Isolate* isolate = reinterpret_cast(this); + i::Handle calling = isolate->GetCallingNativeContext(); + if (calling.is_null()) return Local(); + return Utils::ToLocal(i::Handle::cast(calling)); +} + + +v8::Local Isolate::GetEnteredContext() { + i::Isolate* isolate = reinterpret_cast(this); + i::Handle last = + isolate->handle_scope_implementer()->LastEnteredContext(); + if (last.is_null()) return Local(); + return Utils::ToLocal(i::Handle::cast(last)); +} + + void Isolate::SetObjectGroupId(const Persistent& object, UniqueId id) { i::Isolate* internal_isolate = reinterpret_cast(this); diff --git a/src/api.h b/src/api.h index 51bc4942b..7dfa36d1c 100644 --- a/src/api.h +++ b/src/api.h @@ -543,7 +543,7 @@ class HandleScopeImplementer { inline bool CallDepthIsZero() { return call_depth_ == 0; } inline void EnterContext(Handle context); - inline bool LeaveLastContext(); + inline bool LeaveContext(Handle context); // Returns the last entered context or an empty handle if no // contexts have been entered. @@ -635,8 +635,10 @@ void HandleScopeImplementer::EnterContext(Handle context) { } -bool HandleScopeImplementer::LeaveLastContext() { +bool HandleScopeImplementer::LeaveContext(Handle context) { if (entered_contexts_.is_empty()) return false; + // TODO(dcarney): figure out what's wrong here + // if (*entered_contexts_.last() != *context) return false; entered_contexts_.RemoveLast(); return true; } diff --git a/src/d8.cc b/src/d8.cc index 6e4e61d15..614b16ea8 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -263,7 +263,8 @@ PerIsolateData::RealmScope::RealmScope(PerIsolateData* data) : data_(data) { data_->realm_current_ = 0; data_->realm_switch_ = 0; data_->realms_ = new Persistent[1]; - data_->realms_[0].Reset(data_->isolate_, Context::GetEntered()); + data_->realms_[0].Reset(data_->isolate_, + data_->isolate_->GetEnteredContext()); data_->realm_shared_.Clear(); } @@ -290,7 +291,7 @@ int PerIsolateData::RealmFind(Handle context) { void Shell::RealmCurrent(const v8::FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); PerIsolateData* data = PerIsolateData::Get(isolate); - int index = data->RealmFind(Context::GetEntered()); + int index = data->RealmFind(isolate->GetEnteredContext()); if (index == -1) return; args.GetReturnValue().Set(index); } diff --git a/test/cctest/cctest.h b/test/cctest/cctest.h index b9c5d00fd..bc800399a 100644 --- a/test/cctest/cctest.h +++ b/test/cctest/cctest.h @@ -106,6 +106,10 @@ class CcTest { return i_isolate()->heap(); } + static v8::Local global() { + return isolate()->GetCurrentContext()->Global(); + } + // TODO(dcarney): Remove. // This must be called first in a test. static void InitializeVM() { diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 0f790f5a4..970995a02 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -4661,7 +4661,8 @@ void CThrowCountDown(const v8::FunctionCallbackInfo& args) { v8::ThrowException(v8_str("FromC")); return; } else { - Local global = Context::GetCurrent()->Global(); + Local global = + args.GetIsolate()->GetCurrentContext()->Global(); Local fun = global->Get(v8_str("JSThrowCountDown")); v8::Handle argv[] = { v8_num(count - 1), args[1], @@ -7078,7 +7079,8 @@ static void PGetter(Local name, const v8::PropertyCallbackInfo& info) { ApiTestFuzzer::Fuzz(); p_getter_count++; - v8::Handle global = Context::GetCurrent()->Global(); + v8::Handle global = + info.GetIsolate()->GetCurrentContext()->Global(); CHECK_EQ(info.Holder(), global->Get(v8_str("o1"))); if (name->Equals(v8_str("p1"))) { CHECK_EQ(info.This(), global->Get(v8_str("o1"))); @@ -7112,7 +7114,8 @@ static void PGetter2(Local name, const v8::PropertyCallbackInfo& info) { ApiTestFuzzer::Fuzz(); p_getter_count2++; - v8::Handle global = Context::GetCurrent()->Global(); + v8::Handle global = + info.GetIsolate()->GetCurrentContext()->Global(); CHECK_EQ(info.Holder(), global->Get(v8_str("o1"))); if (name->Equals(v8_str("p1"))) { CHECK_EQ(info.This(), global->Get(v8_str("o1"))); @@ -7218,7 +7221,7 @@ THREADED_TEST(StringWrite) { "for (var i = 0; i < 0xd800; i += 4) {" " right = String.fromCharCode(i) + right;" "}"); - v8::Handle global = Context::GetCurrent()->Global(); + v8::Handle global = context->Global(); Handle left_tree = global->Get(v8_str("left")).As(); Handle right_tree = global->Get(v8_str("right")).As(); @@ -7805,7 +7808,8 @@ static void TroubleCallback(const v8::FunctionCallbackInfo& args) { trouble_nesting++; // Call a JS function that throws an uncaught exception. - Local arg_this = Context::GetCurrent()->Global(); + Local arg_this = + args.GetIsolate()->GetCurrentContext()->Global(); Local trouble_callee = (trouble_nesting == 3) ? arg_this->Get(v8_str("trouble_callee")) : arg_this->Get(v8_str("trouble_caller")); @@ -8327,7 +8331,7 @@ static bool NamedAccessBlocker(Local global, Local name, v8::AccessType type, Local data) { - return Context::GetCurrent()->Global()->Equals(global) || + return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || allowed_access_type[type]; } @@ -8336,7 +8340,7 @@ static bool IndexedAccessBlocker(Local global, uint32_t key, v8::AccessType type, Local data) { - return Context::GetCurrent()->Global()->Equals(global) || + return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || allowed_access_type[type]; } @@ -13484,28 +13488,6 @@ THREADED_TEST(ExternalAllocatedMemory) { } -THREADED_TEST(DisposeEnteredContext) { - LocalContext outer; - v8::Isolate* isolate = outer->GetIsolate(); - v8::Persistent inner; - { - v8::HandleScope scope(isolate); - inner.Reset(isolate, v8::Context::New(isolate)); - } - v8::HandleScope scope(isolate); - { - // Don't want a handle here, so do this unsafely - v8::Handle inner_local = - v8::Utils::Convert( - v8::Utils::OpenPersistent(inner)); - inner_local->Enter(); - inner.Dispose(); - inner.Clear(); - inner_local->Exit(); - } -} - - // Regression test for issue 54, object templates with internal fields // but no accessors or interceptors did not get their internal field // count set on instances. @@ -15041,10 +15023,9 @@ static v8::Local calling_context2; static void GetCallingContextCallback( const v8::FunctionCallbackInfo& args) { ApiTestFuzzer::Fuzz(); - CHECK(Context::GetCurrent() == calling_context0); CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0); - CHECK(Context::GetCalling() == calling_context1); - CHECK(Context::GetEntered() == calling_context2); + CHECK(args.GetIsolate()->GetCallingContext() == calling_context1); + CHECK(args.GetIsolate()->GetEnteredContext() == calling_context2); args.GetReturnValue().Set(42); } diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc index 39210596b..8a3bfa414 100644 --- a/test/cctest/test-debug.cc +++ b/test/cctest/test-debug.cc @@ -200,8 +200,10 @@ static v8::Local CompileFunction(DebugLocalContext* env, static v8::Local CompileFunction(const char* source, const char* function_name) { v8::Script::Compile(v8::String::New(source))->Run(); + v8::Local global = + CcTest::isolate()->GetCurrentContext()->Global(); return v8::Local::Cast( - v8::Context::GetCurrent()->Global()->Get(v8::String::New(function_name))); + global->Get(v8::String::New(function_name))); } @@ -7007,10 +7009,10 @@ static void NamedGetterWithCallingContextCheck( v8::Local name, const v8::PropertyCallbackInfo& info) { CHECK_EQ(0, strcmp(*v8::String::Utf8Value(name), "a")); - v8::Handle current = v8::Context::GetCurrent(); + v8::Handle current = info.GetIsolate()->GetCurrentContext(); CHECK(current == debugee_context); CHECK(current != debugger_context); - v8::Handle calling = v8::Context::GetCalling(); + v8::Handle calling = info.GetIsolate()->GetCallingContext(); CHECK(calling == debugee_context); CHECK(calling != debugger_context); info.GetReturnValue().Set(1); @@ -7026,7 +7028,7 @@ static void DebugEventGetAtgumentPropertyValue( v8::Handle exec_state = event_details.GetExecutionState(); if (event == v8::Break) { break_point_hit_count++; - CHECK(debugger_context == v8::Context::GetCurrent()); + CHECK(debugger_context == CcTest::isolate()->GetCurrentContext()); v8::Handle func = v8::Handle::Cast(CompileRun( "(function(exec_state) {\n" " return (exec_state.frame(0).argumentValue(0).property('a').\n" diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 2824d5b24..f2971be57 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -1897,7 +1897,7 @@ TEST(InstanceOfStubWriteBarrier) { Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); CHECK(f->IsOptimized()); @@ -1912,7 +1912,7 @@ TEST(InstanceOfStubWriteBarrier) { { v8::HandleScope scope(CcTest::isolate()); - v8::Handle global = v8::Context::GetCurrent()->Global(); + v8::Handle global = CcTest::global(); v8::Handle g = v8::Handle::Cast(global->Get(v8_str("g"))); g->Call(global, 0, NULL); @@ -1942,7 +1942,7 @@ TEST(PrototypeTransitionClearing) { Handle baseObject = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("base")))); + CcTest::global()->Get(v8_str("base")))); // Verify that only dead prototype transitions are cleared. CHECK_EQ(10, baseObject->map()->NumberOfProtoTransitions()); @@ -2009,7 +2009,7 @@ TEST(ResetSharedFunctionInfoCountersDuringIncrementalMarking) { Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); CHECK(f->IsOptimized()); IncrementalMarking* marking = CcTest::heap()->incremental_marking(); @@ -2066,7 +2066,7 @@ TEST(ResetSharedFunctionInfoCountersDuringMarkSweep) { Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); CHECK(f->IsOptimized()); CcTest::heap()->incremental_marking()->Abort(); @@ -2475,7 +2475,7 @@ TEST(Regress1465) { Handle root = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); + CcTest::global()->Get(v8_str("root")))); // Count number of live transitions before marking. int transitions_before = CountMapTransitions(root->map()); @@ -2525,7 +2525,7 @@ TEST(Regress2143a) { Handle root = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); + CcTest::global()->Get(v8_str("root")))); // The root object should be in a sane state. CHECK(root->IsJSObject()); @@ -2569,7 +2569,7 @@ TEST(Regress2143b) { Handle root = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); + CcTest::global()->Get(v8_str("root")))); // The root object should be in a sane state. CHECK(root->IsJSObject()); @@ -2665,7 +2665,7 @@ TEST(PrintSharedFunctionInfo) { Handle g = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("g")))); + CcTest::global()->Get(v8_str("g")))); DisallowHeapAllocation no_allocation; g->shared()->PrintLn(); @@ -2728,13 +2728,13 @@ TEST(IncrementalMarkingClearsTypeFeedbackCells) { // Prepare function f that contains type feedback for closures // originating from two different native contexts. - v8::Context::GetCurrent()->Global()->Set(v8_str("fun1"), fun1); - v8::Context::GetCurrent()->Global()->Set(v8_str("fun2"), fun2); + CcTest::global()->Set(v8_str("fun1"), fun1); + CcTest::global()->Set(v8_str("fun2"), fun2); CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); Handle cells(TypeFeedbackInfo::cast( f->shared()->code()->type_feedback_info())->type_feedback_cells()); @@ -2779,7 +2779,7 @@ TEST(IncrementalMarkingPreservesMonomorhpicIC) { Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); CHECK(ic_before->ic_state() == MONOMORPHIC); @@ -2806,12 +2806,12 @@ TEST(IncrementalMarkingClearsMonomorhpicIC) { // Prepare function f that contains a monomorphic IC for object // originating from a different native context. - v8::Context::GetCurrent()->Global()->Set(v8_str("obj1"), obj1); + CcTest::global()->Set(v8_str("obj1"), obj1); CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); CHECK(ic_before->ic_state() == MONOMORPHIC); @@ -2846,13 +2846,13 @@ TEST(IncrementalMarkingClearsPolymorhpicIC) { // Prepare function f that contains a polymorphic IC for objects // originating from two different native contexts. - v8::Context::GetCurrent()->Global()->Set(v8_str("obj1"), obj1); - v8::Context::GetCurrent()->Global()->Set(v8_str("obj2"), obj2); + CcTest::global()->Set(v8_str("obj1"), obj1); + CcTest::global()->Set(v8_str("obj2"), obj2); CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); CHECK(ic_before->ic_state() == POLYMORPHIC); @@ -3057,14 +3057,14 @@ TEST(Regress159140) { Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); CHECK(f->is_compiled()); CompileRun("f = null;"); Handle g = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("g")))); + CcTest::global()->Get(v8_str("g")))); CHECK(g->is_compiled()); const int kAgingThreshold = 6; for (int i = 0; i < kAgingThreshold; i++) { @@ -3112,7 +3112,7 @@ TEST(Regress165495) { Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); CHECK(f->is_compiled()); const int kAgingThreshold = 6; for (int i = 0; i < kAgingThreshold; i++) { @@ -3160,7 +3160,7 @@ TEST(Regress169209) { Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); CHECK(f->is_compiled()); const int kAgingThreshold = 6; for (int i = 0; i < kAgingThreshold; i++) { @@ -3181,7 +3181,7 @@ TEST(Regress169209) { Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("flushMe")))); + CcTest::global()->Get(v8_str("flushMe")))); CHECK(f->is_compiled()); const int kAgingThreshold = 6; for (int i = 0; i < kAgingThreshold; i++) { @@ -3251,7 +3251,7 @@ TEST(Regress169928) { v8_str("fastliteralcase(mote, 2.5);"); v8::Local array_name = v8_str("mote"); - v8::Context::GetCurrent()->Global()->Set(array_name, v8::Int32::New(0)); + CcTest::global()->Set(array_name, v8::Int32::New(0)); // First make sure we flip spaces CcTest::heap()->CollectGarbage(NEW_SPACE); @@ -3285,7 +3285,7 @@ TEST(Regress169928) { // Give the array a name, making sure not to allocate strings. v8::Handle array_obj = v8::Utils::ToLocal(array); - v8::Context::GetCurrent()->Global()->Set(array_name, array_obj); + CcTest::global()->Set(array_name, array_obj); // This should crash with a protection violation if we are running a build // with the bug. @@ -3323,7 +3323,7 @@ TEST(Regress168801) { Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); CHECK(f->is_compiled()); const int kAgingThreshold = 6; for (int i = 0; i < kAgingThreshold; i++) { @@ -3379,7 +3379,7 @@ TEST(Regress173458) { Handle f = v8::Utils::OpenHandle( *v8::Handle::Cast( - v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); + CcTest::global()->Get(v8_str("f")))); CHECK(f->is_compiled()); const int kAgingThreshold = 6; for (int i = 0; i < kAgingThreshold; i++) { diff --git a/test/cctest/test-object-observe.cc b/test/cctest/test-object-observe.cc index 5e1104245..0c8e1cd18 100644 --- a/test/cctest/test-object-observe.cc +++ b/test/cctest/test-object-observe.cc @@ -472,7 +472,9 @@ static bool NamedAccessAllowUnlessBlocked(Local host, AccessType type, Local) { if (type != g_access_block_type) return true; - Handle global = Context::GetCurrent()->Global(); + v8::Isolate* isolate = reinterpret_cast( + Utils::OpenHandle(*host)->GetIsolate()); + Handle global = isolate->GetCurrentContext()->Global(); Handle blacklist = global->Get(String::New("blacklist")); if (!blacklist->IsObject()) return true; if (key->IsString()) return !blacklist.As()->Has(key); @@ -485,7 +487,9 @@ static bool IndexedAccessAllowUnlessBlocked(Local host, AccessType type, Local) { if (type != ACCESS_GET) return true; - Handle global = Context::GetCurrent()->Global(); + v8::Isolate* isolate = reinterpret_cast( + Utils::OpenHandle(*host)->GetIsolate()); + Handle global = isolate->GetCurrentContext()->Global(); Handle blacklist = global->Get(String::New("blacklist")); if (!blacklist->IsObject()) return true; return !blacklist.As()->Has(index); @@ -494,7 +498,9 @@ static bool IndexedAccessAllowUnlessBlocked(Local host, static bool BlockAccessKeys(Local host, Local key, AccessType type, Local) { - Handle global = Context::GetCurrent()->Global(); + v8::Isolate* isolate = reinterpret_cast( + Utils::OpenHandle(*host)->GetIsolate()); + Handle global = isolate->GetCurrentContext()->Global(); Handle blacklist = global->Get(String::New("blacklist")); if (!blacklist->IsObject()) return true; return type != ACCESS_KEYS || -- 2.34.1