Revision: 15266
Author: [email protected]
Date: Fri Jun 21 05:34:47 2013
Log: 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
[email protected],[email protected]
Review URL: https://codereview.chromium.org/16943006
Patch from Andrey Adaykin <[email protected]>.
http://code.google.com/p/v8/source/detail?r=15266
Modified:
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/test/cctest/test-api.cc
=======================================
--- /branches/bleeding_edge/src/api.cc Fri Jun 21 00:56:22 2013
+++ /branches/bleeding_edge/src/api.cc Fri Jun 21 05:34:47 2013
@@ -6559,10 +6559,11 @@
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));
}
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Fri Jun 21 00:56:22 2013
+++ /branches/bleeding_edge/test/cctest/test-api.cc Fri Jun 21 05:34:47 2013
@@ -14198,6 +14198,18 @@
CHECK(Context::GetEntered() == calling_context2);
args.GetReturnValue().Set(42);
}
+
+
+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-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.