Commit 7f175058 authored by yurys@chromium.org's avatar yurys@chromium.org

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
parent 04e12785
......@@ -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));
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment