From 20736f7f5884cf1e2827543c92b6e47f8282aeaf Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 17 Aug 2018 16:44:50 +0000 Subject: Introduce safer CJS_Return::Success() and Failure(). Avoid the possibility of ever re-introducing the issue noticed last week. Remove some redundant JSGetStringFromID() calls. Change-Id: I56687c2191bd72e378f747083f34080e50cbe490 Reviewed-on: https://pdfium-review.googlesource.com/40490 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fxjs/cjs_annot.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'fxjs/cjs_annot.cpp') diff --git a/fxjs/cjs_annot.cpp b/fxjs/cjs_annot.cpp index c4a4f7ab1d..4e93dc2516 100644 --- a/fxjs/cjs_annot.cpp +++ b/fxjs/cjs_annot.cpp @@ -39,10 +39,10 @@ CJS_Annot::~CJS_Annot() = default; CJS_Return CJS_Annot::get_hidden(CJS_Runtime* pRuntime) { if (!m_pAnnot) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); CPDF_Annot* pPDFAnnot = m_pAnnot->AsBAAnnot()->GetPDFAnnot(); - return CJS_Return(pRuntime->NewBoolean( + return CJS_Return::Success(pRuntime->NewBoolean( CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()))); } @@ -53,7 +53,7 @@ CJS_Return CJS_Annot::set_hidden(CJS_Runtime* pRuntime, CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get()); if (!pBAAnnot) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); uint32_t flags = pBAAnnot->GetFlags(); if (bHidden) { @@ -68,14 +68,15 @@ CJS_Return CJS_Annot::set_hidden(CJS_Runtime* pRuntime, flags |= ANNOTFLAG_PRINT; } pBAAnnot->SetFlags(flags); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Annot::get_name(CJS_Runtime* pRuntime) { CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get()); if (!pBAAnnot) - return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return( + return CJS_Return::Failure(JSMessage::kBadObjectError); + + return CJS_Return::Success( pRuntime->NewString(pBAAnnot->GetAnnotName().AsStringView())); } @@ -85,18 +86,18 @@ CJS_Return CJS_Annot::set_name(CJS_Runtime* pRuntime, v8::Local vp) { CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get()); if (!pBAAnnot) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); pBAAnnot->SetAnnotName(annotName); - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Annot::get_type(CJS_Runtime* pRuntime) { CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get()); if (!pBAAnnot) - return CJS_Return(JSMessage::kBadObjectError); + return CJS_Return::Failure(JSMessage::kBadObjectError); - return CJS_Return(pRuntime->NewString( + return CJS_Return::Success(pRuntime->NewString( WideString::FromLocal( CPDF_Annot::AnnotSubtypeToString(pBAAnnot->GetAnnotSubtype()) .AsStringView()) @@ -104,5 +105,5 @@ CJS_Return CJS_Annot::get_type(CJS_Runtime* pRuntime) { } CJS_Return CJS_Annot::set_type(CJS_Runtime* pRuntime, v8::Local vp) { - return CJS_Return(JSMessage::kReadOnlyError); + return CJS_Return::Failure(JSMessage::kReadOnlyError); } -- cgit v1.2.3