summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/javascript')
-rw-r--r--fpdfsdk/javascript/Annot.cpp3
-rw-r--r--fpdfsdk/javascript/Document.cpp117
-rw-r--r--fpdfsdk/javascript/PublicMethods.cpp129
-rw-r--r--fpdfsdk/javascript/app.cpp50
-rw-r--r--fpdfsdk/javascript/cjs_context.cpp6
-rw-r--r--fpdfsdk/javascript/global.cpp7
-rw-r--r--fpdfsdk/javascript/resource.cpp8
-rw-r--r--fpdfsdk/javascript/resource.h6
-rw-r--r--fpdfsdk/javascript/util.cpp23
9 files changed, 148 insertions, 201 deletions
diff --git a/fpdfsdk/javascript/Annot.cpp b/fpdfsdk/javascript/Annot.cpp
index d45aa6032a..ec77000449 100644
--- a/fpdfsdk/javascript/Annot.cpp
+++ b/fpdfsdk/javascript/Annot.cpp
@@ -91,8 +91,7 @@ FX_BOOL Annot::type(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
return FALSE;
}
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index d8e36227e5..cb79ab4589 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -163,8 +163,7 @@ FX_BOOL Document::numFields(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
return FALSE;
}
CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
@@ -278,13 +277,12 @@ FX_BOOL Document::getField(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-
if (params.size() < 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
CFX_WideString wideName = params[0].ToCFXWideString(pRuntime);
CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
@@ -310,19 +308,17 @@ FX_BOOL Document::getNthFieldName(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
int nIndex = params[0].ToInt(pRuntime);
if (nIndex < 0) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
return FALSE;
}
-
CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
CPDF_FormField* pField = pPDFForm->GetField(nIndex);
@@ -470,18 +466,16 @@ FX_BOOL Document::removeField(IJS_Context* cc,
CJS_Value& vRet,
CFX_WideString& sError) {
if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM)))
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) {
+ sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
return FALSE;
-
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-
+ }
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
-
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime);
CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
std::vector<CPDFSDK_Widget*> widgets;
@@ -586,21 +580,18 @@ FX_BOOL Document::submitForm(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
int nSize = params.size();
if (nSize < 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
-
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
CJS_Array aFields;
CFX_WideString strURL;
FX_BOOL bFDF = TRUE;
FX_BOOL bEmpty = FALSE;
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
CJS_Value v = params[0];
if (v.GetType() == CJS_Value::VT_string) {
strURL = params[0].ToCFXWideString(pRuntime);
@@ -746,8 +737,7 @@ FX_BOOL Document::info(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
return FALSE;
}
@@ -889,8 +879,7 @@ FX_BOOL Document::numPages(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
return FALSE;
}
vp << m_pDocument->GetPageCount();
@@ -900,7 +889,7 @@ FX_BOOL Document::numPages(IJS_Context* cc,
FX_BOOL Document::external(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
- // In Chrome case,should always return true.
+ // In Chrome case, should always return true.
if (vp.IsGetting()) {
vp << true;
}
@@ -911,8 +900,7 @@ FX_BOOL Document::filesize(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
return FALSE;
}
vp << 0;
@@ -935,8 +923,7 @@ FX_BOOL Document::URL(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
return FALSE;
}
vp << m_pDocument->GetPath();
@@ -977,8 +964,7 @@ FX_BOOL Document::documentFileName(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
return FALSE;
}
CFX_WideString wsFilePath = m_pDocument->GetPath();
@@ -999,8 +985,7 @@ FX_BOOL Document::path(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
if (vp.IsSetting()) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
return FALSE;
}
vp << app::SysPathToPDFPath(m_pDocument->GetPath());
@@ -1044,16 +1029,14 @@ FX_BOOL Document::getAnnot(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
if (params.size() != 2) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
-
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
int nPageNo = params[0].ToInt(pRuntime);
CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime);
-
CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(nPageNo);
if (!pPageView)
return FALSE;
@@ -1178,31 +1161,30 @@ FX_BOOL Document::addIcon(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
if (params.size() != 2) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime);
if (params[1].GetType() != CJS_Value::VT_object) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR);
return FALSE;
}
v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime);
if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR);
return FALSE;
}
CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject();
if (!pEmbedObj) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR);
return FALSE;
}
@@ -1214,9 +1196,8 @@ FX_BOOL Document::addIcon(IJS_Context* cc,
FX_BOOL Document::icons(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
if (vp.IsSetting()) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+ sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
return FALSE;
}
@@ -1257,17 +1238,15 @@ FX_BOOL Document::getIcon(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
if (m_IconList.empty())
return FALSE;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime);
for (const auto& pIconElement : m_IconList) {
@@ -1344,15 +1323,12 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-
// TODO(tsepez): check maximum allowable params.
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) {
+ sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
return FALSE;
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
+ }
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0;
int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0;
bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true;
@@ -1362,7 +1338,7 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc,
return FALSE;
if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
return FALSE;
}
@@ -1410,17 +1386,15 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) {
+ sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION);
return FALSE;
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
+ }
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0;
CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
return FALSE;
}
@@ -1594,17 +1568,14 @@ FX_BOOL Document::gotoNamedDest(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* context = (CJS_Context*)cc;
-
if (params.size() != 1) {
- sError = JSGetStringFromID(context, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
- CJS_Runtime* pRuntime = context->GetJSRuntime();
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CFX_WideString wideName = params[0].ToCFXWideString(pRuntime);
CFX_ByteString utf8Name = wideName.UTF8Encode();
-
CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
if (!pDocument)
return FALSE;
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index 1dfac93ac4..749c8d7cc9 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -728,13 +728,13 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
CJS_Value& vRet,
CFX_WideString& sError) {
#if _FX_OS_ != _FX_ANDROID_
- CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 6) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (!pEvent->m_pValue)
return FALSE;
@@ -898,7 +898,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (params.size() < 2)
@@ -919,7 +919,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(
swTemp.Replace(L",", L".");
if (!IsNumber(swTemp.c_str())) {
pEvent->Rc() = FALSE;
- sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+ sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
AlertIfPossible(pContext, sError.c_str());
}
return TRUE; // it happens after the last keystroke and before validating,
@@ -1001,12 +1001,12 @@ FX_BOOL CJS_PublicMethods::AFPercent_Format(
CJS_Value& vRet,
CFX_WideString& sError) {
#if _FX_OS_ != _FX_ANDROID_
- CJS_Context* pContext = (CJS_Context*)cc;
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (params.size() != 2) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
if (!pEvent->m_pValue)
@@ -1101,12 +1101,12 @@ FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
if (!pEvent->m_pValue)
@@ -1130,7 +1130,7 @@ FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc,
if (JS_PortIsNan(dDate)) {
CFX_WideString swMsg;
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(),
+ swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(),
sFormat.c_str());
AlertIfPossible(pContext, swMsg.c_str());
return FALSE;
@@ -1223,7 +1223,7 @@ FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(
double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat);
if (bWrongFormat || JS_PortIsNan(dRet)) {
CFX_WideString swMsg;
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(),
+ swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(),
sFormat.c_str());
AlertIfPossible(pContext, swMsg.c_str());
pEvent->Rc() = FALSE;
@@ -1237,9 +1237,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1275,9 +1274,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Keystroke(
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1312,9 +1310,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1337,9 +1334,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Keystroke(
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1378,12 +1374,12 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Format(
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (!pEvent->m_pValue)
return FALSE;
@@ -1424,14 +1420,14 @@ FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(
CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (params.size() < 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
if (!pEvent->m_pValue)
return FALSE;
- CFX_WideString& valEvent = pEvent->Value();
+ CFX_WideString& valEvent = pEvent->Value();
CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime);
if (wstrMask.IsEmpty())
return TRUE;
@@ -1449,8 +1445,7 @@ FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(
if (iIndexMask != wstrMask.GetLength() ||
(iIndexMask != valEvent.GetLength() && wstrMask.GetLength() != 0)) {
AlertIfPossible(
- pContext,
- JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str());
+ pContext, JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str());
pEvent->Rc() = FALSE;
}
return TRUE;
@@ -1465,26 +1460,23 @@ FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(
FX_STRSIZE combined_len = valEvent.GetLength() + wChange.GetLength() +
pEvent->SelStart() - pEvent->SelEnd();
if (combined_len > wstrMask.GetLength()) {
- AlertIfPossible(
- pContext,
- JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
+ AlertIfPossible(pContext,
+ JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str());
pEvent->Rc() = FALSE;
return TRUE;
}
if (iIndexMask >= wstrMask.GetLength() && !wChange.IsEmpty()) {
- AlertIfPossible(
- pContext,
- JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
+ AlertIfPossible(pContext,
+ JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str());
pEvent->Rc() = FALSE;
return TRUE;
}
for (FX_STRSIZE i = 0; i < wChange.GetLength(); ++i) {
if (iIndexMask >= wstrMask.GetLength()) {
- AlertIfPossible(
- pContext,
- JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
+ AlertIfPossible(pContext,
+ JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str());
pEvent->Rc() = FALSE;
return TRUE;
}
@@ -1508,12 +1500,12 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (!pEvent->m_pValue)
return FALSE;
@@ -1547,15 +1539,15 @@ FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
-
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
+
CFX_WideString swValue;
if (pEventHandler->m_pValue)
swValue = pEventHandler->Value();
@@ -1588,14 +1580,12 @@ FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
-
if (params.size() != 2) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CFX_WideString sValue = params[0].ToCFXWideString(pRuntime);
CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime);
@@ -1603,7 +1593,7 @@ FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc,
if (JS_PortIsNan(dDate)) {
CFX_WideString swMsg;
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(),
+ swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(),
sFormat.c_str());
AlertIfPossible((CJS_Context*)cc, swMsg.c_str());
return FALSE;
@@ -1617,14 +1607,12 @@ FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
-
if (params.size() != 3) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
vRet = CJS_Value(pRuntime, static_cast<double>(AF_Simple(
params[0].ToCFXWideString(pRuntime).c_str(),
params[1].ToDouble(pRuntime),
@@ -1637,14 +1625,12 @@ FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
-
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CFX_WideString ws = params[0].ToCFXWideString(pRuntime);
ws.Replace(L",", L".");
vRet = CJS_Value(pRuntime, ws.c_str());
@@ -1659,20 +1645,19 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate(
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
-
if (params.size() != 2) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
CJS_Value params1 = params[1];
if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
@@ -1760,19 +1745,19 @@ FX_BOOL CJS_PublicMethods::AFRange_Validate(
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
-
if (params.size() != 4) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
-
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (!pEvent->m_pValue)
return FALSE;
+
if (pEvent->Value().IsEmpty())
return TRUE;
+
double dEentValue =
atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str());
FX_BOOL bGreaterThan = params[0].ToBool(pRuntime);
@@ -1783,16 +1768,16 @@ FX_BOOL CJS_PublicMethods::AFRange_Validate(
if (bGreaterThan && bLessThan) {
if (dEentValue < dGreaterThan || dEentValue > dLessThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(),
+ swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE1).c_str(),
params[1].ToCFXWideString(pRuntime).c_str(),
params[3].ToCFXWideString(pRuntime).c_str());
} else if (bGreaterThan) {
if (dEentValue < dGreaterThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(),
+ swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE2).c_str(),
params[1].ToCFXWideString(pRuntime).c_str());
} else if (bLessThan) {
if (dEentValue > dLessThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(),
+ swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE3).c_str(),
params[3].ToCFXWideString(pRuntime).c_str());
}
@@ -1807,17 +1792,15 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
-
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
- CJS_Array nums;
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CFX_WideString str = params[0].ToCFXWideString(pRuntime);
CFX_WideString sPart;
+ CJS_Array nums;
if (str.GetAt(0) == L'.' || str.GetAt(0) == L',')
str = L"0" + str;
diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp
index 89e8b563da..d7086d211e 100644
--- a/fpdfsdk/javascript/app.cpp
+++ b/fpdfsdk/javascript/app.cpp
@@ -382,13 +382,12 @@ FX_BOOL app::alert(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
std::vector<CJS_Value> newParams = JS_ExpandKeywordParams(
pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
if (newParams[0].GetType() == CJS_Value::VT_unknown) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -430,7 +429,7 @@ FX_BOOL app::alert(IJS_Context* cc,
if (newParams[3].GetType() != CJS_Value::VT_unknown)
swTitle = newParams[3].ToCFXWideString(pRuntime);
else
- swTitle = JSGetStringFromID(pContext, IDS_STRING_JSALERT);
+ swTitle = JSGetStringFromID(IDS_STRING_JSALERT);
pRuntime->BeginBlock();
if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
@@ -447,14 +446,13 @@ FX_BOOL app::beep(IJS_Context* cc,
CJS_Value& vRet,
CFX_WideString& sError) {
if (params.size() == 1) {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
pEnv->JS_appBeep(params[0].ToInt(pRuntime));
return TRUE;
}
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -480,18 +478,16 @@ FX_BOOL app::setInterval(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
-
if (params.size() > 2 || params.size() == 0) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CFX_WideString script =
params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L"";
if (script.IsEmpty()) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+ sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
return TRUE;
}
@@ -517,17 +513,15 @@ FX_BOOL app::setTimeOut(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
if (params.size() > 2 || params.size() == 0) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CFX_WideString script = params[0].ToCFXWideString(pRuntime);
if (script.IsEmpty()) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+ sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
return TRUE;
}
@@ -555,13 +549,12 @@ FX_BOOL app::clearTimeOut(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
- app::ClearTimerCommon(pContext->GetJSRuntime(), params[0]);
+ app::ClearTimerCommon(CJS_Runtime::FromContext(cc), params[0]);
return TRUE;
}
@@ -569,13 +562,12 @@ FX_BOOL app::clearInterval(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
- app::ClearTimerCommon(pContext->GetJSRuntime(), params[0]);
+ app::ClearTimerCommon(CJS_Runtime::FromContext(cc), params[0]);
return TRUE;
}
@@ -645,14 +637,13 @@ FX_BOOL app::mailMsg(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
std::vector<CJS_Value> newParams =
JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc",
L"cBcc", L"cSubject", L"cMsg");
if (newParams[0].GetType() == CJS_Value::VT_unknown) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
bool bUI = newParams[0].ToBool(pRuntime);
@@ -663,7 +654,7 @@ FX_BOOL app::mailMsg(IJS_Context* cc,
} else {
if (!bUI) {
// cTo parameter required when UI not invoked.
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
}
@@ -685,6 +676,7 @@ FX_BOOL app::mailMsg(IJS_Context* cc,
cMsg = newParams[5].ToCFXWideString(pRuntime);
pRuntime->BeginBlock();
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
pContext->GetReaderApp()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
cSubject.c_str(), cCc.c_str(),
cBcc.c_str(), cMsg.c_str());
@@ -768,14 +760,13 @@ FX_BOOL app::response(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
std::vector<CJS_Value> newParams =
JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
L"cDefault", L"bPassword", L"cLabel");
if (newParams[0].GetType() == CJS_Value::VT_unknown) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
CFX_WideString swQuestion = newParams[0].ToCFXWideString(pRuntime);
@@ -800,12 +791,13 @@ FX_BOOL app::response(IJS_Context* cc,
std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
int nLengthBytes = pContext->GetReaderApp()->JS_appResponse(
swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
bPassword, pBuff.get(), MAX_INPUT_BYTES);
if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG);
return FALSE;
}
diff --git a/fpdfsdk/javascript/cjs_context.cpp b/fpdfsdk/javascript/cjs_context.cpp
index c37fdab738..87b8b43975 100644
--- a/fpdfsdk/javascript/cjs_context.cpp
+++ b/fpdfsdk/javascript/cjs_context.cpp
@@ -33,7 +33,7 @@ FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
v8::Context::Scope context_scope(context);
if (m_bBusy) {
- *info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
+ *info = JSGetStringFromID(IDS_STRING_JSBUSY);
return FALSE;
}
m_bBusy = TRUE;
@@ -42,7 +42,7 @@ FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
CJS_Runtime::FieldEvent event(m_pEventHandler->TargetName(),
m_pEventHandler->EventType());
if (!m_pRuntime->AddEventToSet(event)) {
- *info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
+ *info = JSGetStringFromID(IDS_STRING_JSEVENT);
return FALSE;
}
@@ -55,7 +55,7 @@ FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
if (nRet < 0) {
*info += sErrorMessage;
} else {
- *info = JSGetStringFromID(this, IDS_STRING_RUN);
+ *info = JSGetStringFromID(IDS_STRING_RUN);
}
m_pRuntime->RemoveEventFromSet(event);
diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp
index 27c156e527..c0330f3a14 100644
--- a/fpdfsdk/javascript/global.cpp
+++ b/fpdfsdk/javascript/global.cpp
@@ -161,13 +161,12 @@ FX_BOOL JSGlobalAlternate::setPersistent(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
if (params.size() != 2) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
auto it = m_mapGlobal.find(params[0].ToCFXByteString(pRuntime));
if (it != m_mapGlobal.end()) {
JSGlobalData* pData = it->second;
@@ -177,7 +176,7 @@ FX_BOOL JSGlobalAlternate::setPersistent(IJS_Context* cc,
}
}
- sError = JSGetStringFromID(pContext, IDS_STRING_JSNOGLOBAL);
+ sError = JSGetStringFromID(IDS_STRING_JSNOGLOBAL);
return FALSE;
}
diff --git a/fpdfsdk/javascript/resource.cpp b/fpdfsdk/javascript/resource.cpp
index 88721efd2c..c4edeae905 100644
--- a/fpdfsdk/javascript/resource.cpp
+++ b/fpdfsdk/javascript/resource.cpp
@@ -6,7 +6,7 @@
#include "fpdfsdk/javascript/resource.h"
-CFX_WideString JSGetStringFromID(CJS_Context* pContext, FX_UINT id) {
+CFX_WideString JSGetStringFromID(FX_UINT id) {
switch (id) {
case IDS_STRING_JSALERT:
return L"Alert";
@@ -25,7 +25,7 @@ CFX_WideString JSGetStringFromID(CJS_Context* pContext, FX_UINT id) {
return L"The input value must be greater than or equal to %s.";
case IDS_STRING_JSRANGE3:
return L"The input value must be less than or equal to %s.";
- case IDS_STRING_NOTSUPPORT:
+ case IDS_STRING_JSNOTSUPPORT:
return L"Operation not supported.";
case IDS_STRING_JSBUSY:
return L"System is busy.";
@@ -45,6 +45,10 @@ CFX_WideString JSGetStringFromID(CJS_Context* pContext, FX_UINT id) {
return L"Incorrect parameter type.";
case IDS_STRING_JSVALUEERROR:
return L"Incorrect parameter value.";
+ case IDS_STRING_JSNOPERMISSION:
+ return L"Permission denied.";
+ case IDS_STRING_JSBADOBJECT:
+ return L"Object no longer exists.";
default:
return L"";
}
diff --git a/fpdfsdk/javascript/resource.h b/fpdfsdk/javascript/resource.h
index a6bfaed7c2..d775e94c5e 100644
--- a/fpdfsdk/javascript/resource.h
+++ b/fpdfsdk/javascript/resource.h
@@ -20,7 +20,7 @@ class CJS_Context;
#define IDS_STRING_JSRANGE1 25619
#define IDS_STRING_JSRANGE2 25620
#define IDS_STRING_JSRANGE3 25621
-#define IDS_STRING_NOTSUPPORT 25627
+#define IDS_STRING_JSNOTSUPPORT 25627
#define IDS_STRING_JSBUSY 25628
#define IDS_STRING_JSEVENT 25629
#define IDS_STRING_RUN 25630
@@ -30,8 +30,10 @@ class CJS_Context;
#define IDS_STRING_JSREADONLY 25636
#define IDS_STRING_JSTYPEERROR 25637
#define IDS_STRING_JSVALUEERROR 25638
+#define IDS_STRING_JSNOPERMISSION 25639
+#define IDS_STRING_JSBADOBJECT 25640
-CFX_WideString JSGetStringFromID(CJS_Context* pContext, FX_UINT id);
+CFX_WideString JSGetStringFromID(FX_UINT id);
CFX_WideString JSFormatErrorString(const char* class_name,
const char* property_name,
const CFX_WideString& details);
diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp
index fa53a9e223..44511f591f 100644
--- a/fpdfsdk/javascript/util.cpp
+++ b/fpdfsdk/javascript/util.cpp
@@ -190,12 +190,12 @@ FX_BOOL util::printd(IJS_Context* cc,
CJS_Value p2 = params[1];
CJS_Date jsDate;
if (!p2.ConvertToDate(pRuntime, jsDate)) {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1);
+ sError = JSGetStringFromID(IDS_STRING_JSPRINT1);
return FALSE;
}
if (!jsDate.IsValidDate(pRuntime)) {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2);
+ sError = JSGetStringFromID(IDS_STRING_JSPRINT2);
return FALSE;
}
@@ -223,7 +223,7 @@ FX_BOOL util::printd(IJS_Context* cc,
jsDate.GetSeconds(pRuntime));
break;
default:
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSVALUEERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
return FALSE;
}
@@ -233,7 +233,7 @@ FX_BOOL util::printd(IJS_Context* cc,
if (p1.GetType() == CJS_Value::VT_string) {
if (iSize > 2 && params[2].ToBool(pRuntime)) {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_NOTSUPPORT);
+ sError = JSGetStringFromID(IDS_STRING_JSNOTSUPPORT);
return FALSE; // currently, it doesn't support XFAPicture.
}
@@ -303,7 +303,7 @@ FX_BOOL util::printd(IJS_Context* cc,
return TRUE;
}
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSTYPEERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR);
return FALSE;
}
@@ -312,13 +312,12 @@ FX_BOOL util::printx(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
-
if (params.size() < 2) {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
vRet = CJS_Value(pRuntime, printx(params[0].ToCFXWideString(pRuntime),
params[1].ToCFXWideString(pRuntime))
.c_str());
@@ -456,17 +455,15 @@ FX_BOOL util::byteToChar(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = static_cast<CJS_Context*>(cc);
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
-
if (params.size() < 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
return FALSE;
}
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
int arg = params[0].ToInt(pRuntime);
if (arg < 0 || arg > 255) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
+ sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR);
return FALSE;
}