diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-07-16 11:09:12 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-07-16 11:09:12 -0700 |
commit | fb07e2843dad0774d5842c2b08e7792164efc14a (patch) | |
tree | 4583acca1bdcf5b60fad79af0b9fa405f192c5d8 /fpdfsdk/src/javascript/app.cpp | |
parent | cc8b4d8763151f51c9fe71ce9b64b2a0d7ddcc88 (diff) | |
download | pdfium-fb07e2843dad0774d5842c2b08e7792164efc14a.tar.xz |
Tidy up CPDFDOC_Environment.
- untabify as encountered.
- Only put single-statement method in .h file, move more
complex methods to .cpp (counting an if without braces as
a single statement, killing braces as needed).
- Move invariant arguments to constructor and make
corresponding members const.
- Make all members private and add accessor methods.
- Make existing accessor methods const where possible.
- Kill meaningless asserts.
- Add helper functions in place of duplicate code.
- Rename GetCurrentDoc() to GetSDKDocument(), since the class
has two document members, one of CPDF_Document and one of
CPDFSDK_Document, making it clear which one you get.
- Simplify some logic with early returns.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1235393002 .
Diffstat (limited to 'fpdfsdk/src/javascript/app.cpp')
-rw-r--r-- | fpdfsdk/src/javascript/app.cpp | 104 |
1 files changed, 35 insertions, 69 deletions
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp index 31e313179e..af329655fd 100644 --- a/fpdfsdk/src/javascript/app.cpp +++ b/fpdfsdk/src/javascript/app.cpp @@ -119,10 +119,10 @@ END_JS_STATIC_METHOD() IMPLEMENT_JS_CLASS(CJS_App,app) -app::app(CJS_Object * pJSObject) : CJS_EmbedObj(pJSObject) , - m_bCalculate(true), - m_bRuntimeHighLight(false) -// m_pMenuHead(NULL) +app::app(CJS_Object * pJSObject) + : CJS_EmbedObj(pJSObject), + m_bCalculate(true), + m_bRuntimeHighLight(false) { } @@ -136,60 +136,37 @@ app::~app(void) FX_BOOL app::activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - if (vp.IsGetting()) - { - - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); - - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - ASSERT(pApp != NULL); - - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); - - CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); - - CJS_Array aDocs(pRuntime->GetIsolate()); -// int iNumDocs = pApp->CountDocuments(); - -// for(int iIndex = 0; iIndex<iNumDocs; iIndex++) -// { - CPDFSDK_Document* pDoc = pApp->GetCurrentDoc(); - if (pDoc) - { - CJS_Document * pJSDocument = NULL; - - if (pDoc == pCurDoc) - { - JSFXObject pObj = JS_GetThisObj(*pRuntime); - - if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document")) - { - pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); - } - } - else - { - JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document")); - pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); - ASSERT(pJSDocument != NULL); - - - // pDocument->AttachDoc(pDoc); - } + if (!vp.IsGetting()) + return FALSE; - aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument)); - } - // } + CJS_Context* pContext = (CJS_Context *)cc; + CPDFDoc_Environment* pApp = pContext->GetReaderApp(); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); + CJS_Array aDocs(pRuntime->GetIsolate()); + if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) + { + CJS_Document* pJSDocument = NULL; + if (pDoc == pCurDoc) + { + JSFXObject pObj = JS_GetThisObj(*pRuntime); + if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document")) + pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); + } + else + { + JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document")); + pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); + ASSERT(pJSDocument != NULL); + } + aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument)); + } + if (aDocs.GetLength() > 0) + vp << aDocs; + else + vp.SetNull(); - if (aDocs.GetLength() > 0) - vp << aDocs; - else - vp.SetNull(); - return TRUE; - } - return FALSE; + return TRUE; } FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) @@ -201,27 +178,16 @@ FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr m_bCalculate = (FX_BOOL)bVP; CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - ASSERT(pApp != NULL); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); - CJS_Array aDocs(pRuntime->GetIsolate()); - if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc()) - { - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm(); - ASSERT(pInterForm != NULL); - pInterForm->EnableCalculate((FX_BOOL)m_bCalculate); - } + if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) + pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate); } else { vp << (bool)m_bCalculate; } - return TRUE; } |