From 171b76a6c374547c1f088ed6aee2185bca145243 Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Tue, 7 Apr 2020 17:26:28 +0900 Subject: [PATCH] Fix WebView.EvaluateJavaScript API crash When result handler is null, it will no execute handler. Change-Id: Ieaae745ecf41b19708a789315ae75f238e0f9e66 Signed-off-by: Jiyun Yang --- .../tizen-web-engine-chromium.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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 ); } -- 2.7.4