diff --git a/include/v8.h b/include/v8.h index 10b38fa574..8dabef0d58 100644 --- a/include/v8.h +++ b/include/v8.h @@ -3892,6 +3892,7 @@ class V8EXPORT Context { /** Returns the context that is on the top of the stack. */ static Local GetCurrent(); + static Local GetCurrent(Isolate* isolate); /** * Returns the context of the calling JavaScript code. That is the diff --git a/src/api.cc b/src/api.cc index 7354adaa01..48882ba8df 100644 --- a/src/api.cc +++ b/src/api.cc @@ -5014,6 +5014,16 @@ v8::Local Context::GetCurrent() { } +v8::Local Context::GetCurrent(Isolate* exported_isolate) { + i::Isolate* isolate = reinterpret_cast(exported_isolate); + ASSERT(isolate == i::Isolate::Current()); + i::Handle current = isolate->native_context(); + if (current.is_null()) return Local(); + i::Handle context = i::Handle::cast(current); + return Utils::ToLocal(context); +} + + v8::Local Context::GetCalling() { i::Isolate* isolate = i::Isolate::Current(); if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) { diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index a9780f0332..aa25b6265b 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -13410,6 +13410,7 @@ v8::Persistent calling_context2; static v8::Handle GetCallingContextCallback(const v8::Arguments& args) { ApiTestFuzzer::Fuzz(); CHECK(Context::GetCurrent() == calling_context0); + CHECK(Context::GetCurrent(args.GetIsolate()) == calling_context0); CHECK(Context::GetCalling() == calling_context1); CHECK(Context::GetEntered() == calling_context2); return v8::Integer::New(42);