Permalink
Browse files

ScriptCore::UIT_Evaluate(): ensure that SetEvent() is called before m…

…ethod returns
  • Loading branch information...
1 parent a487074 commit 052faf21a59ffe5d6a815e5dc944a15875b68c28 @ataranto ataranto committed May 15, 2012
Showing with 39 additions and 37 deletions.
  1. +37 −36 CefSharp/ScriptCore.cpp
  2. +2 −1 CefSharp/ScriptCore.h
@@ -5,12 +5,12 @@
namespace CefSharp
{
- bool TryGetMainFrame(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>& mainFrame)
+ bool ScriptCore::TryGetMainFrame(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>& frame)
{
if (browser != nullptr)
{
- mainFrame = browser->GetMainFrame();
- return mainFrame != nullptr;
+ frame = browser->GetMainFrame();
+ return frame != nullptr;
}
else
{
@@ -30,47 +30,48 @@ namespace CefSharp
void ScriptCore::UIT_Evaluate(CefRefPtr<CefBrowser> browser, CefString script)
{
CefRefPtr<CefFrame> mainFrame;
- if (!TryGetMainFrame(browser, mainFrame))
+ if (TryGetMainFrame(browser, mainFrame))
{
- return;
- }
+ CefRefPtr<CefV8Context> context = mainFrame->GetV8Context();
- CefRefPtr<CefV8Context> context = mainFrame->GetV8Context();
-
- if (context.get() &&
- context->Enter())
- {
- CefRefPtr<CefV8Value> global = context->GetGlobal();
- CefRefPtr<CefV8Value> eval = global->GetValue("eval");
- CefRefPtr<CefV8Value> arg = CefV8Value::CreateString(script);
- CefRefPtr<CefV8Value> result;
- CefRefPtr<CefV8Exception> exception;
+ if (context.get() && context->Enter())
+ {
+ CefRefPtr<CefV8Value> global = context->GetGlobal();
+ CefRefPtr<CefV8Value> eval = global->GetValue("eval");
+ CefRefPtr<CefV8Value> arg = CefV8Value::CreateString(script);
+ CefRefPtr<CefV8Value> result;
+ CefRefPtr<CefV8Exception> exception;
- CefV8ValueList args;
- args.push_back(arg);
+ CefV8ValueList args;
+ args.push_back(arg);
- if (eval->ExecuteFunctionWithContext(context, global, args,
- result, exception, false))
- {
- if (exception)
+ if (eval->ExecuteFunctionWithContext(context, global, args,
+ result, exception, false))
{
- CefString message = exception->GetMessage();
- _exception = toClr(message);
- }
- else
- {
- try
+ if (exception)
{
- _result = convertFromCef(result);
+ CefString message = exception->GetMessage();
+ _exceptionMessage = toClr(message);
}
- catch (Exception^ ex)
+ else
{
- _exception = ex->Message;
+ try
+ {
+ _result = convertFromCef(result);
+ }
+ catch (Exception^ ex)
+ {
+ _exceptionMessage = ex->Message;
+ }
}
}
- }
- context->Exit();
+ context->Exit();
+ }
+ }
+ else
+ {
+ _exceptionMessage = "Failed to obtain reference to main frame";
}
SetEvent(_event);
@@ -93,7 +94,7 @@ namespace CefSharp
{
AutoLock lock_scope(this);
_result = nullptr;
- _exception = nullptr;
+ _exceptionMessage = nullptr;
if (CefCurrentlyOn(TID_UI))
{
@@ -114,9 +115,9 @@ namespace CefSharp
throw gcnew ScriptException("Script error");
}
- if (_exception)
+ if (_exceptionMessage)
{
- throw gcnew ScriptException(_exception);
+ throw gcnew ScriptException(_exceptionMessage);
}
else
{
@@ -9,8 +9,9 @@ namespace CefSharp
HANDLE _event;
gcroot<Object^> _result;
- gcroot<String^> _exception;
+ gcroot<String^> _exceptionMessage;
+ bool TryGetMainFrame(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>& frame);
void UIT_Execute(CefRefPtr<CefBrowser> browser, CefString script);
void UIT_Evaluate(CefRefPtr<CefBrowser> browser, CefString script);

0 comments on commit 052faf2

Please sign in to comment.