From: Jiyun Yang Date: Tue, 7 Apr 2020 08:26:28 +0000 (+0900) Subject: Fix WebView.EvaluateJavaScript API crash X-Git-Tag: dali_1.5.7~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F29%2F230029%2F1;p=platform%2Fcore%2Fuifw%2Fdali-extension.git Fix WebView.EvaluateJavaScript API crash When result handler is null, it will no execute handler. Change-Id: Ieaae745ecf41b19708a789315ae75f238e0f9e66 Signed-off-by: Jiyun Yang --- diff --git a/dali-extension/web-engine-chromium/tizen-web-engine-chromium.cpp b/dali-extension/web-engine-chromium/tizen-web-engine-chromium.cpp index e281cb3..e3fa0d9 100644 --- a/dali-extension/web-engine-chromium/tizen-web-engine-chromium.cpp +++ b/dali-extension/web-engine-chromium/tizen-web-engine-chromium.cpp @@ -625,14 +625,22 @@ void TizenWebEngineChromium::EvaluateJavaScript( const std::string& script, std: { if( mWebViewContainer ) { - if( mJavaScriptEvaluationResultHandlers.emplace( mJavaScriptEvaluationCount, resultHandler ).second ) + bool badAlloc = false; + + try { - mWebViewContainer->EvaluateJavaScript( mJavaScriptEvaluationCount++, script ); + mJavaScriptEvaluationResultHandlers.emplace( mJavaScriptEvaluationCount, resultHandler ); } - else + catch( std::bad_alloc &e ) { + badAlloc = true; DALI_LOG_ERROR( "Too many ongoing JavaScript evaluations." ); } + + if( !badAlloc ) + { + mWebViewContainer->EvaluateJavaScript( mJavaScriptEvaluationCount++, script ); + } } } @@ -876,8 +884,11 @@ void TizenWebEngineChromium::RunJavaScriptEvaluationResultHandler( size_t key, c return; } - std::string stored( result ); - handler->second( stored ); + if( handler->second ) + { + std::string stored( result ); + handler->second( stored ); + } mJavaScriptEvaluationResultHandlers.erase( handler ); }