V8 API: Add a missing NULL check into Isolate::GetCurrentContext().

There is a missing NULL check for: "internal_isolate->context() != NULL".
Right now before calling this method one should call v8::Context::InContext()
first to perform this check, otherwise we may crash. But this static method
will do this check on the current isolate, which may not be the same as a given one.

BUG=249655
R=yurys@chromium.org,mvstanton@chromium.org

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

Patch from Andrey Adaykin <aandrey@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15266 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yurys@chromium.org 2013-06-21 12:34:47 +00:00
parent 04e1278529
commit 7f1750580c
2 changed files with 17 additions and 4 deletions

View File

@ -6559,10 +6559,11 @@ CpuProfiler* Isolate::GetCpuProfiler() {
v8::Local<v8::Context> Isolate::GetCurrentContext() {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
i::Handle<i::Object> current = internal_isolate->native_context();
if (current.is_null()) return Local<Context>();
i::Handle<i::Context> context = i::Handle<i::Context>::cast(current);
return Utils::ToLocal(context);
i::Context* context = internal_isolate->context();
if (context == NULL) return Local<Context>();
i::Context* native_context = context->global_object()->native_context();
if (native_context == NULL) return Local<Context>();
return Utils::ToLocal(i::Handle<i::Context>(native_context));
}

View File

@ -14200,6 +14200,18 @@ static void GetCallingContextCallback(
}
THREADED_TEST(GetCurrentContextWhenNotInContext) {
i::Isolate* isolate = i::Isolate::Current();
CHECK(isolate != NULL);
CHECK(isolate->context() == NULL);
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
v8::HandleScope scope(v8_isolate);
// The following should not crash, but return an empty handle.
v8::Local<v8::Context> current = v8_isolate->GetCurrentContext();
CHECK(current.IsEmpty());
}
THREADED_TEST(GetCallingContext) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);