From b1670b5cca9a59dfb612ef9eb891a70dd716bf9c Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 16 Feb 2017 17:01:00 -0800 Subject: Pass CJS_Runtime to JS callbacks. This is much more convenient, since only a fraction of them need an IJS_EventContext, which can be obtained from the CJS_Runtime. Make GetCurrentEventContext() specific to CJS_Runtime, and return the concrete type. This saves a lot of casting. Change-Id: If79a3bcbf44de513f3caace153099234cc313d47 Reviewed-on: https://pdfium-review.googlesource.com/2793 Commit-Queue: dsinclair Reviewed-by: dsinclair --- fpdfsdk/javascript/Annot.cpp | 6 +- fpdfsdk/javascript/Annot.h | 6 +- fpdfsdk/javascript/Document.cpp | 196 +++++++++++++++------------------ fpdfsdk/javascript/Document.h | 160 ++++++++++++++------------- fpdfsdk/javascript/Field.cpp | 183 +++++++++++++----------------- fpdfsdk/javascript/Field.h | 158 +++++++++++++------------- fpdfsdk/javascript/Icon.cpp | 2 +- fpdfsdk/javascript/Icon.h | 2 +- fpdfsdk/javascript/JS_Define.h | 28 ++--- fpdfsdk/javascript/JS_Runtime_Stub.cpp | 5 +- fpdfsdk/javascript/PublicMethods.cpp | 158 +++++++++++--------------- fpdfsdk/javascript/PublicMethods.h | 44 ++++---- fpdfsdk/javascript/app.cpp | 97 +++++++--------- fpdfsdk/javascript/app.h | 66 +++++------ fpdfsdk/javascript/cjs_runtime.cpp | 7 +- fpdfsdk/javascript/cjs_runtime.h | 4 +- fpdfsdk/javascript/color.cpp | 33 +++--- fpdfsdk/javascript/color.h | 30 ++--- fpdfsdk/javascript/console.cpp | 8 +- fpdfsdk/javascript/console.h | 8 +- fpdfsdk/javascript/event.cpp | 102 ++++++++--------- fpdfsdk/javascript/event.h | 42 +++---- fpdfsdk/javascript/global.cpp | 20 ++-- fpdfsdk/javascript/global.h | 10 +- fpdfsdk/javascript/ijs_runtime.h | 1 - fpdfsdk/javascript/report.cpp | 4 +- fpdfsdk/javascript/report.h | 4 +- fpdfsdk/javascript/util.cpp | 15 +-- fpdfsdk/javascript/util.h | 10 +- 29 files changed, 646 insertions(+), 763 deletions(-) (limited to 'fpdfsdk/javascript') diff --git a/fpdfsdk/javascript/Annot.cpp b/fpdfsdk/javascript/Annot.cpp index 1a496ec16c..dbb2cb23f2 100644 --- a/fpdfsdk/javascript/Annot.cpp +++ b/fpdfsdk/javascript/Annot.cpp @@ -37,7 +37,7 @@ Annot::Annot(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} Annot::~Annot() {} -bool Annot::hidden(IJS_EventContext* cc, +bool Annot::hidden(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { @@ -73,7 +73,7 @@ bool Annot::hidden(IJS_EventContext* cc, return true; } -bool Annot::name(IJS_EventContext* cc, +bool Annot::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { @@ -96,7 +96,7 @@ bool Annot::name(IJS_EventContext* cc, return true; } -bool Annot::type(IJS_EventContext* cc, +bool Annot::type(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { diff --git a/fpdfsdk/javascript/Annot.h b/fpdfsdk/javascript/Annot.h index dffa713c4d..d9757fa514 100644 --- a/fpdfsdk/javascript/Annot.h +++ b/fpdfsdk/javascript/Annot.h @@ -17,9 +17,9 @@ class Annot : public CJS_EmbedObj { explicit Annot(CJS_Object* pJSObject); ~Annot() override; - bool hidden(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool name(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool type(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); + bool hidden(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool name(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool type(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); void SetSDKAnnot(CPDFSDK_BAAnnot* annot); diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index 38600ed766..133e1b3fd9 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -163,7 +163,7 @@ Document::~Document() { } // the total number of fileds in document. -bool Document::numFields(IJS_EventContext* cc, +bool Document::numFields(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -180,7 +180,7 @@ bool Document::numFields(IJS_EventContext* cc, return true; } -bool Document::dirty(IJS_EventContext* cc, +bool Document::dirty(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!m_pFormFillEnv) { @@ -201,16 +201,16 @@ bool Document::dirty(IJS_EventContext* cc, return true; } -bool Document::ADBE(IJS_EventContext* cc, +bool Document::ADBE(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) - vp.GetJSValue()->SetNull(CJS_Runtime::FromEventContext(cc)); + vp.GetJSValue()->SetNull(pRuntime); return true; } -bool Document::pageNum(IJS_EventContext* cc, +bool Document::pageNum(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!m_pFormFillEnv) { @@ -235,7 +235,7 @@ bool Document::pageNum(IJS_EventContext* cc, return true; } -bool Document::addAnnot(IJS_EventContext* cc, +bool Document::addAnnot(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -243,7 +243,7 @@ bool Document::addAnnot(IJS_EventContext* cc, return true; } -bool Document::addField(IJS_EventContext* cc, +bool Document::addField(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -251,7 +251,7 @@ bool Document::addField(IJS_EventContext* cc, return true; } -bool Document::exportAsText(IJS_EventContext* cc, +bool Document::exportAsText(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -259,7 +259,7 @@ bool Document::exportAsText(IJS_EventContext* cc, return true; } -bool Document::exportAsFDF(IJS_EventContext* cc, +bool Document::exportAsFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -267,7 +267,7 @@ bool Document::exportAsFDF(IJS_EventContext* cc, return true; } -bool Document::exportAsXFDF(IJS_EventContext* cc, +bool Document::exportAsXFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -280,7 +280,7 @@ bool Document::exportAsXFDF(IJS_EventContext* cc, // note: the paremter cName, this is clue how to treat if the cName is not a // valiable filed name in this document -bool Document::getField(IJS_EventContext* cc, +bool Document::getField(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -292,7 +292,6 @@ bool Document::getField(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); @@ -313,7 +312,7 @@ bool Document::getField(IJS_EventContext* cc, } // Gets the name of the nth field in the document -bool Document::getNthFieldName(IJS_EventContext* cc, +bool Document::getNthFieldName(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -325,7 +324,6 @@ bool Document::getNthFieldName(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int nIndex = params[0].ToInt(pRuntime); if (nIndex < 0) { sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); @@ -341,7 +339,7 @@ bool Document::getNthFieldName(IJS_EventContext* cc, return true; } -bool Document::importAnFDF(IJS_EventContext* cc, +bool Document::importAnFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -349,7 +347,7 @@ bool Document::importAnFDF(IJS_EventContext* cc, return true; } -bool Document::importAnXFDF(IJS_EventContext* cc, +bool Document::importAnXFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -357,7 +355,7 @@ bool Document::importAnXFDF(IJS_EventContext* cc, return true; } -bool Document::importTextData(IJS_EventContext* cc, +bool Document::importTextData(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -368,7 +366,7 @@ bool Document::importTextData(IJS_EventContext* cc, // exports the form data and mails the resulting fdf file as an attachment to // all recipients. // comment: need reader supports -bool Document::mailForm(IJS_EventContext* cc, +bool Document::mailForm(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -380,7 +378,6 @@ bool Document::mailForm(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int iLength = params.size(); bool bUI = iLength > 0 ? params[0].ToBool(pRuntime) : true; CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; @@ -403,7 +400,7 @@ bool Document::mailForm(IJS_EventContext* cc, return true; } -bool Document::print(IJS_EventContext* cc, +bool Document::print(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -411,7 +408,6 @@ bool Document::print(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); bool bUI = true; int nStart = 0; int nEnd = 0; @@ -472,7 +468,7 @@ bool Document::print(IJS_EventContext* cc, // comment: // note: if the filed name is not rational, adobe is dumb for it. -bool Document::removeField(IJS_EventContext* cc, +bool Document::removeField(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -489,7 +485,6 @@ bool Document::removeField(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); std::vector widgets; @@ -532,7 +527,7 @@ bool Document::removeField(IJS_EventContext* cc, // comment: // note: if the fields names r not rational, aodbe is dumb for it. -bool Document::resetForm(IJS_EventContext* cc, +bool Document::resetForm(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -557,9 +552,6 @@ bool Document::resetForm(IJS_EventContext* cc, return true; } - CJS_EventContext* pContext = static_cast(cc); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - switch (params[0].GetType()) { default: aName.Attach(params[0].ToV8Array(pRuntime)); @@ -586,7 +578,7 @@ bool Document::resetForm(IJS_EventContext* cc, return true; } -bool Document::saveAs(IJS_EventContext* cc, +bool Document::saveAs(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -594,14 +586,14 @@ bool Document::saveAs(IJS_EventContext* cc, return true; } -bool Document::syncAnnotScan(IJS_EventContext* cc, +bool Document::syncAnnotScan(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Document::submitForm(IJS_EventContext* cc, +bool Document::submitForm(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -614,7 +606,7 @@ bool Document::submitForm(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); + CJS_Array aFields; CFX_WideString strURL; bool bFDF = true; @@ -683,18 +675,16 @@ void Document::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { m_pFormFillEnv.Reset(pFormFillEnv); } -bool Document::bookmarkRoot(IJS_EventContext* cc, +bool Document::bookmarkRoot(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool Document::mailDoc(IJS_EventContext* cc, +bool Document::mailDoc(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - // TODO(tsepez): Check maximum number of allowed params. bool bUI = true; CFX_WideString cTo = L""; @@ -746,13 +736,13 @@ bool Document::mailDoc(IJS_EventContext* cc, return true; } -bool Document::author(IJS_EventContext* cc, +bool Document::author(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - return getPropertyInternal(cc, vp, "Author", sError); + return getPropertyInternal(pRuntime, vp, "Author", sError); } -bool Document::info(IJS_EventContext* cc, +bool Document::info(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -778,7 +768,6 @@ bool Document::info(IJS_EventContext* cc, CFX_WideString cwModDate = pDictionary->GetUnicodeTextFor("ModDate"); CFX_WideString cwTrapped = pDictionary->GetUnicodeTextFor("Trapped"); - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); v8::Local pObj = pRuntime->NewFxDynamicObj(-1); pRuntime->PutObjectProperty(pObj, L"Author", pRuntime->NewString(cwAuthor)); pRuntime->PutObjectProperty(pObj, L"Title", pRuntime->NewString(cwTitle)); @@ -813,7 +802,7 @@ bool Document::info(IJS_EventContext* cc, return true; } -bool Document::getPropertyInternal(IJS_EventContext* cc, +bool Document::getPropertyInternal(CJS_Runtime* pRuntime, CJS_PropValue& vp, const CFX_ByteString& propName, CFX_WideString& sError) { @@ -841,19 +830,19 @@ bool Document::getPropertyInternal(IJS_EventContext* cc, return true; } -bool Document::creationDate(IJS_EventContext* cc, +bool Document::creationDate(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - return getPropertyInternal(cc, vp, "CreationDate", sError); + return getPropertyInternal(pRuntime, vp, "CreationDate", sError); } -bool Document::creator(IJS_EventContext* cc, +bool Document::creator(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - return getPropertyInternal(cc, vp, "Creator", sError); + return getPropertyInternal(pRuntime, vp, "Creator", sError); } -bool Document::delay(IJS_EventContext* cc, +bool Document::delay(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!m_pFormFillEnv) { @@ -881,41 +870,41 @@ bool Document::delay(IJS_EventContext* cc, return true; } -bool Document::keywords(IJS_EventContext* cc, +bool Document::keywords(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - return getPropertyInternal(cc, vp, "Keywords", sError); + return getPropertyInternal(pRuntime, vp, "Keywords", sError); } -bool Document::modDate(IJS_EventContext* cc, +bool Document::modDate(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - return getPropertyInternal(cc, vp, "ModDate", sError); + return getPropertyInternal(pRuntime, vp, "ModDate", sError); } -bool Document::producer(IJS_EventContext* cc, +bool Document::producer(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - return getPropertyInternal(cc, vp, "Producer", sError); + return getPropertyInternal(pRuntime, vp, "Producer", sError); } -bool Document::subject(IJS_EventContext* cc, +bool Document::subject(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - return getPropertyInternal(cc, vp, "Subject", sError); + return getPropertyInternal(pRuntime, vp, "Subject", sError); } -bool Document::title(IJS_EventContext* cc, +bool Document::title(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) { sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - return getPropertyInternal(cc, vp, "Title", sError); + return getPropertyInternal(pRuntime, vp, "Title", sError); } -bool Document::numPages(IJS_EventContext* cc, +bool Document::numPages(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -930,7 +919,7 @@ bool Document::numPages(IJS_EventContext* cc, return true; } -bool Document::external(IJS_EventContext* cc, +bool Document::external(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { // In Chrome case, should always return true. @@ -940,7 +929,7 @@ bool Document::external(IJS_EventContext* cc, return true; } -bool Document::filesize(IJS_EventContext* cc, +bool Document::filesize(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -951,19 +940,19 @@ bool Document::filesize(IJS_EventContext* cc, return true; } -bool Document::mouseX(IJS_EventContext* cc, +bool Document::mouseX(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool Document::mouseY(IJS_EventContext* cc, +bool Document::mouseY(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool Document::URL(IJS_EventContext* cc, +bool Document::URL(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -978,7 +967,7 @@ bool Document::URL(IJS_EventContext* cc, return true; } -bool Document::baseURL(IJS_EventContext* cc, +bool Document::baseURL(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { @@ -989,7 +978,7 @@ bool Document::baseURL(IJS_EventContext* cc, return true; } -bool Document::calculate(IJS_EventContext* cc, +bool Document::calculate(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!m_pFormFillEnv) { @@ -1007,7 +996,7 @@ bool Document::calculate(IJS_EventContext* cc, return true; } -bool Document::documentFileName(IJS_EventContext* cc, +bool Document::documentFileName(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -1032,7 +1021,7 @@ bool Document::documentFileName(IJS_EventContext* cc, return true; } -bool Document::path(IJS_EventContext* cc, +bool Document::path(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -1047,40 +1036,40 @@ bool Document::path(IJS_EventContext* cc, return true; } -bool Document::pageWindowRect(IJS_EventContext* cc, +bool Document::pageWindowRect(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool Document::layout(IJS_EventContext* cc, +bool Document::layout(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool Document::addLink(IJS_EventContext* cc, +bool Document::addLink(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Document::closeDoc(IJS_EventContext* cc, +bool Document::closeDoc(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Document::getPageBox(IJS_EventContext* cc, +bool Document::getPageBox(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Document::getAnnot(IJS_EventContext* cc, +bool Document::getAnnot(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1092,7 +1081,6 @@ bool Document::getAnnot(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int nPageNo = params[0].ToInt(pRuntime); CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); @@ -1131,7 +1119,7 @@ bool Document::getAnnot(IJS_EventContext* cc, return true; } -bool Document::getAnnots(IJS_EventContext* cc, +bool Document::getAnnots(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1139,8 +1127,6 @@ bool Document::getAnnots(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - // TODO(tonikitoo): Add support supported parameters as per // the PDF spec. @@ -1180,29 +1166,29 @@ bool Document::getAnnots(IJS_EventContext* cc, return true; } -bool Document::getAnnot3D(IJS_EventContext* cc, +bool Document::getAnnot3D(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - vRet.SetNull(CJS_Runtime::FromEventContext(cc)); + vRet.SetNull(pRuntime); return true; } -bool Document::getAnnots3D(IJS_EventContext* cc, +bool Document::getAnnots3D(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Document::getOCGs(IJS_EventContext* cc, +bool Document::getOCGs(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Document::getLinks(IJS_EventContext* cc, +bool Document::getLinks(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1214,7 +1200,7 @@ bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); } -bool Document::addIcon(IJS_EventContext* cc, +bool Document::addIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1223,7 +1209,6 @@ bool Document::addIcon(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); if (params[1].GetType() != CJS_Value::VT_object) { sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); @@ -1247,22 +1232,19 @@ bool Document::addIcon(IJS_EventContext* cc, return true; } -bool Document::icons(IJS_EventContext* cc, +bool Document::icons(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { sError = JSGetStringFromID(IDS_STRING_JSREADONLY); return false; } - - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); if (m_Icons.empty()) { vp.GetJSValue()->SetNull(pRuntime); return true; } CJS_Array Icons; - int i = 0; for (const auto& pIconElement : m_Icons) { v8::Local pObj = @@ -1288,7 +1270,7 @@ bool Document::icons(IJS_EventContext* cc, return true; } -bool Document::getIcon(IJS_EventContext* cc, +bool Document::getIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1300,9 +1282,7 @@ bool Document::getIcon(IJS_EventContext* cc, if (m_Icons.empty()) return false; - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); - for (const auto& pIconElement : m_Icons) { if (pIconElement->IconName != swIconName) continue; @@ -1331,7 +1311,7 @@ bool Document::getIcon(IJS_EventContext* cc, return false; } -bool Document::removeIcon(IJS_EventContext* cc, +bool Document::removeIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1339,7 +1319,7 @@ bool Document::removeIcon(IJS_EventContext* cc, return true; } -bool Document::createDataObject(IJS_EventContext* cc, +bool Document::createDataObject(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1347,13 +1327,13 @@ bool Document::createDataObject(IJS_EventContext* cc, return true; } -bool Document::media(IJS_EventContext* cc, +bool Document::media(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool Document::calculateNow(IJS_EventContext* cc, +bool Document::calculateNow(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1371,13 +1351,13 @@ bool Document::calculateNow(IJS_EventContext* cc, return true; } -bool Document::Collab(IJS_EventContext* cc, +bool Document::Collab(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool Document::getPageNthWord(IJS_EventContext* cc, +bool Document::getPageNthWord(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1389,7 +1369,6 @@ bool Document::getPageNthWord(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); // TODO(tsepez): check maximum allowable params. @@ -1436,7 +1415,7 @@ bool Document::getPageNthWord(IJS_EventContext* cc, return true; } -bool Document::getPageNthWordQuads(IJS_EventContext* cc, +bool Document::getPageNthWordQuads(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1451,7 +1430,7 @@ bool Document::getPageNthWordQuads(IJS_EventContext* cc, return false; } -bool Document::getPageNumWords(IJS_EventContext* cc, +bool Document::getPageNumWords(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1463,7 +1442,6 @@ bool Document::getPageNumWords(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { @@ -1488,11 +1466,10 @@ bool Document::getPageNumWords(IJS_EventContext* cc, return true; } -bool Document::getPrintParams(IJS_EventContext* cc, +bool Document::getPrintParams(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); v8::Local pRetObj = pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID); @@ -1574,7 +1551,7 @@ CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, return swRet; } -bool Document::zoom(IJS_EventContext* cc, +bool Document::zoom(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; @@ -1590,13 +1567,13 @@ bool Document::zoom(IJS_EventContext* cc, (refW, ReflowWidth) */ -bool Document::zoomType(IJS_EventContext* cc, +bool Document::zoomType(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool Document::deletePages(IJS_EventContext* cc, +bool Document::deletePages(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1604,7 +1581,7 @@ bool Document::deletePages(IJS_EventContext* cc, return true; } -bool Document::extractPages(IJS_EventContext* cc, +bool Document::extractPages(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1612,7 +1589,7 @@ bool Document::extractPages(IJS_EventContext* cc, return true; } -bool Document::insertPages(IJS_EventContext* cc, +bool Document::insertPages(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1620,7 +1597,7 @@ bool Document::insertPages(IJS_EventContext* cc, return true; } -bool Document::replacePages(IJS_EventContext* cc, +bool Document::replacePages(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1628,7 +1605,7 @@ bool Document::replacePages(IJS_EventContext* cc, return true; } -bool Document::getURL(IJS_EventContext* cc, +bool Document::getURL(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1636,7 +1613,7 @@ bool Document::getURL(IJS_EventContext* cc, return true; } -bool Document::gotoNamedDest(IJS_EventContext* cc, +bool Document::gotoNamedDest(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1648,7 +1625,6 @@ bool Document::gotoNamedDest(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); CFX_ByteString utf8Name = wideName.UTF8Encode(); CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); diff --git a/fpdfsdk/javascript/Document.h b/fpdfsdk/javascript/Document.h index 97a93c528e..661307e62a 100644 --- a/fpdfsdk/javascript/Document.h +++ b/fpdfsdk/javascript/Document.h @@ -61,231 +61,241 @@ class Document : public CJS_EmbedObj { explicit Document(CJS_Object* pJSObject); ~Document() override; - bool ADBE(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool author(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool baseURL(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool bookmarkRoot(IJS_EventContext* cc, + bool ADBE(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool author(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool baseURL(CJS_Runtime* pRuntime, + CJS_PropValue& vp, + CFX_WideString& sError); + bool bookmarkRoot(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool calculate(IJS_EventContext* cc, + bool calculate(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool Collab(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool creationDate(IJS_EventContext* cc, + bool Collab(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool creationDate(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool creator(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool delay(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool dirty(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool documentFileName(IJS_EventContext* cc, + bool creator(CJS_Runtime* pRuntime, + CJS_PropValue& vp, + CFX_WideString& sError); + bool delay(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool dirty(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool documentFileName(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool external(IJS_EventContext* cc, + bool external(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool filesize(IJS_EventContext* cc, + bool filesize(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool icons(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool info(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool keywords(IJS_EventContext* cc, + bool icons(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool info(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool keywords(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool layout(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool media(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool modDate(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool mouseX(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool mouseY(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool numFields(IJS_EventContext* cc, + bool layout(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool media(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool modDate(CJS_Runtime* pRuntime, + CJS_PropValue& vp, + CFX_WideString& sError); + bool mouseX(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool mouseY(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool numFields(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool numPages(IJS_EventContext* cc, + bool numPages(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool pageNum(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool pageWindowRect(IJS_EventContext* cc, + bool pageNum(CJS_Runtime* pRuntime, + CJS_PropValue& vp, + CFX_WideString& sError); + bool pageWindowRect(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool path(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool producer(IJS_EventContext* cc, + bool path(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool producer(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool subject(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool title(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool zoom(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool zoomType(IJS_EventContext* cc, + bool subject(CJS_Runtime* pRuntime, + CJS_PropValue& vp, + CFX_WideString& sError); + bool title(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool zoom(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool zoomType(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool addAnnot(IJS_EventContext* cc, + bool addAnnot(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool addField(IJS_EventContext* cc, + bool addField(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool addLink(IJS_EventContext* cc, + bool addLink(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool addIcon(IJS_EventContext* cc, + bool addIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool calculateNow(IJS_EventContext* cc, + bool calculateNow(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool closeDoc(IJS_EventContext* cc, + bool closeDoc(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool createDataObject(IJS_EventContext* cc, + bool createDataObject(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool deletePages(IJS_EventContext* cc, + bool deletePages(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool exportAsText(IJS_EventContext* cc, + bool exportAsText(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool exportAsFDF(IJS_EventContext* cc, + bool exportAsFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool exportAsXFDF(IJS_EventContext* cc, + bool exportAsXFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool extractPages(IJS_EventContext* cc, + bool extractPages(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getAnnot(IJS_EventContext* cc, + bool getAnnot(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getAnnots(IJS_EventContext* cc, + bool getAnnots(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getAnnot3D(IJS_EventContext* cc, + bool getAnnot3D(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getAnnots3D(IJS_EventContext* cc, + bool getAnnots3D(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getField(IJS_EventContext* cc, + bool getField(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getIcon(IJS_EventContext* cc, + bool getIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getLinks(IJS_EventContext* cc, + bool getLinks(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getNthFieldName(IJS_EventContext* cc, + bool getNthFieldName(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getOCGs(IJS_EventContext* cc, + bool getOCGs(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getPageBox(IJS_EventContext* cc, + bool getPageBox(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getPageNthWord(IJS_EventContext* cc, + bool getPageNthWord(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getPageNthWordQuads(IJS_EventContext* cc, + bool getPageNthWordQuads(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getPageNumWords(IJS_EventContext* cc, + bool getPageNumWords(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getPrintParams(IJS_EventContext* cc, + bool getPrintParams(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getURL(IJS_EventContext* cc, + bool getURL(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool gotoNamedDest(IJS_EventContext* cc, + bool gotoNamedDest(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool importAnFDF(IJS_EventContext* cc, + bool importAnFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool importAnXFDF(IJS_EventContext* cc, + bool importAnXFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool importTextData(IJS_EventContext* cc, + bool importTextData(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool insertPages(IJS_EventContext* cc, + bool insertPages(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool mailForm(IJS_EventContext* cc, + bool mailForm(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool print(IJS_EventContext* cc, + bool print(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool removeField(IJS_EventContext* cc, + bool removeField(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool replacePages(IJS_EventContext* cc, + bool replacePages(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool resetForm(IJS_EventContext* cc, + bool resetForm(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool saveAs(IJS_EventContext* cc, + bool saveAs(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool submitForm(IJS_EventContext* cc, + bool submitForm(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool syncAnnotScan(IJS_EventContext* cc, + bool syncAnnotScan(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool mailDoc(IJS_EventContext* cc, + bool mailDoc(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool removeIcon(IJS_EventContext* cc, + bool removeIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool URL(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); + bool URL(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv); CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { @@ -300,7 +310,7 @@ class Document : public CJS_EmbedObj { int CountWords(CPDF_TextObject* pTextObj); CFX_WideString GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex); - bool getPropertyInternal(IJS_EventContext* cc, + bool getPropertyInternal(CJS_Runtime* pRuntime, CJS_PropValue& vp, const CFX_ByteString& propName, CFX_WideString& sError); diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index 3eb3f8e35b..263e3a775e 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -375,7 +375,7 @@ CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) { return pFormField->GetControl(m_nFormControlIndex); } -bool Field::alignment(IJS_EventContext* cc, +bool Field::alignment(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -431,7 +431,7 @@ void Field::SetAlignment(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::borderStyle(IJS_EventContext* cc, +bool Field::borderStyle(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -540,7 +540,7 @@ void Field::SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::buttonAlignX(IJS_EventContext* cc, +bool Field::buttonAlignX(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -589,7 +589,7 @@ void Field::SetButtonAlignX(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::buttonAlignY(IJS_EventContext* cc, +bool Field::buttonAlignY(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -638,7 +638,7 @@ void Field::SetButtonAlignY(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::buttonFitBounds(IJS_EventContext* cc, +bool Field::buttonFitBounds(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -682,7 +682,7 @@ void Field::SetButtonFitBounds(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::buttonPosition(IJS_EventContext* cc, +bool Field::buttonPosition(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -725,7 +725,7 @@ void Field::SetButtonPosition(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::buttonScaleHow(IJS_EventContext* cc, +bool Field::buttonScaleHow(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -773,7 +773,7 @@ void Field::SetButtonScaleHow(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::buttonScaleWhen(IJS_EventContext* cc, +bool Field::buttonScaleWhen(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -832,7 +832,7 @@ void Field::SetButtonScaleWhen(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::calcOrderIndex(IJS_EventContext* cc, +bool Field::calcOrderIndex(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -876,7 +876,7 @@ void Field::SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::charLimit(IJS_EventContext* cc, +bool Field::charLimit(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -915,7 +915,7 @@ void Field::SetCharLimit(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::comb(IJS_EventContext* cc, +bool Field::comb(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -958,7 +958,7 @@ void Field::SetComb(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::commitOnSelChange(IJS_EventContext* cc, +bool Field::commitOnSelChange(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -1003,11 +1003,9 @@ void Field::SetCommitOnSelChange(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::currentValueIndices(IJS_EventContext* cc, +bool Field::currentValueIndices(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - if (vp.IsSetting()) { if (!m_bCanSet) return false; @@ -1089,7 +1087,7 @@ void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::defaultStyle(IJS_EventContext* cc, +bool Field::defaultStyle(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return false; @@ -1101,7 +1099,7 @@ void Field::SetDefaultStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::defaultValue(IJS_EventContext* cc, +bool Field::defaultValue(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -1142,7 +1140,7 @@ void Field::SetDefaultValue(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::doNotScroll(IJS_EventContext* cc, +bool Field::doNotScroll(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -1185,7 +1183,7 @@ void Field::SetDoNotScroll(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::doNotSpellCheck(IJS_EventContext* cc, +bool Field::doNotSpellCheck(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -1225,7 +1223,7 @@ void Field::SetDelay(bool bDelay) { } } -bool Field::delay(IJS_EventContext* cc, +bool Field::delay(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsSetting()) { @@ -1241,7 +1239,7 @@ bool Field::delay(IJS_EventContext* cc, return true; } -bool Field::display(IJS_EventContext* cc, +bool Field::display(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -1323,7 +1321,7 @@ void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::doc(IJS_EventContext* cc, +bool Field::doc(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) @@ -1333,7 +1331,7 @@ bool Field::doc(IJS_EventContext* cc, return true; } -bool Field::editable(IJS_EventContext* cc, +bool Field::editable(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -1356,7 +1354,7 @@ bool Field::editable(IJS_EventContext* cc, return true; } -bool Field::exportValues(IJS_EventContext* cc, +bool Field::exportValues(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { std::vector FieldArray = GetFormFields(m_FieldName); @@ -1371,7 +1369,6 @@ bool Field::exportValues(IJS_EventContext* cc, if (vp.IsSetting()) return m_bCanSet && vp.GetJSValue()->IsArrayObject(); - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CJS_Array ExportValusArray; if (m_nFormControlIndex < 0) { for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { @@ -1397,7 +1394,7 @@ bool Field::exportValues(IJS_EventContext* cc, return true; } -bool Field::fileSelect(IJS_EventContext* cc, +bool Field::fileSelect(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { std::vector FieldArray = GetFormFields(m_FieldName); @@ -1420,10 +1417,9 @@ bool Field::fileSelect(IJS_EventContext* cc, return true; } -bool Field::fillColor(IJS_EventContext* cc, +bool Field::fillColor(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CJS_Array crArray; std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -1489,7 +1485,7 @@ void Field::SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::hidden(IJS_EventContext* cc, +bool Field::hidden(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -1535,7 +1531,7 @@ void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv, SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display); } -bool Field::highlight(IJS_EventContext* cc, +bool Field::highlight(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -1594,7 +1590,7 @@ void Field::SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::lineWidth(IJS_EventContext* cc, +bool Field::lineWidth(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -1673,7 +1669,7 @@ void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::multiline(IJS_EventContext* cc, +bool Field::multiline(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -1716,7 +1712,7 @@ void Field::SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::multipleSelection(IJS_EventContext* cc, +bool Field::multipleSelection(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -1753,7 +1749,7 @@ void Field::SetMultipleSelection(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::name(IJS_EventContext* cc, +bool Field::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) @@ -1767,7 +1763,7 @@ bool Field::name(IJS_EventContext* cc, return true; } -bool Field::numItems(IJS_EventContext* cc, +bool Field::numItems(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) @@ -1787,7 +1783,7 @@ bool Field::numItems(IJS_EventContext* cc, return true; } -bool Field::page(IJS_EventContext* cc, +bool Field::page(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) { @@ -1810,7 +1806,6 @@ bool Field::page(IJS_EventContext* cc, return true; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CJS_Array PageArray; int i = 0; for (const auto& pObserved : widgets) { @@ -1833,7 +1828,7 @@ bool Field::page(IJS_EventContext* cc, return true; } -bool Field::password(IJS_EventContext* cc, +bool Field::password(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -1872,7 +1867,7 @@ void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::print(IJS_EventContext* cc, +bool Field::print(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); @@ -1943,7 +1938,7 @@ bool Field::print(IJS_EventContext* cc, return true; } -bool Field::radiosInUnison(IJS_EventContext* cc, +bool Field::radiosInUnison(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { std::vector FieldArray = GetFormFields(m_FieldName); @@ -1966,7 +1961,7 @@ bool Field::radiosInUnison(IJS_EventContext* cc, return true; } -bool Field::readonly(IJS_EventContext* cc, +bool Field::readonly(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { std::vector FieldArray = GetFormFields(m_FieldName); @@ -1985,10 +1980,9 @@ bool Field::readonly(IJS_EventContext* cc, return true; } -bool Field::rect(IJS_EventContext* cc, +bool Field::rect(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CJS_Value Upper_Leftx(pRuntime); CJS_Value Upper_Lefty(pRuntime); CJS_Value Lower_Rightx(pRuntime); @@ -2106,7 +2100,7 @@ void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::required(IJS_EventContext* cc, +bool Field::required(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { std::vector FieldArray = GetFormFields(m_FieldName); @@ -2129,7 +2123,7 @@ bool Field::required(IJS_EventContext* cc, return true; } -bool Field::richText(IJS_EventContext* cc, +bool Field::richText(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -2158,13 +2152,13 @@ bool Field::richText(IJS_EventContext* cc, return true; } -bool Field::richValue(IJS_EventContext* cc, +bool Field::richValue(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool Field::rotation(IJS_EventContext* cc, +bool Field::rotation(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -2203,10 +2197,9 @@ void Field::SetRotation(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::strokeColor(IJS_EventContext* cc, +bool Field::strokeColor(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CJS_Array crArray; if (vp.IsSetting()) { @@ -2270,7 +2263,7 @@ void Field::SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::style(IJS_EventContext* cc, +bool Field::style(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -2338,16 +2331,15 @@ void Field::SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::submitName(IJS_EventContext* cc, +bool Field::submitName(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool Field::textColor(IJS_EventContext* cc, +bool Field::textColor(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CJS_Array crArray; if (vp.IsSetting()) { @@ -2407,7 +2399,7 @@ void Field::SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::textFont(IJS_EventContext* cc, +bool Field::textFont(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -2459,7 +2451,7 @@ void Field::SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::textSize(IJS_EventContext* cc, +bool Field::textSize(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -2504,7 +2496,7 @@ void Field::SetTextSize(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::type(IJS_EventContext* cc, +bool Field::type(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) @@ -2547,7 +2539,7 @@ bool Field::type(IJS_EventContext* cc, return true; } -bool Field::userName(IJS_EventContext* cc, +bool Field::userName(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pFormFillEnv); @@ -2582,11 +2574,9 @@ void Field::SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv, // Not supported. } -bool Field::value(IJS_EventContext* cc, +bool Field::value(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - if (vp.IsSetting()) { if (!m_bCanSet) return false; @@ -2723,7 +2713,7 @@ void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv, } } -bool Field::valueAsString(IJS_EventContext* cc, +bool Field::valueAsString(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) @@ -2765,7 +2755,7 @@ bool Field::valueAsString(IJS_EventContext* cc, return true; } -bool Field::browseForFileToSubmit(IJS_EventContext* cc, +bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -2786,12 +2776,10 @@ bool Field::browseForFileToSubmit(IJS_EventContext* cc, return false; } -bool Field::buttonGetCaption(IJS_EventContext* cc, +bool Field::buttonGetCaption(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - int nface = 0; int iSize = params.size(); if (iSize >= 1) @@ -2821,13 +2809,10 @@ bool Field::buttonGetCaption(IJS_EventContext* cc, return true; } -bool Field::buttonGetIcon(IJS_EventContext* cc, +bool Field::buttonGetIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_EventContext* pContext = static_cast(cc); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - int nface = 0; int iSize = params.size(); if (iSize >= 1) @@ -2867,28 +2852,28 @@ bool Field::buttonGetIcon(IJS_EventContext* cc, return true; } -bool Field::buttonImportIcon(IJS_EventContext* cc, +bool Field::buttonImportIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Field::buttonSetCaption(IJS_EventContext* cc, +bool Field::buttonSetCaption(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool Field::buttonSetIcon(IJS_EventContext* cc, +bool Field::buttonSetIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool Field::checkThisBox(IJS_EventContext* cc, +bool Field::checkThisBox(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -2899,9 +2884,7 @@ bool Field::checkThisBox(IJS_EventContext* cc, if (!m_bCanSet) return false; - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int nWidget = params[0].ToInt(pRuntime); - bool bCheckit = true; if (iSize >= 2) bCheckit = params[1].ToBool(pRuntime); @@ -2927,14 +2910,14 @@ bool Field::checkThisBox(IJS_EventContext* cc, return true; } -bool Field::clearItems(IJS_EventContext* cc, +bool Field::clearItems(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Field::defaultIsChecked(IJS_EventContext* cc, +bool Field::defaultIsChecked(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -2945,9 +2928,7 @@ bool Field::defaultIsChecked(IJS_EventContext* cc, if (iSize < 1) return false; - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int nWidget = params[0].ToInt(pRuntime); - std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2963,14 +2944,14 @@ bool Field::defaultIsChecked(IJS_EventContext* cc, return true; } -bool Field::deleteItemAt(IJS_EventContext* cc, +bool Field::deleteItemAt(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Field::getArray(IJS_EventContext* cc, +bool Field::getArray(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -2989,8 +2970,6 @@ bool Field::getArray(IJS_EventContext* cc, [](const std::unique_ptr& p1, const std::unique_ptr& p2) { return *p1 < *p2; }); - CJS_EventContext* pContext = (CJS_EventContext*)cc; - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CJS_Array FormFieldArray; int j = 0; @@ -3010,12 +2989,10 @@ bool Field::getArray(IJS_EventContext* cc, return true; } -bool Field::getItemAt(IJS_EventContext* cc, +bool Field::getItemAt(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - int iSize = params.size(); int nIdx = -1; if (iSize >= 1) @@ -3050,26 +3027,24 @@ bool Field::getItemAt(IJS_EventContext* cc, return true; } -bool Field::getLock(IJS_EventContext* cc, +bool Field::getLock(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool Field::insertItemAt(IJS_EventContext* cc, +bool Field::insertItemAt(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Field::isBoxChecked(IJS_EventContext* cc, +bool Field::isBoxChecked(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - int nIndex = -1; if (params.size() >= 1) nIndex = params[0].ToInt(pRuntime); @@ -3090,12 +3065,10 @@ bool Field::isBoxChecked(IJS_EventContext* cc, return true; } -bool Field::isDefaultChecked(IJS_EventContext* cc, +bool Field::isDefaultChecked(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - int nIndex = -1; if (params.size() >= 1) nIndex = params[0].ToInt(pRuntime); @@ -3115,14 +3088,14 @@ bool Field::isDefaultChecked(IJS_EventContext* cc, return true; } -bool Field::setAction(IJS_EventContext* cc, +bool Field::setAction(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Field::setFocus(IJS_EventContext* cc, +bool Field::setFocus(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -3167,63 +3140,63 @@ bool Field::setFocus(IJS_EventContext* cc, return true; } -bool Field::setItems(IJS_EventContext* cc, +bool Field::setItems(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool Field::setLock(IJS_EventContext* cc, +bool Field::setLock(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool Field::signatureGetModifications(IJS_EventContext* cc, +bool Field::signatureGetModifications(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool Field::signatureGetSeedValue(IJS_EventContext* cc, +bool Field::signatureGetSeedValue(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool Field::signatureInfo(IJS_EventContext* cc, +bool Field::signatureInfo(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool Field::signatureSetSeedValue(IJS_EventContext* cc, +bool Field::signatureSetSeedValue(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool Field::signatureSign(IJS_EventContext* cc, +bool Field::signatureSign(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool Field::signatureValidate(IJS_EventContext* cc, +bool Field::signatureValidate(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool Field::source(IJS_EventContext* cc, +bool Field::source(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { diff --git a/fpdfsdk/javascript/Field.h b/fpdfsdk/javascript/Field.h index 9087f82703..462c1271a1 100644 --- a/fpdfsdk/javascript/Field.h +++ b/fpdfsdk/javascript/Field.h @@ -77,238 +77,240 @@ class Field : public CJS_EmbedObj { explicit Field(CJS_Object* pJSObject); ~Field() override; - bool alignment(IJS_EventContext* cc, + bool alignment(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool borderStyle(IJS_EventContext* cc, + bool borderStyle(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool buttonAlignX(IJS_EventContext* cc, + bool buttonAlignX(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool buttonAlignY(IJS_EventContext* cc, + bool buttonAlignY(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool buttonFitBounds(IJS_EventContext* cc, + bool buttonFitBounds(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool buttonPosition(IJS_EventContext* cc, + bool buttonPosition(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool buttonScaleHow(IJS_EventContext* cc, + bool buttonScaleHow(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool buttonScaleWhen(IJS_EventContext* cc, + bool buttonScaleWhen(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool calcOrderIndex(IJS_EventContext* cc, + bool calcOrderIndex(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool charLimit(IJS_EventContext* cc, + bool charLimit(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool comb(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool commitOnSelChange(IJS_EventContext* cc, + bool comb(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool commitOnSelChange(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool currentValueIndices(IJS_EventContext* cc, + bool currentValueIndices(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool defaultStyle(IJS_EventContext* cc, + bool defaultStyle(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool defaultValue(IJS_EventContext* cc, + bool defaultValue(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool doNotScroll(IJS_EventContext* cc, + bool doNotScroll(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool doNotSpellCheck(IJS_EventContext* cc, + bool doNotSpellCheck(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool delay(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool display(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool doc(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool editable(IJS_EventContext* cc, + bool delay(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool display(CJS_Runtime* pRuntime, + CJS_PropValue& vp, + CFX_WideString& sError); + bool doc(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool editable(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool exportValues(IJS_EventContext* cc, + bool exportValues(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool fileSelect(IJS_EventContext* cc, + bool fileSelect(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool fillColor(IJS_EventContext* cc, + bool fillColor(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool hidden(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool highlight(IJS_EventContext* cc, + bool hidden(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool highlight(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool lineWidth(IJS_EventContext* cc, + bool lineWidth(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool multiline(IJS_EventContext* cc, + bool multiline(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool multipleSelection(IJS_EventContext* cc, + bool multipleSelection(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool name(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool numItems(IJS_EventContext* cc, + bool name(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool numItems(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool page(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool password(IJS_EventContext* cc, + bool page(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool password(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool print(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool radiosInUnison(IJS_EventContext* cc, + bool print(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool radiosInUnison(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool readonly(IJS_EventContext* cc, + bool readonly(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool rect(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool required(IJS_EventContext* cc, + bool rect(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool required(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool richText(IJS_EventContext* cc, + bool richText(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool richValue(IJS_EventContext* cc, + bool richValue(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool rotation(IJS_EventContext* cc, + bool rotation(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool strokeColor(IJS_EventContext* cc, + bool strokeColor(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool style(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool submitName(IJS_EventContext* cc, + bool style(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool submitName(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool textColor(IJS_EventContext* cc, + bool textColor(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool textFont(IJS_EventContext* cc, + bool textFont(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool textSize(IJS_EventContext* cc, + bool textSize(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool type(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool userName(IJS_EventContext* cc, + bool type(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool userName(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool value(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool valueAsString(IJS_EventContext* cc, + bool value(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool valueAsString(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool source(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); + bool source(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool browseForFileToSubmit(IJS_EventContext* cc, + bool browseForFileToSubmit(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool buttonGetCaption(IJS_EventContext* cc, + bool buttonGetCaption(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool buttonGetIcon(IJS_EventContext* cc, + bool buttonGetIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool buttonImportIcon(IJS_EventContext* cc, + bool buttonImportIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool buttonSetCaption(IJS_EventContext* cc, + bool buttonSetCaption(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool buttonSetIcon(IJS_EventContext* cc, + bool buttonSetIcon(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool checkThisBox(IJS_EventContext* cc, + bool checkThisBox(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool clearItems(IJS_EventContext* cc, + bool clearItems(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool defaultIsChecked(IJS_EventContext* cc, + bool defaultIsChecked(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool deleteItemAt(IJS_EventContext* cc, + bool deleteItemAt(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getArray(IJS_EventContext* cc, + bool getArray(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getItemAt(IJS_EventContext* cc, + bool getItemAt(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool getLock(IJS_EventContext* cc, + bool getLock(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool insertItemAt(IJS_EventContext* cc, + bool insertItemAt(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool isBoxChecked(IJS_EventContext* cc, + bool isBoxChecked(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool isDefaultChecked(IJS_EventContext* cc, + bool isDefaultChecked(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool setAction(IJS_EventContext* cc, + bool setAction(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool setFocus(IJS_EventContext* cc, + bool setFocus(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool setItems(IJS_EventContext* cc, + bool setItems(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool setLock(IJS_EventContext* cc, + bool setLock(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool signatureGetModifications(IJS_EventContext* cc, + bool signatureGetModifications(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool signatureGetSeedValue(IJS_EventContext* cc, + bool signatureGetSeedValue(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool signatureInfo(IJS_EventContext* cc, + bool signatureInfo(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool signatureSetSeedValue(IJS_EventContext* cc, + bool signatureSetSeedValue(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool signatureSign(IJS_EventContext* cc, + bool signatureSign(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool signatureValidate(IJS_EventContext* cc, + bool signatureValidate(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); diff --git a/fpdfsdk/javascript/Icon.cpp b/fpdfsdk/javascript/Icon.cpp index cfce52fd0e..778c1edb10 100644 --- a/fpdfsdk/javascript/Icon.cpp +++ b/fpdfsdk/javascript/Icon.cpp @@ -44,7 +44,7 @@ CFX_WideString Icon::GetIconName() { return m_swIconName; } -bool Icon::name(IJS_EventContext* cc, +bool Icon::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) diff --git a/fpdfsdk/javascript/Icon.h b/fpdfsdk/javascript/Icon.h index 76bf8e4a18..5a51f20410 100644 --- a/fpdfsdk/javascript/Icon.h +++ b/fpdfsdk/javascript/Icon.h @@ -16,7 +16,7 @@ class Icon : public CJS_EmbedObj { explicit Icon(CJS_Object* pJSObject); ~Icon() override; - bool name(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); + bool name(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); void SetStream(CPDF_Stream* pIconStream); CPDF_Stream* GetStream(); void SetIconName(CFX_WideString name); diff --git a/fpdfsdk/javascript/JS_Define.h b/fpdfsdk/javascript/JS_Define.h index 957f6836fc..718442cd9d 100644 --- a/fpdfsdk/javascript/JS_Define.h +++ b/fpdfsdk/javascript/JS_Define.h @@ -70,8 +70,7 @@ struct JSMethodSpec { } \ ; // NOLINT -template +template void JSPropGetter(const char* prop_name_string, const char* class_name_string, v8::Local property, @@ -86,7 +85,7 @@ void JSPropGetter(const char* prop_name_string, CFX_WideString sError; CJS_PropValue value(pRuntime); value.StartGetting(); - if (!(pObj->*M)(pRuntime->GetCurrentEventContext(), value, sError)) { + if (!(pObj->*M)(pRuntime, value, sError)) { pRuntime->Error( JSFormatErrorString(class_name_string, prop_name_string, sError)); return; @@ -94,8 +93,7 @@ void JSPropGetter(const char* prop_name_string, info.GetReturnValue().Set(value.GetJSValue()->ToV8Value(pRuntime)); } -template +template void JSPropSetter(const char* prop_name_string, const char* class_name_string, v8::Local property, @@ -111,7 +109,7 @@ void JSPropSetter(const char* prop_name_string, CFX_WideString sError; CJS_PropValue propValue(pRuntime, CJS_Value(pRuntime, value)); propValue.StartSetting(); - if (!(pObj->*M)(pRuntime->GetCurrentEventContext(), propValue, sError)) { + if (!(pObj->*M)(pRuntime, propValue, sError)) { pRuntime->Error( JSFormatErrorString(class_name_string, prop_name_string, sError)); } @@ -132,7 +130,7 @@ void JSPropSetter(const char* prop_name_string, } template &, CJS_Value&, CFX_WideString&)> @@ -152,8 +150,7 @@ void JSMethod(const char* method_name_string, C* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); CFX_WideString sError; CJS_Value valueRes(pRuntime); - if (!(pObj->*M)(pRuntime->GetCurrentEventContext(), parameters, valueRes, - sError)) { + if (!(pObj->*M)(pRuntime, parameters, valueRes, sError)) { pRuntime->Error( JSFormatErrorString(class_name_string, method_name_string, sError)); return; @@ -377,8 +374,7 @@ void JSSpecialPropGet(const char* class_name, CFX_WideString sError; CJS_PropValue value(pRuntime); value.StartGetting(); - if (!pObj->DoProperty(pRuntime->GetCurrentEventContext(), propname.c_str(), - value, sError)) { + if (!pObj->DoProperty(pRuntime, propname.c_str(), value, sError)) { pRuntime->Error(JSFormatErrorString(class_name, "GetProperty", sError)); return; } @@ -403,8 +399,7 @@ void JSSpecialPropPut(const char* class_name, CFX_WideString sError; CJS_PropValue PropValue(pRuntime, CJS_Value(pRuntime, value)); PropValue.StartSetting(); - if (!pObj->DoProperty(pRuntime->GetCurrentEventContext(), propname.c_str(), - PropValue, sError)) { + if (!pObj->DoProperty(pRuntime, propname.c_str(), PropValue, sError)) { pRuntime->Error(JSFormatErrorString(class_name, "PutProperty", sError)); } } @@ -424,15 +419,14 @@ void JSSpecialPropDel(const char* class_name, CFX_WideString propname = CFX_WideString::FromUTF8( CFX_ByteStringC(*utf8_value, utf8_value.length())); CFX_WideString sError; - if (!pObj->DelProperty(pRuntime->GetCurrentEventContext(), propname.c_str(), - sError)) { + if (!pObj->DelProperty(pRuntime, propname.c_str(), sError)) { CFX_ByteString cbName; cbName.Format("%s.%s", class_name, "DelProperty"); // Probably a missing call to JSFX_Error(). } } -template &, CJS_Value&, CFX_WideString&)> @@ -448,7 +442,7 @@ void JSGlobalFunc(const char* func_name_string, } CJS_Value valueRes(pRuntime); CFX_WideString sError; - if (!(*F)(pRuntime->GetCurrentEventContext(), parameters, valueRes, sError)) { + if (!(*F)(pRuntime, parameters, valueRes, sError)) { pRuntime->Error(JSFormatErrorString(func_name_string, nullptr, sError)); return; } diff --git a/fpdfsdk/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/javascript/JS_Runtime_Stub.cpp index 12edc1be3f..dcd8ceb97c 100644 --- a/fpdfsdk/javascript/JS_Runtime_Stub.cpp +++ b/fpdfsdk/javascript/JS_Runtime_Stub.cpp @@ -127,12 +127,9 @@ class CJS_RuntimeStub final : public IJS_Runtime { IJS_EventContext* NewEventContext() override { if (!m_pContext) m_pContext = pdfium::MakeUnique(); - return GetCurrentEventContext(); - } - - IJS_EventContext* GetCurrentEventContext() override { return m_pContext.get(); } + void ReleaseEventContext(IJS_EventContext* pContext) override {} CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override { diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index 32484d4813..7eee979c66 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -750,7 +750,7 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, // function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, // bCurrencyPrepend) -bool CJS_PublicMethods::AFNumber_Format(IJS_EventContext* cc, +bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -760,9 +760,8 @@ bool CJS_PublicMethods::AFNumber_Format(IJS_EventContext* cc, return false; } - CJS_EventContext* pContext = static_cast(cc); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (!pEvent->m_pValue) return false; @@ -855,7 +854,7 @@ bool CJS_PublicMethods::AFNumber_Format(IJS_EventContext* cc, vProp.StartGetting(); vProp << arColor; vProp.StartSetting(); - fTarget->textColor(cc, vProp, sError); // red + fTarget->textColor(pRuntime, vProp, sError); // red } } } else { @@ -872,7 +871,7 @@ bool CJS_PublicMethods::AFNumber_Format(IJS_EventContext* cc, CJS_PropValue vProp(pRuntime); vProp.StartGetting(); - fTarget->textColor(cc, vProp, sError); + fTarget->textColor(pRuntime, vProp, sError); CJS_Array aProp; vProp.GetJSValue()->ConvertToArray(pRuntime, aProp); @@ -887,7 +886,7 @@ bool CJS_PublicMethods::AFNumber_Format(IJS_EventContext* cc, vProp2.StartGetting(); vProp2 << arColor; vProp2.StartSetting(); - fTarget->textColor(cc, vProp2, sError); + fTarget->textColor(pRuntime, vProp2, sError); } } } @@ -898,16 +897,15 @@ bool CJS_PublicMethods::AFNumber_Format(IJS_EventContext* cc, // function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, // bCurrencyPrepend) -bool CJS_PublicMethods::AFNumber_Keystroke(IJS_EventContext* cc, +bool CJS_PublicMethods::AFNumber_Keystroke(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_EventContext* pContext = static_cast(cc); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - if (params.size() < 2) return false; + CJS_EventContext* pContext = pRuntime->GetCurrentEventContext(); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); if (!pEvent->m_pValue) return false; @@ -945,7 +943,6 @@ bool CJS_PublicMethods::AFNumber_Keystroke(IJS_EventContext* cc, } } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int iSepStyle = params[1].ToInt(pRuntime); if (iSepStyle < 0 || iSepStyle > 3) iSepStyle = 0; @@ -999,19 +996,18 @@ bool CJS_PublicMethods::AFNumber_Keystroke(IJS_EventContext* cc, } // function AFPercent_Format(nDec, sepStyle) -bool CJS_PublicMethods::AFPercent_Format(IJS_EventContext* cc, +bool CJS_PublicMethods::AFPercent_Format(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { #if _FX_OS_ != _FX_ANDROID_ - CJS_EventContext* pContext = static_cast(cc); - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - if (params.size() != 2) { sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return false; } + + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (!pEvent->m_pValue) return false; @@ -1092,26 +1088,25 @@ bool CJS_PublicMethods::AFPercent_Format(IJS_EventContext* cc, } // AFPercent_Keystroke(nDec, sepStyle) bool CJS_PublicMethods::AFPercent_Keystroke( - IJS_EventContext* cc, + CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - return AFNumber_Keystroke(cc, params, vRet, sError); + return AFNumber_Keystroke(pRuntime, params, vRet, sError); } // function AFDate_FormatEx(cFormat) -bool CJS_PublicMethods::AFDate_FormatEx(IJS_EventContext* cc, +bool CJS_PublicMethods::AFDate_FormatEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_EventContext* pContext = static_cast(cc); - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - if (params.size() != 1) { sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return false; } + + CJS_EventContext* pContext = pRuntime->GetCurrentEventContext(); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); if (!pEvent->m_pValue) return false; @@ -1200,22 +1195,21 @@ double CJS_PublicMethods::MakeInterDate(const CFX_WideString& strValue) { } // AFDate_KeystrokeEx(cFormat) -bool CJS_PublicMethods::AFDate_KeystrokeEx(IJS_EventContext* cc, +bool CJS_PublicMethods::AFDate_KeystrokeEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_EventContext* pContext = (CJS_EventContext*)cc; - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - if (params.size() != 1) { sError = L"AFDate_KeystrokeEx's parameters' size r not correct"; return false; } + CJS_EventContext* pContext = pRuntime->GetCurrentEventContext(); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); if (pEvent->WillCommit()) { if (!pEvent->m_pValue) return false; + CFX_WideString strValue = pEvent->Value(); if (strValue.IsEmpty()) return true; @@ -1235,7 +1229,7 @@ bool CJS_PublicMethods::AFDate_KeystrokeEx(IJS_EventContext* cc, return true; } -bool CJS_PublicMethods::AFDate_Format(IJS_EventContext* cc, +bool CJS_PublicMethods::AFDate_Format(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1244,7 +1238,6 @@ bool CJS_PublicMethods::AFDate_Format(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int iIndex = params[0].ToInt(pRuntime); const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", @@ -1265,13 +1258,12 @@ bool CJS_PublicMethods::AFDate_Format(IJS_EventContext* cc, iIndex = 0; std::vector newParams; - newParams.push_back( - CJS_Value(CJS_Runtime::FromEventContext(cc), cFormats[iIndex])); - return AFDate_FormatEx(cc, newParams, vRet, sError); + newParams.push_back(CJS_Value(pRuntime, cFormats[iIndex])); + return AFDate_FormatEx(pRuntime, newParams, vRet, sError); } // AFDate_KeystrokeEx(cFormat) -bool CJS_PublicMethods::AFDate_Keystroke(IJS_EventContext* cc, +bool CJS_PublicMethods::AFDate_Keystroke(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1280,7 +1272,6 @@ bool CJS_PublicMethods::AFDate_Keystroke(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int iIndex = params[0].ToInt(pRuntime); const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", @@ -1301,13 +1292,12 @@ bool CJS_PublicMethods::AFDate_Keystroke(IJS_EventContext* cc, iIndex = 0; std::vector newParams; - newParams.push_back( - CJS_Value(CJS_Runtime::FromEventContext(cc), cFormats[iIndex])); - return AFDate_KeystrokeEx(cc, newParams, vRet, sError); + newParams.push_back(CJS_Value(pRuntime, cFormats[iIndex])); + return AFDate_KeystrokeEx(pRuntime, newParams, vRet, sError); } // function AFTime_Format(ptf) -bool CJS_PublicMethods::AFTime_Format(IJS_EventContext* cc, +bool CJS_PublicMethods::AFTime_Format(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1316,7 +1306,6 @@ bool CJS_PublicMethods::AFTime_Format(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int iIndex = params[0].ToInt(pRuntime); const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"}; @@ -1325,12 +1314,11 @@ bool CJS_PublicMethods::AFTime_Format(IJS_EventContext* cc, iIndex = 0; std::vector newParams; - newParams.push_back( - CJS_Value(CJS_Runtime::FromEventContext(cc), cFormats[iIndex])); - return AFDate_FormatEx(cc, newParams, vRet, sError); + newParams.push_back(CJS_Value(pRuntime, cFormats[iIndex])); + return AFDate_FormatEx(pRuntime, newParams, vRet, sError); } -bool CJS_PublicMethods::AFTime_Keystroke(IJS_EventContext* cc, +bool CJS_PublicMethods::AFTime_Keystroke(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1339,7 +1327,6 @@ bool CJS_PublicMethods::AFTime_Keystroke(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int iIndex = params[0].ToInt(pRuntime); const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"}; @@ -1348,27 +1335,26 @@ bool CJS_PublicMethods::AFTime_Keystroke(IJS_EventContext* cc, iIndex = 0; std::vector newParams; - newParams.push_back( - CJS_Value(CJS_Runtime::FromEventContext(cc), cFormats[iIndex])); - return AFDate_KeystrokeEx(cc, newParams, vRet, sError); + newParams.push_back(CJS_Value(pRuntime, cFormats[iIndex])); + return AFDate_KeystrokeEx(pRuntime, newParams, vRet, sError); } -bool CJS_PublicMethods::AFTime_FormatEx(IJS_EventContext* cc, +bool CJS_PublicMethods::AFTime_FormatEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - return AFDate_FormatEx(cc, params, vRet, sError); + return AFDate_FormatEx(pRuntime, params, vRet, sError); } -bool CJS_PublicMethods::AFTime_KeystrokeEx(IJS_EventContext* cc, +bool CJS_PublicMethods::AFTime_KeystrokeEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - return AFDate_KeystrokeEx(cc, params, vRet, sError); + return AFDate_KeystrokeEx(pRuntime, params, vRet, sError); } // function AFSpecial_Format(psf) -bool CJS_PublicMethods::AFSpecial_Format(IJS_EventContext* cc, +bool CJS_PublicMethods::AFSpecial_Format(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1377,12 +1363,11 @@ bool CJS_PublicMethods::AFSpecial_Format(IJS_EventContext* cc, return false; } - CJS_EventContext* pContext = static_cast(cc); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (!pEvent->m_pValue) return false; - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CFX_WideString wsSource = pEvent->Value(); CFX_WideString wsFormat; switch (params[0].ToInt(pRuntime)) { @@ -1409,19 +1394,17 @@ bool CJS_PublicMethods::AFSpecial_Format(IJS_EventContext* cc, // function AFSpecial_KeystrokeEx(mask) bool CJS_PublicMethods::AFSpecial_KeystrokeEx( - IJS_EventContext* cc, + CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_EventContext* pContext = (CJS_EventContext*)cc; - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - if (params.size() < 1) { sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return false; } + CJS_EventContext* pContext = pRuntime->GetCurrentEventContext(); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); if (!pEvent->m_pValue) return false; @@ -1494,7 +1477,7 @@ bool CJS_PublicMethods::AFSpecial_KeystrokeEx( // function AFSpecial_Keystroke(psf) bool CJS_PublicMethods::AFSpecial_Keystroke( - IJS_EventContext* cc, + CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1503,13 +1486,12 @@ bool CJS_PublicMethods::AFSpecial_Keystroke( return false; } - CJS_EventContext* pContext = static_cast(cc); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (!pEvent->m_pValue) return false; const char* cFormat = ""; - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); switch (params[0].ToInt(pRuntime)) { case 0: cFormat = "99999"; @@ -1529,11 +1511,11 @@ bool CJS_PublicMethods::AFSpecial_Keystroke( } std::vector params2; - params2.push_back(CJS_Value(CJS_Runtime::FromEventContext(cc), cFormat)); - return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); + params2.push_back(CJS_Value(pRuntime, cFormat)); + return AFSpecial_KeystrokeEx(pRuntime, params2, vRet, sError); } -bool CJS_PublicMethods::AFMergeChange(IJS_EventContext* cc, +bool CJS_PublicMethods::AFMergeChange(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1542,9 +1524,8 @@ bool CJS_PublicMethods::AFMergeChange(IJS_EventContext* cc, return false; } - CJS_EventContext* pContext = static_cast(cc); - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); - CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); + CJS_EventHandler* pEventHandler = + pRuntime->GetCurrentEventContext()->GetEventHandler(); CFX_WideString swValue; if (pEventHandler->m_pValue) @@ -1574,7 +1555,7 @@ bool CJS_PublicMethods::AFMergeChange(IJS_EventContext* cc, return true; } -bool CJS_PublicMethods::AFParseDateEx(IJS_EventContext* cc, +bool CJS_PublicMethods::AFParseDateEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1583,8 +1564,6 @@ bool CJS_PublicMethods::AFParseDateEx(IJS_EventContext* cc, return false; } - CJS_EventContext* pContext = static_cast(cc); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CFX_WideString sValue = params[0].ToCFXWideString(pRuntime); CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime); double dDate = MakeRegularDate(sValue, sFormat, nullptr); @@ -1592,7 +1571,7 @@ bool CJS_PublicMethods::AFParseDateEx(IJS_EventContext* cc, CFX_WideString swMsg; swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str()); - AlertIfPossible(pContext, swMsg.c_str()); + AlertIfPossible(pRuntime->GetCurrentEventContext(), swMsg.c_str()); return false; } @@ -1600,7 +1579,7 @@ bool CJS_PublicMethods::AFParseDateEx(IJS_EventContext* cc, return true; } -bool CJS_PublicMethods::AFSimple(IJS_EventContext* cc, +bool CJS_PublicMethods::AFSimple(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1609,7 +1588,6 @@ bool CJS_PublicMethods::AFSimple(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); vRet = CJS_Value(pRuntime, static_cast(AF_Simple( params[0].ToCFXWideString(pRuntime).c_str(), params[1].ToDouble(pRuntime), @@ -1618,7 +1596,7 @@ bool CJS_PublicMethods::AFSimple(IJS_EventContext* cc, return true; } -bool CJS_PublicMethods::AFMakeNumber(IJS_EventContext* cc, +bool CJS_PublicMethods::AFMakeNumber(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1627,7 +1605,6 @@ bool CJS_PublicMethods::AFMakeNumber(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CFX_WideString ws = params[0].ToCFXWideString(pRuntime); ws.Replace(L",", L"."); vRet = CJS_Value(pRuntime, ws.c_str()); @@ -1637,7 +1614,7 @@ bool CJS_PublicMethods::AFMakeNumber(IJS_EventContext* cc, return true; } -bool CJS_PublicMethods::AFSimple_Calculate(IJS_EventContext* cc, +bool CJS_PublicMethods::AFSimple_Calculate(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1652,10 +1629,8 @@ bool CJS_PublicMethods::AFSimple_Calculate(IJS_EventContext* cc, return false; } - CJS_EventContext* pContext = static_cast(cc); - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CPDFSDK_InterForm* pReaderInterForm = - pContext->GetFormFillEnv()->GetInterForm(); + pRuntime->GetFormFillEnv()->GetInterForm(); CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime); @@ -1726,7 +1701,9 @@ bool CJS_PublicMethods::AFSimple_Calculate(IJS_EventContext* cc, dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / FXSYS_pow((double)10, (double)6); + CJS_Value jsValue(pRuntime, dValue); + CJS_EventContext* pContext = pRuntime->GetCurrentEventContext(); if (pContext->GetEventHandler()->m_pValue) pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(pRuntime); @@ -1736,7 +1713,7 @@ bool CJS_PublicMethods::AFSimple_Calculate(IJS_EventContext* cc, /* This function validates the current event to ensure that its value is ** within the specified range. */ -bool CJS_PublicMethods::AFRange_Validate(IJS_EventContext* cc, +bool CJS_PublicMethods::AFRange_Validate(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1744,8 +1721,7 @@ bool CJS_PublicMethods::AFRange_Validate(IJS_EventContext* cc, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return false; } - CJS_EventContext* pContext = static_cast(cc); - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); + CJS_EventContext* pContext = pRuntime->GetCurrentEventContext(); CJS_EventHandler* pEvent = pContext->GetEventHandler(); if (!pEvent->m_pValue) return false; @@ -1783,7 +1759,7 @@ bool CJS_PublicMethods::AFRange_Validate(IJS_EventContext* cc, return true; } -bool CJS_PublicMethods::AFExtractNums(IJS_EventContext* cc, +bool CJS_PublicMethods::AFExtractNums(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -1792,14 +1768,12 @@ bool CJS_PublicMethods::AFExtractNums(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(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; + CFX_WideString sPart; + CJS_Array nums; int nIndex = 0; for (int i = 0, sz = str.GetLength(); i < sz; i++) { FX_WCHAR wc = str.GetAt(i); diff --git a/fpdfsdk/javascript/PublicMethods.h b/fpdfsdk/javascript/PublicMethods.h index bb01ea33cb..060c74303a 100644 --- a/fpdfsdk/javascript/PublicMethods.h +++ b/fpdfsdk/javascript/PublicMethods.h @@ -18,91 +18,91 @@ class CJS_PublicMethods : public CJS_Object { : CJS_Object(pObject) {} ~CJS_PublicMethods() override {} - static bool AFNumber_Format(IJS_EventContext* cc, + static bool AFNumber_Format(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFNumber_Keystroke(IJS_EventContext* cc, + static bool AFNumber_Keystroke(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFPercent_Format(IJS_EventContext* cc, + static bool AFPercent_Format(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFPercent_Keystroke(IJS_EventContext* cc, + static bool AFPercent_Keystroke(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFDate_FormatEx(IJS_EventContext* cc, + static bool AFDate_FormatEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFDate_KeystrokeEx(IJS_EventContext* cc, + static bool AFDate_KeystrokeEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFDate_Format(IJS_EventContext* cc, + static bool AFDate_Format(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFDate_Keystroke(IJS_EventContext* cc, + static bool AFDate_Keystroke(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFTime_FormatEx(IJS_EventContext* cc, + static bool AFTime_FormatEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); // - static bool AFTime_KeystrokeEx(IJS_EventContext* cc, + static bool AFTime_KeystrokeEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFTime_Format(IJS_EventContext* cc, + static bool AFTime_Format(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFTime_Keystroke(IJS_EventContext* cc, + static bool AFTime_Keystroke(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFSpecial_Format(IJS_EventContext* cc, + static bool AFSpecial_Format(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFSpecial_Keystroke(IJS_EventContext* cc, + static bool AFSpecial_Keystroke(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFSpecial_KeystrokeEx(IJS_EventContext* cc, + static bool AFSpecial_KeystrokeEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); // - static bool AFSimple(IJS_EventContext* cc, + static bool AFSimple(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFMakeNumber(IJS_EventContext* cc, + static bool AFMakeNumber(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFSimple_Calculate(IJS_EventContext* cc, + static bool AFSimple_Calculate(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFRange_Validate(IJS_EventContext* cc, + static bool AFRange_Validate(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFMergeChange(IJS_EventContext* cc, + static bool AFMergeChange(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFParseDateEx(IJS_EventContext* cc, + static bool AFParseDateEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - static bool AFExtractNums(IJS_EventContext* cc, + static bool AFExtractNums(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index 6de4d2025f..dfd2cc11d7 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -211,14 +211,12 @@ app::app(CJS_Object* pJSObject) app::~app() { } -bool app::activeDocs(IJS_EventContext* cc, +bool app::activeDocs(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; - CJS_EventContext* pContext = static_cast(cc); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CJS_Document* pJSDocument = nullptr; v8::Local pObj = pRuntime->GetThisObj(); if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) { @@ -236,16 +234,14 @@ bool app::activeDocs(IJS_EventContext* cc, return true; } -bool app::calculate(IJS_EventContext* cc, +bool app::calculate(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { bool bVP; vp >> bVP; m_bCalculate = (bool)bVP; - - CJS_EventContext* pContext = static_cast(cc); - pContext->GetFormFillEnv()->GetInterForm()->EnableCalculate( + pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate( (bool)m_bCalculate); } else { vp << (bool)m_bCalculate; @@ -253,7 +249,7 @@ bool app::calculate(IJS_EventContext* cc, return true; } -bool app::formsVersion(IJS_EventContext* cc, +bool app::formsVersion(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { @@ -264,7 +260,7 @@ bool app::formsVersion(IJS_EventContext* cc, return false; } -bool app::viewerType(IJS_EventContext* cc, +bool app::viewerType(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { @@ -275,7 +271,7 @@ bool app::viewerType(IJS_EventContext* cc, return false; } -bool app::viewerVariation(IJS_EventContext* cc, +bool app::viewerVariation(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { @@ -286,14 +282,13 @@ bool app::viewerVariation(IJS_EventContext* cc, return false; } -bool app::viewerVersion(IJS_EventContext* cc, +bool app::viewerVersion(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; #ifdef PDF_ENABLE_XFA - CJS_EventContext* pJSContext = static_cast(cc); - CPDFXFA_Context* pXFAContext = pJSContext->GetFormFillEnv()->GetXFAContext(); + CPDFXFA_Context* pXFAContext = pRuntime->GetFormFillEnv()->GetXFAContext(); if (pXFAContext->GetDocType() == 1 || pXFAContext->GetDocType() == 2) { vp << JS_NUM_VIEWERVERSION_XFA; return true; @@ -303,14 +298,13 @@ bool app::viewerVersion(IJS_EventContext* cc, return true; } -bool app::platform(IJS_EventContext* cc, +bool app::platform(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; #ifdef PDF_ENABLE_XFA - CPDFSDK_FormFillEnvironment* pFormFillEnv = - CJS_Runtime::FromEventContext(cc)->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); if (!pFormFillEnv) return false; CFX_WideString platfrom = pFormFillEnv->GetPlatform(); @@ -323,14 +317,13 @@ bool app::platform(IJS_EventContext* cc, return true; } -bool app::language(IJS_EventContext* cc, +bool app::language(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; #ifdef PDF_ENABLE_XFA - CPDFSDK_FormFillEnvironment* pFormFillEnv = - CJS_Runtime::FromEventContext(cc)->GetFormFillEnv(); + CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); if (!pFormFillEnv) return false; CFX_WideString language = pFormFillEnv->GetLanguage(); @@ -347,7 +340,7 @@ bool app::language(IJS_EventContext* cc, // comment: need reader support // note: // CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF(); -bool app::newFDF(IJS_EventContext* cc, +bool app::newFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -360,18 +353,17 @@ bool app::newFDF(IJS_EventContext* cc, // CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool // bUserConv); -bool app::openFDF(IJS_EventContext* cc, +bool app::openFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool app::alert(IJS_EventContext* cc, +bool app::alert(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); std::vector newParams = JS_ExpandKeywordParams( pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); @@ -429,12 +421,11 @@ bool app::alert(IJS_EventContext* cc, return true; } -bool app::beep(IJS_EventContext* cc, +bool app::beep(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { if (params.size() == 1) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime)); return true; } @@ -443,25 +434,25 @@ bool app::beep(IJS_EventContext* cc, return false; } -bool app::findComponent(IJS_EventContext* cc, +bool app::findComponent(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool app::popUpMenuEx(IJS_EventContext* cc, +bool app::popUpMenuEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool app::fs(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError) { +bool app::fs(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return false; } -bool app::setInterval(IJS_EventContext* cc, +bool app::setInterval(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -470,7 +461,6 @@ bool app::setInterval(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L""; if (script.IsEmpty()) { @@ -495,7 +485,7 @@ bool app::setInterval(IJS_EventContext* cc, return true; } -bool app::setTimeOut(IJS_EventContext* cc, +bool app::setTimeOut(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -504,7 +494,6 @@ bool app::setTimeOut(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CFX_WideString script = params[0].ToCFXWideString(pRuntime); if (script.IsEmpty()) { sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); @@ -530,7 +519,7 @@ bool app::setTimeOut(IJS_EventContext* cc, return true; } -bool app::clearTimeOut(IJS_EventContext* cc, +bool app::clearTimeOut(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -539,11 +528,11 @@ bool app::clearTimeOut(IJS_EventContext* cc, return false; } - app::ClearTimerCommon(CJS_Runtime::FromEventContext(cc), params[0]); + app::ClearTimerCommon(pRuntime, params[0]); return true; } -bool app::clearInterval(IJS_EventContext* cc, +bool app::clearInterval(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -552,7 +541,7 @@ bool app::clearInterval(IJS_EventContext* cc, return false; } - app::ClearTimerCommon(CJS_Runtime::FromEventContext(cc), params[0]); + app::ClearTimerCommon(pRuntime, params[0]); return true; } @@ -575,7 +564,7 @@ void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) { GlobalTimer::Cancel(pTimerObj->GetTimerID()); } -bool app::execMenuItem(IJS_EventContext* cc, +bool app::execMenuItem(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -602,7 +591,7 @@ void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) { } } -bool app::goBack(IJS_EventContext* cc, +bool app::goBack(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -610,7 +599,7 @@ bool app::goBack(IJS_EventContext* cc, return true; } -bool app::goForward(IJS_EventContext* cc, +bool app::goForward(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -618,11 +607,10 @@ bool app::goForward(IJS_EventContext* cc, return true; } -bool app::mailMsg(IJS_EventContext* cc, +bool app::mailMsg(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); std::vector newParams = JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc", L"cSubject", L"cMsg"); @@ -661,15 +649,14 @@ bool app::mailMsg(IJS_EventContext* cc, cMsg = newParams[5].ToCFXWideString(pRuntime); pRuntime->BeginBlock(); - CJS_EventContext* pContext = static_cast(cc); - pContext->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), + pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str()); pRuntime->EndBlock(); return true; } -bool app::launchURL(IJS_EventContext* cc, +bool app::launchURL(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -677,7 +664,7 @@ bool app::launchURL(IJS_EventContext* cc, return true; } -bool app::runtimeHighlight(IJS_EventContext* cc, +bool app::runtimeHighlight(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { @@ -688,20 +675,20 @@ bool app::runtimeHighlight(IJS_EventContext* cc, return true; } -bool app::fullscreen(IJS_EventContext* cc, +bool app::fullscreen(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return false; } -bool app::popUpMenu(IJS_EventContext* cc, +bool app::popUpMenu(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool app::browseForDoc(IJS_EventContext* cc, +bool app::browseForDoc(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -727,25 +714,24 @@ CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) { return sRet; } -bool app::newDoc(IJS_EventContext* cc, +bool app::newDoc(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool app::openDoc(IJS_EventContext* cc, +bool app::openDoc(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return false; } -bool app::response(IJS_EventContext* cc, +bool app::response(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); std::vector newParams = JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", L"cDefault", L"bPassword", L"cLabel"); @@ -776,8 +762,7 @@ bool app::response(IJS_EventContext* cc, std::unique_ptr pBuff(new char[MAX_INPUT_BYTES + 2]); memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); - CJS_EventContext* pContext = static_cast(cc); - int nLengthBytes = pContext->GetFormFillEnv()->JS_appResponse( + int nLengthBytes = pRuntime->GetFormFillEnv()->JS_appResponse( swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), bPassword, pBuff.get(), MAX_INPUT_BYTES); @@ -794,13 +779,13 @@ bool app::response(IJS_EventContext* cc, return true; } -bool app::media(IJS_EventContext* cc, +bool app::media(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return false; } -bool app::execDialog(IJS_EventContext* cc, +bool app::execDialog(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { diff --git a/fpdfsdk/javascript/app.h b/fpdfsdk/javascript/app.h index 6cd68d3813..9e11b82419 100644 --- a/fpdfsdk/javascript/app.h +++ b/fpdfsdk/javascript/app.h @@ -41,120 +41,120 @@ class app : public CJS_EmbedObj { explicit app(CJS_Object* pJSObject); ~app() override; - bool activeDocs(IJS_EventContext* cc, + bool activeDocs(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool calculate(IJS_EventContext* cc, + bool calculate(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool formsVersion(IJS_EventContext* cc, + bool formsVersion(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool fs(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool fullscreen(IJS_EventContext* cc, + bool fs(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool fullscreen(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool language(IJS_EventContext* cc, + bool language(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool media(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool platform(IJS_EventContext* cc, + bool media(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool platform(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool runtimeHighlight(IJS_EventContext* cc, + bool runtimeHighlight(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool viewerType(IJS_EventContext* cc, + bool viewerType(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool viewerVariation(IJS_EventContext* cc, + bool viewerVariation(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool viewerVersion(IJS_EventContext* cc, + bool viewerVersion(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool alert(IJS_EventContext* cc, + bool alert(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool beep(IJS_EventContext* cc, + bool beep(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool browseForDoc(IJS_EventContext* cc, + bool browseForDoc(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool clearInterval(IJS_EventContext* cc, + bool clearInterval(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool clearTimeOut(IJS_EventContext* cc, + bool clearTimeOut(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool execDialog(IJS_EventContext* cc, + bool execDialog(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool execMenuItem(IJS_EventContext* cc, + bool execMenuItem(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool findComponent(IJS_EventContext* cc, + bool findComponent(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool goBack(IJS_EventContext* cc, + bool goBack(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool goForward(IJS_EventContext* cc, + bool goForward(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool launchURL(IJS_EventContext* cc, + bool launchURL(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool mailMsg(IJS_EventContext* cc, + bool mailMsg(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool newFDF(IJS_EventContext* cc, + bool newFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool newDoc(IJS_EventContext* cc, + bool newDoc(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool openDoc(IJS_EventContext* cc, + bool openDoc(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool openFDF(IJS_EventContext* cc, + bool openFDF(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool popUpMenuEx(IJS_EventContext* cc, + bool popUpMenuEx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool popUpMenu(IJS_EventContext* cc, + bool popUpMenu(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool response(IJS_EventContext* cc, + bool response(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool setInterval(IJS_EventContext* cc, + bool setInterval(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool setTimeOut(IJS_EventContext* cc, + bool setTimeOut(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index bf50ca92c6..8466e4d3fd 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -50,11 +50,6 @@ IJS_Runtime* IJS_Runtime::Create(CPDFSDK_FormFillEnvironment* pFormFillEnv) { return new CJS_Runtime(pFormFillEnv); } -// static -CJS_Runtime* CJS_Runtime::FromEventContext(const IJS_EventContext* cc) { - return static_cast(cc)->GetJSRuntime(); -} - // static CJS_Runtime* CJS_Runtime::CurrentRuntimeFromIsolate(v8::Isolate* pIsolate) { return static_cast( @@ -165,7 +160,7 @@ void CJS_Runtime::ReleaseEventContext(IJS_EventContext* pContext) { m_EventContextArray.erase(it); } -IJS_EventContext* CJS_Runtime::GetCurrentEventContext() { +CJS_EventContext* CJS_Runtime::GetCurrentEventContext() const { return m_EventContextArray.empty() ? nullptr : m_EventContextArray.back().get(); } diff --git a/fpdfsdk/javascript/cjs_runtime.h b/fpdfsdk/javascript/cjs_runtime.h index 96b171b41e..039e24b63e 100644 --- a/fpdfsdk/javascript/cjs_runtime.h +++ b/fpdfsdk/javascript/cjs_runtime.h @@ -27,7 +27,6 @@ class CJS_Runtime : public IJS_Runtime, public: using FieldEvent = std::pair; - static CJS_Runtime* FromEventContext(const IJS_EventContext* cc); static CJS_Runtime* CurrentRuntimeFromIsolate(v8::Isolate* pIsolate); explicit CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv); @@ -36,11 +35,12 @@ class CJS_Runtime : public IJS_Runtime, // IJS_Runtime IJS_EventContext* NewEventContext() override; void ReleaseEventContext(IJS_EventContext* pContext) override; - IJS_EventContext* GetCurrentEventContext() override; CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override; int ExecuteScript(const CFX_WideString& script, CFX_WideString* info) override; + CJS_EventContext* GetCurrentEventContext() const; + // Returns true if the event isn't already found in the set. bool AddEventToSet(const FieldEvent& event); void RemoveEventFromSet(const FieldEvent& event); diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp index be26987ff7..90a8495b86 100644 --- a/fpdfsdk/javascript/color.cpp +++ b/fpdfsdk/javascript/color.cpp @@ -133,20 +133,19 @@ void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, } } -#define JS_IMPLEMENT_COLORPROP(prop, var) \ - bool color::prop(IJS_EventContext* cc, CJS_PropValue& vp, \ - CFX_WideString& sError) { \ - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); \ - CJS_Array array; \ - if (vp.IsGetting()) { \ - ConvertPWLColorToArray(pRuntime, var, &array); \ - vp << array; \ - } else { \ - if (!vp.GetJSValue()->ConvertToArray(pRuntime, array)) \ - return false; \ - ConvertArrayToPWLColor(pRuntime, array, &var); \ - } \ - return true; \ +#define JS_IMPLEMENT_COLORPROP(prop, var) \ + bool color::prop(CJS_Runtime* pRuntime, CJS_PropValue& vp, \ + CFX_WideString& sError) { \ + CJS_Array array; \ + if (vp.IsGetting()) { \ + ConvertPWLColorToArray(pRuntime, var, &array); \ + vp << array; \ + } else { \ + if (!vp.GetJSValue()->ConvertToArray(pRuntime, array)) \ + return false; \ + ConvertArrayToPWLColor(pRuntime, array, &var); \ + } \ + return true; \ } JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent) @@ -162,7 +161,7 @@ JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray) JS_IMPLEMENT_COLORPROP(gray, m_crGray) JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray) -bool color::convert(IJS_EventContext* cc, +bool color::convert(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -170,7 +169,6 @@ bool color::convert(IJS_EventContext* cc, if (iSize < 2) return false; - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CJS_Array aSource; if (!params[0].ConvertToArray(pRuntime, aSource)) return false; @@ -200,14 +198,13 @@ bool color::convert(IJS_EventContext* cc, return true; } -bool color::equal(IJS_EventContext* cc, +bool color::equal(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { if (params.size() < 2) return false; - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CJS_Array array1; CJS_Array array2; if (!params[0].ConvertToArray(pRuntime, array1)) diff --git a/fpdfsdk/javascript/color.h b/fpdfsdk/javascript/color.h index df53b4ab52..f966ca76d1 100644 --- a/fpdfsdk/javascript/color.h +++ b/fpdfsdk/javascript/color.h @@ -17,26 +17,28 @@ class color : public CJS_EmbedObj { explicit color(CJS_Object* pJSObject); ~color() override; - bool black(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool blue(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool cyan(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool dkGray(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool gray(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool green(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool ltGray(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool magenta(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool red(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool transparent(IJS_EventContext* cc, + bool black(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool blue(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool cyan(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool dkGray(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool gray(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool green(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool ltGray(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool magenta(CJS_Runtime* pRuntime, + CJS_PropValue& vp, + CFX_WideString& sError); + bool red(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool transparent(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool white(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool yellow(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); + bool white(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool yellow(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool convert(IJS_EventContext* cc, + bool convert(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool equal(IJS_EventContext* cc, + bool equal(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); diff --git a/fpdfsdk/javascript/console.cpp b/fpdfsdk/javascript/console.cpp index 538a4ef858..fdef98f34f 100644 --- a/fpdfsdk/javascript/console.cpp +++ b/fpdfsdk/javascript/console.cpp @@ -33,21 +33,21 @@ console::console(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} console::~console() {} -bool console::clear(IJS_EventContext* cc, +bool console::clear(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool console::hide(IJS_EventContext* cc, +bool console::hide(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { return true; } -bool console::println(IJS_EventContext* cc, +bool console::println(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -57,7 +57,7 @@ bool console::println(IJS_EventContext* cc, return true; } -bool console::show(IJS_EventContext* cc, +bool console::show(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { diff --git a/fpdfsdk/javascript/console.h b/fpdfsdk/javascript/console.h index 1b6e9dd362..a7e4d8ed9b 100644 --- a/fpdfsdk/javascript/console.h +++ b/fpdfsdk/javascript/console.h @@ -17,19 +17,19 @@ class console : public CJS_EmbedObj { ~console() override; public: - bool clear(IJS_EventContext* cc, + bool clear(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool hide(IJS_EventContext* cc, + bool hide(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool println(IJS_EventContext* cc, + bool println(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool show(IJS_EventContext* cc, + bool show(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); diff --git a/fpdfsdk/javascript/event.cpp b/fpdfsdk/javascript/event.cpp index 48f3ce8a9c..88dce4b36a 100644 --- a/fpdfsdk/javascript/event.cpp +++ b/fpdfsdk/javascript/event.cpp @@ -48,11 +48,11 @@ event::event(CJS_Object* pJsObject) : CJS_EmbedObj(pJsObject) {} event::~event() {} -bool event::change(IJS_EventContext* cc, +bool event::change(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); CFX_WideString& wChange = pEvent->Change(); if (vp.IsSetting()) { if (vp.GetJSValue()->GetType() == CJS_Value::VT_string) @@ -63,99 +63,90 @@ bool event::change(IJS_EventContext* cc, return true; } -bool event::changeEx(IJS_EventContext* cc, +bool event::changeEx(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->ChangeEx(); return true; } -bool event::commitKey(IJS_EventContext* cc, +bool event::commitKey(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->CommitKey(); return true; } -bool event::fieldFull(IJS_EventContext* cc, +bool event::fieldFull(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (!vp.IsGetting() && wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return false; - if (pEvent->FieldFull()) - vp << true; - else - vp << false; + vp << pEvent->FieldFull(); return true; } -bool event::keyDown(IJS_EventContext* cc, +bool event::keyDown(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); - if (pEvent->KeyDown()) - vp << true; - else - vp << false; + vp << pEvent->KeyDown(); return true; } -bool event::modifier(IJS_EventContext* cc, +bool event::modifier(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); - if (pEvent->Modifier()) - vp << true; - else - vp << false; + vp << pEvent->Modifier(); return true; } -bool event::name(IJS_EventContext* cc, +bool event::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->Name(); return true; } -bool event::rc(IJS_EventContext* cc, +bool event::rc(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); bool& bRc = pEvent->Rc(); if (vp.IsSetting()) @@ -166,29 +157,29 @@ bool event::rc(IJS_EventContext* cc, return true; } -bool event::richChange(IJS_EventContext* cc, +bool event::richChange(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool event::richChangeEx(IJS_EventContext* cc, +bool event::richChangeEx(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool event::richValue(IJS_EventContext* cc, +bool event::richValue(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool event::selEnd(IJS_EventContext* cc, +bool event::selEnd(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return true; @@ -202,11 +193,11 @@ bool event::selEnd(IJS_EventContext* cc, return true; } -bool event::selStart(IJS_EventContext* cc, +bool event::selStart(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return true; @@ -220,79 +211,76 @@ bool event::selStart(IJS_EventContext* cc, return true; } -bool event::shift(IJS_EventContext* cc, +bool event::shift(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); - if (pEvent->Shift()) - vp << true; - else - vp << false; + vp << pEvent->Shift(); return true; } -bool event::source(IJS_EventContext* cc, +bool event::source(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->Source()->GetJSObject(); return true; } -bool event::target(IJS_EventContext* cc, +bool event::target(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->Target_Field()->GetJSObject(); return true; } -bool event::targetName(IJS_EventContext* cc, +bool event::targetName(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; - CJS_EventContext* pContext = (CJS_EventContext*)cc; - CJS_EventHandler* pEvent = pContext->GetEventHandler(); + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->TargetName(); return true; } -bool event::type(IJS_EventContext* cc, +bool event::type(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->Type(); return true; } -bool event::value(IJS_EventContext* cc, +bool event::value(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0) return false; @@ -309,19 +297,15 @@ bool event::value(IJS_EventContext* cc, return true; } -bool event::willCommit(IJS_EventContext* cc, +bool event::willCommit(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast(cc)->GetEventHandler(); - - if (pEvent->WillCommit()) - vp << true; - else - vp << false; + pRuntime->GetCurrentEventContext()->GetEventHandler(); + vp << pEvent->WillCommit(); return true; } diff --git a/fpdfsdk/javascript/event.h b/fpdfsdk/javascript/event.h index 54ba3f0a07..2be8a0adb2 100644 --- a/fpdfsdk/javascript/event.h +++ b/fpdfsdk/javascript/event.h @@ -15,44 +15,46 @@ class event : public CJS_EmbedObj { ~event() override; public: - bool change(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool changeEx(IJS_EventContext* cc, + bool change(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool changeEx(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool commitKey(IJS_EventContext* cc, + bool commitKey(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool fieldFull(IJS_EventContext* cc, + bool fieldFull(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool keyDown(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool modifier(IJS_EventContext* cc, + bool keyDown(CJS_Runtime* pRuntime, + CJS_PropValue& vp, + CFX_WideString& sError); + bool modifier(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool name(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool rc(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool richChange(IJS_EventContext* cc, + bool name(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool rc(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool richChange(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool richChangeEx(IJS_EventContext* cc, + bool richChangeEx(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool richValue(IJS_EventContext* cc, + bool richValue(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool selEnd(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool selStart(IJS_EventContext* cc, + bool selEnd(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool selStart(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool shift(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool source(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool target(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool targetName(IJS_EventContext* cc, + bool shift(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool source(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool target(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool targetName(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); - bool type(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool value(IJS_EventContext* cc, CJS_PropValue& vp, CFX_WideString& sError); - bool willCommit(IJS_EventContext* cc, + bool type(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool value(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); + bool willCommit(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError); }; diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp index 06b9d67f6a..8f9ce1a090 100644 --- a/fpdfsdk/javascript/global.cpp +++ b/fpdfsdk/javascript/global.cpp @@ -66,7 +66,7 @@ bool JSGlobalAlternate::QueryProperty(const FX_WCHAR* propname) { return CFX_WideString(propname) != L"setPersistent"; } -bool JSGlobalAlternate::DelProperty(IJS_EventContext* cc, +bool JSGlobalAlternate::DelProperty(CJS_Runtime* pRuntime, const FX_WCHAR* propname, CFX_WideString& sError) { auto it = m_mapGlobal.find(CFX_ByteString::FromUnicode(propname)); @@ -77,11 +77,10 @@ bool JSGlobalAlternate::DelProperty(IJS_EventContext* cc, return true; } -bool JSGlobalAlternate::DoProperty(IJS_EventContext* cc, +bool JSGlobalAlternate::DoProperty(CJS_Runtime* pRuntime, const FX_WCHAR* propname, CJS_PropValue& vp, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); if (vp.IsSetting()) { CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); switch (vp.GetJSValue()->GetType()) { @@ -114,7 +113,7 @@ bool JSGlobalAlternate::DoProperty(IJS_EventContext* cc, false, "", v8::Local(), false); } case CJS_Value::VT_undefined: { - DelProperty(cc, propname, sError); + DelProperty(pRuntime, propname, sError); return true; } default: @@ -157,7 +156,7 @@ bool JSGlobalAlternate::DoProperty(IJS_EventContext* cc, return false; } -bool JSGlobalAlternate::setPersistent(IJS_EventContext* cc, +bool JSGlobalAlternate::setPersistent(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -166,7 +165,6 @@ bool JSGlobalAlternate::setPersistent(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); auto it = m_mapGlobal.find(params[0].ToCFXByteString(pRuntime)); if (it != m_mapGlobal.end()) { JSGlobalData* pData = it->second; @@ -232,7 +230,8 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() { } } -void JSGlobalAlternate::CommitGlobalPersisitentVariables(IJS_EventContext* cc) { +void JSGlobalAlternate::CommitGlobalPersisitentVariables( + CJS_Runtime* pRuntime) { for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) { CFX_ByteString name = it->first; JSGlobalData* pData = it->second; @@ -256,7 +255,7 @@ void JSGlobalAlternate::CommitGlobalPersisitentVariables(IJS_EventContext* cc) { CJS_GlobalVariableArray array; v8::Local obj = v8::Local::New( GetJSObject()->GetIsolate(), pData->pData); - ObjectToArray(cc, obj, array); + ObjectToArray(pRuntime, obj, array); m_pGlobalData->SetGlobalVariableObject(name, array); m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); } break; @@ -269,10 +268,9 @@ void JSGlobalAlternate::CommitGlobalPersisitentVariables(IJS_EventContext* cc) { } } -void JSGlobalAlternate::ObjectToArray(IJS_EventContext* cc, +void JSGlobalAlternate::ObjectToArray(CJS_Runtime* pRuntime, v8::Local pObj, CJS_GlobalVariableArray& array) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); std::vector pKeyList = pRuntime->GetObjectPropertyNames(pObj); for (const auto& ws : pKeyList) { CFX_ByteString sKey = ws.UTF8Encode(); @@ -305,7 +303,7 @@ void JSGlobalAlternate::ObjectToArray(IJS_EventContext* cc, CJS_KeyValue* pObjElement = new CJS_KeyValue; pObjElement->nType = JS_GlobalDataType::OBJECT; pObjElement->sKey = sKey; - ObjectToArray(cc, pRuntime->ToObject(v), pObjElement->objData); + ObjectToArray(pRuntime, pRuntime->ToObject(v), pObjElement->objData); array.Add(pObjElement); } break; case CJS_Value::VT_null: { diff --git a/fpdfsdk/javascript/global.h b/fpdfsdk/javascript/global.h index cc5601cdeb..50dfcf3795 100644 --- a/fpdfsdk/javascript/global.h +++ b/fpdfsdk/javascript/global.h @@ -35,23 +35,23 @@ class JSGlobalAlternate : public CJS_EmbedObj { explicit JSGlobalAlternate(CJS_Object* pJSObject); ~JSGlobalAlternate() override; - bool setPersistent(IJS_EventContext* cc, + bool setPersistent(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); bool QueryProperty(const FX_WCHAR* propname); - bool DoProperty(IJS_EventContext* cc, + bool DoProperty(CJS_Runtime* pRuntime, const FX_WCHAR* propname, CJS_PropValue& vp, CFX_WideString& sError); - bool DelProperty(IJS_EventContext* cc, + bool DelProperty(CJS_Runtime* pRuntime, const FX_WCHAR* propname, CFX_WideString& sError); void Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv); private: void UpdateGlobalPersistentVariables(); - void CommitGlobalPersisitentVariables(IJS_EventContext* cc); + void CommitGlobalPersisitentVariables(CJS_Runtime* pRuntime); void DestroyGlobalPersisitentVariables(); bool SetGlobalVariables(const CFX_ByteString& propname, JS_GlobalDataType nType, @@ -60,7 +60,7 @@ class JSGlobalAlternate : public CJS_EmbedObj { const CFX_ByteString& sData, v8::Local pData, bool bDefaultPersistent); - void ObjectToArray(IJS_EventContext* cc, + void ObjectToArray(CJS_Runtime* pRuntime, v8::Local pObj, CJS_GlobalVariableArray& array); void PutObjectProperty(v8::Local obj, CJS_KeyValue* pData); diff --git a/fpdfsdk/javascript/ijs_runtime.h b/fpdfsdk/javascript/ijs_runtime.h index a0e69d863e..babc41842c 100644 --- a/fpdfsdk/javascript/ijs_runtime.h +++ b/fpdfsdk/javascript/ijs_runtime.h @@ -27,7 +27,6 @@ class IJS_Runtime { virtual IJS_EventContext* NewEventContext() = 0; virtual void ReleaseEventContext(IJS_EventContext* pContext) = 0; - virtual IJS_EventContext* GetCurrentEventContext() = 0; virtual CPDFSDK_FormFillEnvironment* GetFormFillEnv() const = 0; virtual int ExecuteScript(const CFX_WideString& script, CFX_WideString* info) = 0; diff --git a/fpdfsdk/javascript/report.cpp b/fpdfsdk/javascript/report.cpp index 87ed416b05..2cb123ab71 100644 --- a/fpdfsdk/javascript/report.cpp +++ b/fpdfsdk/javascript/report.cpp @@ -29,7 +29,7 @@ Report::Report(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} Report::~Report() {} -bool Report::writeText(IJS_EventContext* cc, +bool Report::writeText(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -37,7 +37,7 @@ bool Report::writeText(IJS_EventContext* cc, return true; } -bool Report::save(IJS_EventContext* cc, +bool Report::save(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { diff --git a/fpdfsdk/javascript/report.h b/fpdfsdk/javascript/report.h index 566b2e8e6f..c66db80fd1 100644 --- a/fpdfsdk/javascript/report.h +++ b/fpdfsdk/javascript/report.h @@ -17,11 +17,11 @@ class Report : public CJS_EmbedObj { ~Report() override; public: - bool save(IJS_EventContext* cc, + bool save(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool writeText(IJS_EventContext* cc, + bool writeText(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp index 0baca534b4..8ae1773c49 100644 --- a/fpdfsdk/javascript/util.cpp +++ b/fpdfsdk/javascript/util.cpp @@ -114,11 +114,10 @@ util::util(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} util::~util() {} -bool util::printf(IJS_EventContext* cc, +bool util::printf(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int iSize = params.size(); if (iSize < 1) return false; @@ -177,7 +176,7 @@ bool util::printf(IJS_EventContext* cc, return true; } -bool util::printd(IJS_EventContext* cc, +bool util::printd(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -185,7 +184,6 @@ bool util::printd(IJS_EventContext* cc, if (iSize < 2) return false; - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); CJS_Value p1 = params[0]; CJS_Value p2 = params[1]; CJS_Date jsDate; @@ -307,7 +305,7 @@ bool util::printd(IJS_EventContext* cc, return false; } -bool util::printx(IJS_EventContext* cc, +bool util::printx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -316,7 +314,6 @@ bool util::printx(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); vRet = CJS_Value(pRuntime, printx(params[0].ToCFXWideString(pRuntime), params[1].ToCFXWideString(pRuntime)) .c_str()); @@ -425,11 +422,10 @@ CFX_WideString util::printx(const CFX_WideString& wsFormat, return wsResult; } -bool util::scand(IJS_EventContext* cc, +bool util::scand(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int iSize = params.size(); if (iSize < 2) return false; @@ -450,7 +446,7 @@ bool util::scand(IJS_EventContext* cc, return true; } -bool util::byteToChar(IJS_EventContext* cc, +bool util::byteToChar(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { @@ -459,7 +455,6 @@ bool util::byteToChar(IJS_EventContext* cc, return false; } - CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc); int arg = params[0].ToInt(pRuntime); if (arg < 0 || arg > 255) { sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); diff --git a/fpdfsdk/javascript/util.h b/fpdfsdk/javascript/util.h index e7adb20edb..98761b6f30 100644 --- a/fpdfsdk/javascript/util.h +++ b/fpdfsdk/javascript/util.h @@ -17,23 +17,23 @@ class util : public CJS_EmbedObj { explicit util(CJS_Object* pJSObject); ~util() override; - bool printd(IJS_EventContext* cc, + bool printd(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool printf(IJS_EventContext* cc, + bool printf(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool printx(IJS_EventContext* cc, + bool printx(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool scand(IJS_EventContext* cc, + bool scand(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); - bool byteToChar(IJS_EventContext* cc, + bool byteToChar(CJS_Runtime* pRuntime, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError); -- cgit v1.2.3