From ad16e9ea4937ca6daf1c9007619ba04c462d1a98 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 26 Jan 2015 18:47:23 -0800 Subject: [PATCH] Check for the existence of "ipc" object --- atom/renderer/atom_render_view_observer.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/atom/renderer/atom_render_view_observer.cc b/atom/renderer/atom_render_view_observer.cc index 046b029026..afaf20b08a 100644 --- a/atom/renderer/atom_render_view_observer.cc +++ b/atom/renderer/atom_render_view_observer.cc @@ -29,10 +29,15 @@ namespace atom { namespace { -v8::Handle GetIPCObject(v8::Isolate* isolate, - v8::Handle context) { +bool GetIPCObject(v8::Isolate* isolate, + v8::Handle context, + v8::Handle* ipc) { v8::Handle key = mate::StringToV8(isolate, "ipc"); - return context->Global()->GetHiddenValue(key)->ToObject(); + v8::Handle value = context->Global()->GetHiddenValue(key); + if (value.IsEmpty() || !value->IsObject()) + return false; + *ipc = value->ToObject(); + return true; } std::vector> ListValueToVector( @@ -118,8 +123,9 @@ void AtomRenderViewObserver::OnBrowserMessage(const base::string16& channel, isolate, args); arguments.insert(arguments.begin(), mate::ConvertToV8(isolate, channel)); - v8::Handle ipc = GetIPCObject(isolate, context); - node::MakeCallback(isolate, ipc, "emit", arguments.size(), &arguments[0]); + v8::Handle ipc; + if (GetIPCObject(isolate, context, &ipc)) + node::MakeCallback(isolate, ipc, "emit", arguments.size(), &arguments[0]); } } // namespace atom