From 434e28dd41e37dc829440aab1eb4cb4ec561962b Mon Sep 17 00:00:00 2001 From: Adam Klein Date: Mon, 22 Jan 2018 17:53:56 +0000 Subject: Use MaybeLocal versions of v8::Script APIs The non-Maybe versions will soon be deprecated. Where the code was already handling failures, I did the same; where the code was not handling failures, I inserted ToLocalChecked() calls. Thus the behavior before and after this patch should be the same. For consistency, also updated the use of v8::Function::Call in CFXJSE_Context::ExecuteScript() to the Maybe version, so that all code in that function now branches on the non-emptyness of MaybeLocals, rather than TryCatch::HasCaught(). ASSERTs were inserted to sanity-check the API usage. Bug: v8:7269, v8:7273, v8:7274 Change-Id: I59696e63a64a233a9f9c2b72c621a05b5e349a31 Reviewed-on: https://pdfium-review.googlesource.com/23270 Commit-Queue: Jochen Eisinger Reviewed-by: Jochen Eisinger --- fxjs/cfxjse_context.cpp | 34 +++++++++++++++++++++------------- fxjs/cfxjse_value.cpp | 9 +++++++-- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/fxjs/cfxjse_context.cpp b/fxjs/cfxjse_context.cpp index bf9bee8652..5c85cfd5b1 100644 --- a/fxjs/cfxjse_context.cpp +++ b/fxjs/cfxjse_context.cpp @@ -228,14 +228,17 @@ bool CFXJSE_Context::ExecuteScript(const char* szScript, CFXJSE_Value* lpRetValue, CFXJSE_Value* lpNewThisObject) { CFXJSE_ScopeUtil_IsolateHandleContext scope(this); + v8::Local hContext = m_pIsolate->GetCurrentContext(); v8::TryCatch trycatch(m_pIsolate); v8::Local hScriptString = v8::String::NewFromUtf8(m_pIsolate, szScript); if (!lpNewThisObject) { - v8::Local hScript = v8::Script::Compile(hScriptString); - if (!trycatch.HasCaught()) { - v8::Local hValue = hScript->Run(); - if (!trycatch.HasCaught()) { + v8::Local hScript; + if (v8::Script::Compile(hContext, hScriptString).ToLocal(&hScript)) { + ASSERT(!trycatch.HasCaught()); + v8::Local hValue; + if (hScript->Run(hContext).ToLocal(&hValue)) { + ASSERT(!trycatch.HasCaught()); if (lpRetValue) lpRetValue->m_hValue.Reset(m_pIsolate, hValue); return true; @@ -251,16 +254,21 @@ bool CFXJSE_Context::ExecuteScript(const char* szScript, v8::Local hNewThis = v8::Local::New(m_pIsolate, lpNewThisObject->m_hValue); ASSERT(!hNewThis.IsEmpty()); - v8::Local hWrapper = v8::Script::Compile(v8::String::NewFromUtf8( - m_pIsolate, "(function () { return eval(arguments[0]); })")); - v8::Local hWrapperValue = hWrapper->Run(); - ASSERT(hWrapperValue->IsFunction()); - v8::Local hWrapperFn = hWrapperValue.As(); - if (!trycatch.HasCaught()) { + v8::Local hWrapper = + v8::Script::Compile( + hContext, + v8::String::NewFromUtf8( + m_pIsolate, "(function () { return eval(arguments[0]); })")) + .ToLocalChecked(); + v8::Local hWrapperValue; + if (hWrapper->Run(hContext).ToLocal(&hWrapperValue)) { + ASSERT(!trycatch.HasCaught()); + v8::Local hWrapperFn = hWrapperValue.As(); v8::Local rgArgs[] = {hScriptString}; - v8::Local hValue = - hWrapperFn->Call(hNewThis.As(), 1, rgArgs); - if (!trycatch.HasCaught()) { + v8::Local hValue; + if (hWrapperFn->Call(hContext, hNewThis.As(), 1, rgArgs) + .ToLocal(&hValue)) { + ASSERT(!trycatch.HasCaught()); if (lpRetValue) lpRetValue->m_hValue.Reset(m_pIsolate, hValue); return true; diff --git a/fxjs/cfxjse_value.cpp b/fxjs/cfxjse_value.cpp index d07b3565d3..c1dd7b0027 100644 --- a/fxjs/cfxjse_value.cpp +++ b/fxjs/cfxjse_value.cpp @@ -250,10 +250,15 @@ bool CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction, v8::String::NewFromUtf8(m_pIsolate, "(function (oldfunction, newthis) { return " "oldfunction.bind(newthis); })"); + v8::Local hContext = m_pIsolate->GetCurrentContext(); v8::Local hBinderFunc = - v8::Script::Compile(hBinderFuncSource)->Run().As(); + v8::Script::Compile(hContext, hBinderFuncSource) + .ToLocalChecked() + ->Run(hContext) + .ToLocalChecked() + .As(); v8::Local hBoundFunction = - hBinderFunc->Call(m_pIsolate->GetCurrentContext()->Global(), 2, rgArgs); + hBinderFunc->Call(hContext->Global(), 2, rgArgs); if (hBoundFunction.IsEmpty() || !hBoundFunction->IsFunction()) return false; -- cgit v1.2.3