diff options
Diffstat (limited to 'fpdfsdk/src/javascript/app.cpp')
-rw-r--r-- | fpdfsdk/src/javascript/app.cpp | 83 |
1 files changed, 36 insertions, 47 deletions
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp index bc18ae53a9..93a627c97a 100644 --- a/fpdfsdk/src/javascript/app.cpp +++ b/fpdfsdk/src/javascript/app.cpp @@ -18,12 +18,6 @@ #include "JS_Value.h" #include "resource.h" -static v8::Isolate* GetIsolate(IJS_Context* cc) { - CJS_Context* pContext = (CJS_Context*)cc; - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - return pRuntime->GetIsolate(); -} - BEGIN_JS_STATIC_CONST(CJS_TimerObj) END_JS_STATIC_CONST() @@ -119,7 +113,7 @@ FX_BOOL app::activeDocs(IJS_Context* cc, CPDFDoc_Environment* pApp = pContext->GetReaderApp(); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); - CJS_Array aDocs(pRuntime->GetIsolate()); + CJS_Array aDocs(pRuntime); if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { CJS_Document* pJSDocument = NULL; if (pDoc == pCurDoc) { @@ -134,7 +128,7 @@ FX_BOOL app::activeDocs(IJS_Context* cc, (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); ASSERT(pJSDocument != NULL); } - aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument)); + aDocs.SetElement(0, CJS_Value(pRuntime, pJSDocument)); } if (aDocs.GetLength() > 0) vp << aDocs; @@ -155,7 +149,7 @@ FX_BOOL app::calculate(IJS_Context* cc, CJS_Context* pContext = (CJS_Context*)cc; CPDFDoc_Environment* pApp = pContext->GetReaderApp(); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - CJS_Array aDocs(pRuntime->GetIsolate()); + CJS_Array aDocs(pRuntime); if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate); } else { @@ -266,7 +260,8 @@ FX_BOOL app::alert(IJS_Context* cc, int iIcon = 0; int iType = 0; - v8::Isolate* isolate = GetIsolate(cc); + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); + v8::Isolate* isolate = pRuntime->GetIsolate(); if (iSize == 1) { if (params[0].GetType() == CJS_Value::VT_object) { @@ -274,25 +269,25 @@ FX_BOOL app::alert(IJS_Context* cc, { v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg"); - swMsg = - CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToCFXWideString(); + swMsg = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown) + .ToCFXWideString(); pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle"); - swTitle = - CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToCFXWideString(); + swTitle = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown) + .ToCFXWideString(); pValue = FXJS_GetObjectElement(isolate, pObj, L"nIcon"); - iIcon = CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToInt(); + iIcon = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown).ToInt(); pValue = FXJS_GetObjectElement(isolate, pObj, L"nType"); - iType = CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToInt(); + iType = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown).ToInt(); } if (swMsg == L"") { - CJS_Array carray(isolate); + CJS_Array carray(pRuntime); if (params[0].ConvertToArray(carray)) { int iLength = carray.GetLength(); - CJS_Value* pValue = new CJS_Value(isolate); + CJS_Value* pValue = new CJS_Value(pRuntime); for (int i = 0; i < iLength; ++i) { carray.GetElement(i, *pValue); swMsg += (*pValue).ToCFXWideString(); @@ -340,15 +335,10 @@ FX_BOOL app::alert(IJS_Context* cc, } } - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); pRuntime->BeginBlock(); vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType, iIcon); pRuntime->EndBlock(); - return TRUE; } @@ -595,8 +585,8 @@ FX_BOOL app::mailMsg(IJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Context* pContext = (CJS_Context*)cc; - v8::Isolate* isolate = GetIsolate(cc); + if (params.size() < 1) + return FALSE; FX_BOOL bUI = TRUE; CFX_WideString cTo = L""; @@ -605,30 +595,33 @@ FX_BOOL app::mailMsg(IJS_Context* cc, CFX_WideString cSubject = L""; CFX_WideString cMsg = L""; - if (params.size() < 1) - return FALSE; + CJS_Context* pContext = static_cast<CJS_Context*>(cc); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + v8::Isolate* isolate = pRuntime->GetIsolate(); if (params[0].GetType() == CJS_Value::VT_object) { v8::Local<v8::Object> pObj = params[0].ToV8Object(); v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI"); - bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); + bUI = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo"); - cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + cTo = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc"); - cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + cCc = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc"); - cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + cBcc = + CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject"); cSubject = - CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg"); - cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + cMsg = + CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); } else { if (params.size() < 2) return FALSE; @@ -646,15 +639,10 @@ FX_BOOL app::mailMsg(IJS_Context* cc, cMsg = params[5].ToCFXWideString(); } - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); - - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - ASSERT(pApp != NULL); - pRuntime->BeginBlock(); - pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), - cBcc.c_str(), cMsg.c_str()); + pContext->GetReaderApp()->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), + cSubject.c_str(), cCc.c_str(), + cBcc.c_str(), cMsg.c_str()); pRuntime->EndBlock(); return FALSE; @@ -743,7 +731,8 @@ FX_BOOL app::response(IJS_Context* cc, CFX_WideString swDefault = L""; bool bPassWord = false; - v8::Isolate* isolate = GetIsolate(cc); + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); + v8::Isolate* isolate = pRuntime->GetIsolate(); int iLength = params.size(); if (iLength > 0 && params[0].GetType() == CJS_Value::VT_object) { @@ -751,22 +740,22 @@ FX_BOOL app::response(IJS_Context* cc, v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cQuestion"); swQuestion = - CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle"); swTitle = - CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = FXJS_GetObjectElement(isolate, pObj, L"cDefault"); swDefault = - CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = FXJS_GetObjectElement(isolate, pObj, L"cLabel"); swLabel = - CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = FXJS_GetObjectElement(isolate, pObj, L"bPassword"); - bPassWord = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); + bPassWord = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); } else { switch (iLength) { case 5: |