From 3cace320e07bb954710c50fc7634ca3a8f3eda38 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 9 Jun 2016 11:49:22 -0700 Subject: Change CFXJSE_Context::GetGlobalObject to return This Cl changes CFXJSE_Context::GetGlobalObject to return a std::unique_ptr instead of accepting a CFXJSE_Value out parameter. All usages created the CFXJSE_Value with the same runtime as the caller. Review-Url: https://codereview.chromium.org/2056733003 --- xfa/fxfa/parser/xfa_script_imp.cpp | 17 ++++------------- xfa/fxjse/context.cpp | 7 +++++-- xfa/fxjse/context.h | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/xfa/fxfa/parser/xfa_script_imp.cpp b/xfa/fxfa/parser/xfa_script_imp.cpp index 245ea8bca4..fe8400515f 100644 --- a/xfa/fxfa/parser/xfa_script_imp.cpp +++ b/xfa/fxfa/parser/xfa_script_imp.cpp @@ -502,10 +502,7 @@ FX_BOOL CXFA_ScriptContext::QueryVariableValue( FX_BOOL bRes = FALSE; CFXJSE_Context* pVariableContext = static_cast(lpVariables); - std::unique_ptr pObject( - new CFXJSE_Value(pVariableContext->GetRuntime())); - pVariableContext->GetGlobalObject(pObject.get()); - + std::unique_ptr pObject = pVariableContext->GetGlobalObject(); std::unique_ptr hVariableValue(new CFXJSE_Value(m_pIsolate)); if (!bGetter) { pObject->SetObjectOwnProperty(szPropName, pValue); @@ -529,11 +526,8 @@ void CXFA_ScriptContext::ReleaseVariablesMap() { CXFA_Object* pScriptNode; CFXJSE_Context* pVariableContext = nullptr; m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); - std::unique_ptr pObject( - new CFXJSE_Value(pVariableContext->GetRuntime())); - pVariableContext->GetGlobalObject(pObject.get()); - delete ToThisProxy(pObject.get(), nullptr); + delete ToThisProxy(pVariableContext->GetGlobalObject().get(), nullptr); delete pVariableContext; } m_mapVariableToContext.RemoveAll(); @@ -545,14 +539,11 @@ void CXFA_ScriptContext::DefineJsClass() { void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; - std::unique_ptr pObject( - new CFXJSE_Value(pContext->GetRuntime())); - pContext->GetGlobalObject(pObject.get()); - + std::unique_ptr pObject = pContext->GetGlobalObject(); std::unique_ptr hProp(new CFXJSE_Value(m_pIsolate)); for (int i = 0; i < 2; ++i) { if (pObject->GetObjectProperty(OBJ_NAME[i], hProp.get())) - pObject.get()->DeleteObjectProperty(OBJ_NAME[i]); + pObject->DeleteObjectProperty(OBJ_NAME[i]); } } CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() { diff --git a/xfa/fxjse/context.cpp b/xfa/fxjse/context.cpp index 8eacc77a74..e5d5f994d5 100644 --- a/xfa/fxjse/context.cpp +++ b/xfa/fxjse/context.cpp @@ -157,13 +157,16 @@ CFXJSE_Context::CFXJSE_Context(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {} CFXJSE_Context::~CFXJSE_Context() {} -void CFXJSE_Context::GetGlobalObject(CFXJSE_Value* pValue) { - ASSERT(pValue); +std::unique_ptr CFXJSE_Context::GetGlobalObject() { + std::unique_ptr pValue(new CFXJSE_Value(m_pIsolate)); + CFXJSE_ScopeUtil_IsolateHandleContext scope(this); v8::Local hContext = v8::Local::New(m_pIsolate, m_hContext); v8::Local hGlobalObject = hContext->Global(); pValue->ForceSetValue(hGlobalObject); + + return pValue; } void CFXJSE_Context::EnableCompatibleMode() { diff --git a/xfa/fxjse/context.h b/xfa/fxjse/context.h index 4219713ece..0bb1e4fa26 100644 --- a/xfa/fxjse/context.h +++ b/xfa/fxjse/context.h @@ -27,7 +27,7 @@ class CFXJSE_Context { ~CFXJSE_Context(); V8_INLINE v8::Isolate* GetRuntime(void) { return m_pIsolate; } - void GetGlobalObject(CFXJSE_Value* pValue); + std::unique_ptr GetGlobalObject(); void EnableCompatibleMode(); FX_BOOL ExecuteScript(const FX_CHAR* szScript, CFXJSE_Value* lpRetValue, -- cgit v1.2.3