diff options
Diffstat (limited to 'fxjs/cjs_document.cpp')
-rw-r--r-- | fxjs/cjs_document.cpp | 375 |
1 files changed, 191 insertions, 184 deletions
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp index a6d68c8d29..b842c150bf 100644 --- a/fxjs/cjs_document.cpp +++ b/fxjs/cjs_document.cpp @@ -133,58 +133,61 @@ CJS_Document::~CJS_Document() = default; // The total number of fields in document. CJS_Return CJS_Document::get_num_fields(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); - return CJS_Return(pRuntime->NewNumber( + return CJS_Return::Success(pRuntime->NewNumber( static_cast<int>(pPDFForm->CountFields(WideString())))); } CJS_Return CJS_Document::set_num_fields(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(JSMessage::kReadOnlyError); + return CJS_Return::Failure(JSMessage::kReadOnlyError); } CJS_Return CJS_Document::get_dirty(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return(pRuntime->NewBoolean(!!m_pFormFillEnv->GetChangeMark())); + return CJS_Return::Failure(JSMessage::kBadObjectError); + + return CJS_Return::Success( + pRuntime->NewBoolean(!!m_pFormFillEnv->GetChangeMark())); } CJS_Return CJS_Document::set_dirty(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); pRuntime->ToBoolean(vp) ? m_pFormFillEnv->SetChangeMark() : m_pFormFillEnv->ClearChangeMark(); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_ADBE(CJS_Runtime* pRuntime) { - return CJS_Return(pRuntime->NewUndefined()); + return CJS_Return::Success(pRuntime->NewUndefined()); } CJS_Return CJS_Document::set_ADBE(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_page_num(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView(); if (!pPageView) - return CJS_Return(pRuntime->NewUndefined()); - return CJS_Return(pRuntime->NewNumber(pPageView->GetPageIndex())); + return CJS_Return::Success(pRuntime->NewUndefined()); + + return CJS_Return::Success(pRuntime->NewNumber(pPageView->GetPageIndex())); } CJS_Return CJS_Document::set_page_num(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); int iPageCount = m_pFormFillEnv->GetPageCount(); int iPageNum = pRuntime->ToInt32(vp); @@ -195,70 +198,71 @@ CJS_Return CJS_Document::set_page_num(CJS_Runtime* pRuntime, else if (iPageNum < 0) m_pFormFillEnv->JS_docgotoPage(0); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::addAnnot( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - // Not supported. - return CJS_Return(); + // Not supported, but do not return an error. + return CJS_Return::Success(); } CJS_Return CJS_Document::addField( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - // Not supported. - return CJS_Return(); + // Not supported, but do not return an error. + return CJS_Return::Success(); } CJS_Return CJS_Document::exportAsText( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - // Unsafe, not supported. - return CJS_Return(); + // Unsafe, not supported, but do not return an error. + return CJS_Return::Success(); } CJS_Return CJS_Document::exportAsFDF( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - // Unsafe, not supported. - return CJS_Return(); + // Unsafe, not supported, but do not return an error. + return CJS_Return::Success(); } CJS_Return CJS_Document::exportAsXFDF( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - // Unsafe, not supported. - return CJS_Return(); + // Unsafe, not supported, but do not return an error. + return CJS_Return::Success(); } CJS_Return CJS_Document::getField( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (params.empty()) - return CJS_Return(JSMessage::kParamError); + return CJS_Return::Failure(JSMessage::kParamError); + if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); WideString wideName = pRuntime->ToWideString(params[0]); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); if (pPDFForm->CountFields(wideName) <= 0) - return CJS_Return(pRuntime->NewUndefined()); + return CJS_Return::Success(pRuntime->NewUndefined()); v8::Local<v8::Object> pFieldObj = pRuntime->NewFXJSBoundObject( CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pFieldObj.IsEmpty()) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); auto* pJSField = static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pFieldObj)); if (!pJSField) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); pJSField->AttachField(this, wideName); - return CJS_Return(pJSField->ToV8Object()); + return CJS_Return::Success(pJSField->ToV8Object()); } // Gets the name of the nth field in the document @@ -266,41 +270,42 @@ CJS_Return CJS_Document::getNthFieldName( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (params.size() != 1) - return CJS_Return(JSMessage::kParamError); + return CJS_Return::Failure(JSMessage::kParamError); if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); int nIndex = pRuntime->ToInt32(params[0]); if (nIndex < 0) - return CJS_Return(JSMessage::kValueError); + return CJS_Return::Failure(JSMessage::kValueError); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); CPDF_FormField* pField = pPDFForm->GetField(nIndex, WideString()); if (!pField) - return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return(pRuntime->NewString(pField->GetFullName().AsStringView())); + return CJS_Return::Failure(JSMessage::kBadObjectError); + return CJS_Return::Success( + pRuntime->NewString(pField->GetFullName().AsStringView())); } CJS_Return CJS_Document::importAnFDF( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, not supported. - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::importAnXFDF( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, not supported. - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::importTextData( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, not supported. - return CJS_Return(); + return CJS_Return::Success(); } // exports the form data and mails the resulting fdf file as an attachment to @@ -310,14 +315,14 @@ CJS_Return CJS_Document::mailForm( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) - return CJS_Return(JSMessage::kPermissionError); + return CJS_Return::Failure(JSMessage::kPermissionError); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); ByteString sTextBuf = pInterForm->ExportFormToFDFTextBuf(); if (sTextBuf.GetLength() == 0) - return CJS_Return(L"Bad FDF format."); + return CJS_Return::Failure(L"Bad FDF format."); size_t nLength = params.size(); bool bUI = nLength > 0 ? pRuntime->ToBoolean(params[0]) : true; @@ -333,14 +338,14 @@ CJS_Return CJS_Document::mailForm( pFormFillEnv->JS_docmailForm(mutable_buf.data(), mutable_buf.size(), bUI, cTo, cSubject, cCc, cBcc, cMsg); pRuntime->EndBlock(); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::print( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); bool bUI = true; int nStart = 0; @@ -386,11 +391,11 @@ CJS_Return CJS_Document::print( } if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); m_pFormFillEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations); - return CJS_Return(); + return CJS_Return::Success(); } // removes the specified field from the document. @@ -401,20 +406,20 @@ CJS_Return CJS_Document::removeField( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (params.size() != 1) - return CJS_Return(JSMessage::kParamError); + return CJS_Return::Failure(JSMessage::kParamError); if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM))) - return CJS_Return(JSMessage::kPermissionError); + return CJS_Return::Failure(JSMessage::kPermissionError); WideString sFieldName = pRuntime->ToWideString(params[0]); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); std::vector<CPDFSDK_Annot::ObservedPtr> widgets; pInterForm->GetWidgets(sFieldName, &widgets); if (widgets.empty()) - return CJS_Return(); + return CJS_Return::Success(); for (const auto& pAnnot : widgets) { CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot.Get()); @@ -444,7 +449,7 @@ CJS_Return CJS_Document::removeField( } m_pFormFillEnv->SetChangeMark(); - return CJS_Return(); + return CJS_Return::Success(); } // reset filed values within a document. @@ -455,11 +460,11 @@ CJS_Return CJS_Document::resetForm( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { - return CJS_Return(JSMessage::kPermissionError); + return CJS_Return::Failure(JSMessage::kPermissionError); } CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); @@ -467,7 +472,7 @@ CJS_Return CJS_Document::resetForm( if (params.empty()) { pPDFForm->ResetForm(NotificationOption::kNotify); m_pFormFillEnv->SetChangeMark(); - return CJS_Return(); + return CJS_Return::Success(); } v8::Local<v8::Array> array; @@ -491,20 +496,20 @@ CJS_Return CJS_Document::resetForm( m_pFormFillEnv->SetChangeMark(); } - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::saveAs( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, not supported. - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::syncAnnotScan( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::submitForm( @@ -512,9 +517,9 @@ CJS_Return CJS_Document::submitForm( const std::vector<v8::Local<v8::Value>>& params) { size_t nSize = params.size(); if (nSize < 1) - return CJS_Return(JSMessage::kParamError); + return CJS_Return::Failure(JSMessage::kParamError); if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); v8::Local<v8::Array> aFields; WideString strURL; @@ -548,7 +553,7 @@ CJS_Return CJS_Document::submitForm( pInterForm->SubmitForm(strURL, false); pRuntime->EndBlock(); } - return CJS_Return(); + return CJS_Return::Success(); } std::vector<CPDF_FormField*> fieldObjects; @@ -570,7 +575,7 @@ CJS_Return CJS_Document::submitForm( pInterForm->SubmitFields(strURL, fieldObjects, true, !bFDF); pRuntime->EndBlock(); } - return CJS_Return(); + return CJS_Return::Success(); } void CJS_Document::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { @@ -578,12 +583,12 @@ void CJS_Document::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { } CJS_Return CJS_Document::get_bookmark_root(CJS_Runtime* pRuntime) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::set_bookmark_root(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::mailDoc( @@ -626,7 +631,7 @@ CJS_Return CJS_Document::mailDoc( CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); pFormFillEnv->JS_docmailForm(nullptr, 0, bUI, cTo, cSubject, cCc, cBcc, cMsg); pRuntime->EndBlock(); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_author(CJS_Runtime* pRuntime) { @@ -640,11 +645,11 @@ CJS_Return CJS_Document::set_author(CJS_Runtime* pRuntime, CJS_Return CJS_Document::get_info(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); const auto* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); if (!pDictionary) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); WideString cwAuthor = pDictionary->GetUnicodeTextFor("Author"); WideString cwTitle = pDictionary->GetUnicodeTextFor("Title"); @@ -694,23 +699,23 @@ CJS_Return CJS_Document::get_info(CJS_Runtime* pRuntime) { pObj, wsKey, pRuntime->NewBoolean(!!pValueObj->GetInteger())); } } - return CJS_Return(pObj); + return CJS_Return::Success(pObj); } CJS_Return CJS_Document::set_info(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(JSMessage::kReadOnlyError); + return CJS_Return::Failure(JSMessage::kReadOnlyError); } CJS_Return CJS_Document::getPropertyInternal(CJS_Runtime* pRuntime, const ByteString& propName) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); if (!pDictionary) - return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return(pRuntime->NewString( + return CJS_Return::Failure(JSMessage::kBadObjectError); + return CJS_Return::Success(pRuntime->NewString( pDictionary->GetUnicodeTextFor(propName).AsStringView())); } @@ -718,20 +723,20 @@ CJS_Return CJS_Document::setPropertyInternal(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp, const ByteString& propName) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); if (!pDictionary) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) - return CJS_Return(JSMessage::kPermissionError); + return CJS_Return::Failure(JSMessage::kPermissionError); WideString csProperty = pRuntime->ToWideString(vp); pDictionary->SetNewFor<CPDF_String>(propName, PDF_EncodeText(csProperty), false); m_pFormFillEnv->SetChangeMark(); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_creation_date(CJS_Runtime* pRuntime) { @@ -754,21 +759,21 @@ CJS_Return CJS_Document::set_creator(CJS_Runtime* pRuntime, CJS_Return CJS_Document::get_delay(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return(pRuntime->NewBoolean(m_bDelay)); + return CJS_Return::Failure(JSMessage::kBadObjectError); + return CJS_Return::Success(pRuntime->NewBoolean(m_bDelay)); } CJS_Return CJS_Document::set_delay(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) - return CJS_Return(JSMessage::kPermissionError); + return CJS_Return::Failure(JSMessage::kPermissionError); m_bDelay = pRuntime->ToBoolean(vp); if (m_bDelay) { m_DelayData.clear(); - return CJS_Return(); + return CJS_Return::Success(); } std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; @@ -776,7 +781,7 @@ CJS_Return CJS_Document::set_delay(CJS_Runtime* pRuntime, for (const auto& pData : DelayDataToProcess) CJS_Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_keywords(CJS_Runtime* pRuntime) { @@ -817,108 +822,110 @@ CJS_Return CJS_Document::set_subject(CJS_Runtime* pRuntime, CJS_Return CJS_Document::get_title(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv || !m_pFormFillEnv->GetPDFDocument()) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); return getPropertyInternal(pRuntime, "Title"); } CJS_Return CJS_Document::set_title(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { if (!m_pFormFillEnv || !m_pFormFillEnv->GetPDFDocument()) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); return setPropertyInternal(pRuntime, vp, "Title"); } CJS_Return CJS_Document::get_num_pages(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return(pRuntime->NewNumber(m_pFormFillEnv->GetPageCount())); + return CJS_Return::Failure(JSMessage::kBadObjectError); + return CJS_Return::Success( + pRuntime->NewNumber(m_pFormFillEnv->GetPageCount())); } CJS_Return CJS_Document::set_num_pages(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(JSMessage::kReadOnlyError); + return CJS_Return::Failure(JSMessage::kReadOnlyError); } CJS_Return CJS_Document::get_external(CJS_Runtime* pRuntime) { // In Chrome case, should always return true. - return CJS_Return(pRuntime->NewBoolean(true)); + return CJS_Return::Success(pRuntime->NewBoolean(true)); } CJS_Return CJS_Document::set_external(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_filesize(CJS_Runtime* pRuntime) { - return CJS_Return(pRuntime->NewNumber(0)); + return CJS_Return::Success(pRuntime->NewNumber(0)); } CJS_Return CJS_Document::set_filesize(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(JSMessage::kReadOnlyError); + return CJS_Return::Failure(JSMessage::kReadOnlyError); } CJS_Return CJS_Document::get_mouse_x(CJS_Runtime* pRuntime) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::set_mouse_x(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_mouse_y(CJS_Runtime* pRuntime) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::set_mouse_y(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_URL(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return( + return CJS_Return::Failure(JSMessage::kBadObjectError); + return CJS_Return::Success( pRuntime->NewString(m_pFormFillEnv->JS_docGetFilePath().AsStringView())); } CJS_Return CJS_Document::set_URL(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(JSMessage::kReadOnlyError); + return CJS_Return::Failure(JSMessage::kReadOnlyError); } CJS_Return CJS_Document::get_base_URL(CJS_Runtime* pRuntime) { - return CJS_Return(pRuntime->NewString(m_cwBaseURL.AsStringView())); + return CJS_Return::Success(pRuntime->NewString(m_cwBaseURL.AsStringView())); } CJS_Return CJS_Document::set_base_URL(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { m_cwBaseURL = pRuntime->ToWideString(vp); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_calculate(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); - return CJS_Return(pRuntime->NewBoolean(!!pInterForm->IsCalculateEnabled())); + return CJS_Return::Success( + pRuntime->NewBoolean(!!pInterForm->IsCalculateEnabled())); } CJS_Return CJS_Document::set_calculate(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); pInterForm->EnableCalculate(pRuntime->ToBoolean(vp)); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_document_file_name(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath(); size_t i = wsFilePath.GetLength(); @@ -927,78 +934,78 @@ CJS_Return CJS_Document::get_document_file_name(CJS_Runtime* pRuntime) { break; } if (i > 0 && i < wsFilePath.GetLength()) - return CJS_Return(pRuntime->NewString(wsFilePath.c_str() + i)); + return CJS_Return::Success(pRuntime->NewString(wsFilePath.c_str() + i)); - return CJS_Return(pRuntime->NewString(L"")); + return CJS_Return::Success(pRuntime->NewString(L"")); } CJS_Return CJS_Document::set_document_file_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(JSMessage::kReadOnlyError); + return CJS_Return::Failure(JSMessage::kReadOnlyError); } CJS_Return CJS_Document::get_path(CJS_Runtime* pRuntime) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return(pRuntime->NewString( + return CJS_Return::Failure(JSMessage::kBadObjectError); + return CJS_Return::Success(pRuntime->NewString( CJS_App::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath()) .AsStringView())); } CJS_Return CJS_Document::set_path(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(JSMessage::kReadOnlyError); + return CJS_Return::Failure(JSMessage::kReadOnlyError); } CJS_Return CJS_Document::get_page_window_rect(CJS_Runtime* pRuntime) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::set_page_window_rect(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_layout(CJS_Runtime* pRuntime) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::set_layout(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::addLink( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::closeDoc( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::getPageBox( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::getAnnot( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (params.size() != 2) - return CJS_Return(JSMessage::kParamError); + return CJS_Return::Failure(JSMessage::kParamError); if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); int nPageNo = pRuntime->ToInt32(params[0]); WideString swAnnotName = pRuntime->ToWideString(params[1]); CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); if (!pPageView) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDFSDK_AnnotIteration annotIteration(pPageView, false); CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; @@ -1010,27 +1017,27 @@ CJS_Return CJS_Document::getAnnot( } } if (!pSDKBAAnnot) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject( CJS_Annot::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pObj.IsEmpty()) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); auto* pJS_Annot = static_cast<CJS_Annot*>(CFXJS_Engine::GetObjectPrivate(pObj)); if (!pJS_Annot) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); pJS_Annot->SetSDKAnnot(pSDKBAAnnot); - return CJS_Return(pJS_Annot->ToV8Object()); + return CJS_Return::Success(pJS_Annot->ToV8Object()); } CJS_Return CJS_Document::getAnnots( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); // TODO(tonikitoo): Add support supported parameters as per // the PDF spec. @@ -1040,17 +1047,17 @@ CJS_Return CJS_Document::getAnnots( for (int i = 0; i < nPageNo; ++i) { CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i); if (!pPageView) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDFSDK_AnnotIteration annotIteration(pPageView, false); for (const auto& pSDKAnnotCur : annotIteration) { if (!pSDKAnnotCur) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject( CJS_Annot::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pObj.IsEmpty()) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); auto* pJS_Annot = static_cast<CJS_Annot*>(CFXJS_Engine::GetObjectPrivate(pObj)); @@ -1061,31 +1068,31 @@ CJS_Return CJS_Document::getAnnots( : v8::Local<v8::Value>()); } } - return CJS_Return(annots); + return CJS_Return::Success(annots); } CJS_Return CJS_Document::getAnnot3D( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - return CJS_Return(pRuntime->NewUndefined()); + return CJS_Return::Success(pRuntime->NewUndefined()); } CJS_Return CJS_Document::getAnnots3D( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::getOCGs( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::getLinks( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { - return CJS_Return(); + return CJS_Return::Success(); } bool CJS_Document::IsEnclosedInRect(CFX_FloatRect rect, @@ -1098,23 +1105,23 @@ CJS_Return CJS_Document::addIcon( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (params.size() != 2) - return CJS_Return(JSMessage::kParamError); + return CJS_Return::Failure(JSMessage::kParamError); if (!params[1]->IsObject()) - return CJS_Return(JSMessage::kTypeError); + return CJS_Return::Failure(JSMessage::kTypeError); v8::Local<v8::Object> pObj = pRuntime->ToObject(params[1]); if (!JSGetObject<CJS_Icon>(pObj)) - return CJS_Return(JSMessage::kTypeError); + return CJS_Return::Failure(JSMessage::kTypeError); WideString swIconName = pRuntime->ToWideString(params[0]); m_IconNames.push_back(swIconName); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_icons(CJS_Runtime* pRuntime) { if (m_IconNames.empty()) - return CJS_Return(pRuntime->NewUndefined()); + return CJS_Return::Success(pRuntime->NewUndefined()); v8::Local<v8::Array> Icons = pRuntime->NewArray(); int i = 0; @@ -1122,7 +1129,7 @@ CJS_Return CJS_Document::get_icons(CJS_Runtime* pRuntime) { v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject( CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pObj.IsEmpty()) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); auto* pJS_Icon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj)); @@ -1132,93 +1139,93 @@ CJS_Return CJS_Document::get_icons(CJS_Runtime* pRuntime) { ? v8::Local<v8::Value>(pJS_Icon->ToV8Object()) : v8::Local<v8::Value>()); } - return CJS_Return(Icons); + return CJS_Return::Success(Icons); } CJS_Return CJS_Document::set_icons(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(JSMessage::kReadOnlyError); + return CJS_Return::Failure(JSMessage::kReadOnlyError); } CJS_Return CJS_Document::getIcon( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (params.size() != 1) - return CJS_Return(JSMessage::kParamError); + return CJS_Return::Failure(JSMessage::kParamError); WideString swIconName = pRuntime->ToWideString(params[0]); auto it = std::find(m_IconNames.begin(), m_IconNames.end(), swIconName); if (it == m_IconNames.end()) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject( CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pObj.IsEmpty()) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); auto* pJSIcon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj)); if (!pJSIcon) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); pJSIcon->SetIconName(*it); - return CJS_Return(pJSIcon->ToV8Object()); + return CJS_Return::Success(pJSIcon->ToV8Object()); } CJS_Return CJS_Document::removeIcon( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, no supported. - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::createDataObject( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, not implemented. - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_media(CJS_Runtime* pRuntime) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::set_media(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::calculateNow( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { - return CJS_Return(JSMessage::kPermissionError); + return CJS_Return::Failure(JSMessage::kPermissionError); } m_pFormFillEnv->GetInterForm()->OnCalculate(nullptr); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_collab(CJS_Runtime* pRuntime) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::set_collab(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::getPageNthWord( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) - return CJS_Return(JSMessage::kPermissionError); + return CJS_Return::Failure(JSMessage::kPermissionError); // TODO(tsepez): check maximum allowable params. @@ -1228,14 +1235,14 @@ CJS_Return CJS_Document::getPageNthWord( CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (!pDocument) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) - return CJS_Return(JSMessage::kValueError); + return CJS_Return::Failure(JSMessage::kValueError); CPDF_Dictionary* pPageDict = pDocument->GetPageDictionary(nPageNo); if (!pPageDict) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); auto page = pdfium::MakeRetain<CPDF_Page>(pDocument, pPageDict, true); page->ParseContent(); @@ -1256,35 +1263,35 @@ CJS_Return CJS_Document::getPageNthWord( if (bStrip) swRet.Trim(); - return CJS_Return(pRuntime->NewString(swRet.AsStringView())); + return CJS_Return::Success(pRuntime->NewString(swRet.AsStringView())); } CJS_Return CJS_Document::getPageNthWordQuads( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) - return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return(JSMessage::kNotSupportedError); + return CJS_Return::Failure(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kNotSupportedError); } CJS_Return CJS_Document::getPageNumWords( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) - return CJS_Return(JSMessage::kPermissionError); + return CJS_Return::Failure(JSMessage::kPermissionError); int nPageNo = params.size() > 0 ? pRuntime->ToInt32(params[0]) : 0; CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) - return CJS_Return(JSMessage::kValueError); + return CJS_Return::Failure(JSMessage::kValueError); CPDF_Dictionary* pPageDict = pDocument->GetPageDictionary(nPageNo); if (!pPageDict) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); auto page = pdfium::MakeRetain<CPDF_Page>(pDocument, pPageDict, true); page->ParseContent(); @@ -1295,7 +1302,7 @@ CJS_Return CJS_Document::getPageNumWords( nWords += CountWords(pPageObj->AsText()); } - return CJS_Return(pRuntime->NewNumber(nWords)); + return CJS_Return::Success(pRuntime->NewNumber(nWords)); } CJS_Return CJS_Document::getPrintParams( @@ -1304,8 +1311,8 @@ CJS_Return CJS_Document::getPrintParams( v8::Local<v8::Object> pRetObj = pRuntime->NewFXJSBoundObject( CJS_PrintParamsObj::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pRetObj.IsEmpty()) - return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return(JSMessage::kNotSupportedError); + return CJS_Return::Failure(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kNotSupportedError); } #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) @@ -1379,76 +1386,76 @@ WideString CJS_Document::GetObjWordStr(CPDF_TextObject* pTextObj, } CJS_Return CJS_Document::get_zoom(CJS_Runtime* pRuntime) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::set_zoom(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::get_zoom_type(CJS_Runtime* pRuntime) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::set_zoom_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::deletePages( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, not supported. - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::extractPages( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, not supported. - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::insertPages( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, not supported. - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::replacePages( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, not supported. - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::getURL( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { // Unsafe, not supported. - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Document::gotoNamedDest( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { if (params.size() != 1) - return CJS_Return(JSMessage::kParamError); + return CJS_Return::Failure(JSMessage::kParamError); if (!m_pFormFillEnv) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (!pDocument) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDF_NameTree nameTree(pDocument, "Dests"); CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, pRuntime->ToWideString(params[0])); if (!destArray) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDF_Dest dest(destArray); const CPDF_Array* arrayObject = ToArray(dest.GetObject()); @@ -1462,7 +1469,7 @@ CJS_Return CJS_Document::gotoNamedDest( dest.GetZoomMode(), scrollPositionArray.data(), scrollPositionArray.size()); pRuntime->EndBlock(); - return CJS_Return(); + return CJS_Return::Success(); } void CJS_Document::AddDelayData(std::unique_ptr<CJS_DelayData> pData) { |