diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-08-17 16:44:50 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-08-17 16:44:50 +0000 |
commit | 20736f7f5884cf1e2827543c92b6e47f8282aeaf (patch) | |
tree | 9a0f3cbd9262d1676f70ab02c3fa5b4e0acaa03a /fxjs/cjs_global.cpp | |
parent | 21068062a038db72b5ee40512fe638acbdd17c3d (diff) | |
download | pdfium-20736f7f5884cf1e2827543c92b6e47f8282aeaf.tar.xz |
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 <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/cjs_global.cpp')
-rw-r--r-- | fxjs/cjs_global.cpp | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp index 1865f57ddb..e747d6205c 100644 --- a/fxjs/cjs_global.cpp +++ b/fxjs/cjs_global.cpp @@ -226,47 +226,47 @@ void CJS_Global::Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv) { CJS_Return CJS_Global::QueryProperty(const wchar_t* propname) { if (WideString(propname) != L"setPersistent") - return CJS_Return(JSMessage::kUnknownProperty); - return CJS_Return(); + return CJS_Return::Failure(JSMessage::kUnknownProperty); + return CJS_Return::Success(); } CJS_Return CJS_Global::DelProperty(CJS_Runtime* pRuntime, const wchar_t* propname) { auto it = m_MapGlobal.find(WideString(propname).ToDefANSI()); if (it == m_MapGlobal.end()) - return CJS_Return(JSMessage::kUnknownProperty); + return CJS_Return::Failure(JSMessage::kUnknownProperty); it->second->bDeleted = true; - return CJS_Return(); + return CJS_Return::Success(); } CJS_Return CJS_Global::GetProperty(CJS_Runtime* pRuntime, const wchar_t* propname) { auto it = m_MapGlobal.find(WideString(propname).ToDefANSI()); if (it == m_MapGlobal.end()) - return CJS_Return(); + return CJS_Return::Success(); JSGlobalData* pData = it->second.get(); if (pData->bDeleted) - return CJS_Return(); + return CJS_Return::Success(); switch (pData->nType) { case JS_GlobalDataType::NUMBER: - return CJS_Return(pRuntime->NewNumber(pData->dData)); + return CJS_Return::Success(pRuntime->NewNumber(pData->dData)); case JS_GlobalDataType::BOOLEAN: - return CJS_Return(pRuntime->NewBoolean(pData->bData)); + return CJS_Return::Success(pRuntime->NewBoolean(pData->bData)); case JS_GlobalDataType::STRING: - return CJS_Return(pRuntime->NewString( + return CJS_Return::Success(pRuntime->NewString( WideString::FromLocal(pData->sData.AsStringView()).AsStringView())); case JS_GlobalDataType::OBJECT: - return CJS_Return( + return CJS_Return::Success( v8::Local<v8::Object>::New(pRuntime->GetIsolate(), pData->pData)); case JS_GlobalDataType::NULLOBJ: - return CJS_Return(pRuntime->NewNull()); + return CJS_Return::Success(pRuntime->NewNull()); default: break; } - return CJS_Return(JSMessage::kObjectTypeError); + return CJS_Return::Failure(JSMessage::kObjectTypeError); } CJS_Return CJS_Global::SetProperty(CJS_Runtime* pRuntime, @@ -298,23 +298,23 @@ CJS_Return CJS_Global::SetProperty(CJS_Runtime* pRuntime, } if (vp->IsUndefined()) { DelProperty(pRuntime, propname); - return CJS_Return(); + return CJS_Return::Success(); } - return CJS_Return(JSMessage::kObjectTypeError); + return CJS_Return::Failure(JSMessage::kObjectTypeError); } CJS_Return CJS_Global::setPersistent( 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); auto it = m_MapGlobal.find(pRuntime->ToWideString(params[0]).ToDefANSI()); if (it == m_MapGlobal.end() || it->second->bDeleted) - return CJS_Return(JSMessage::kGlobalNotFoundError); + return CJS_Return::Failure(JSMessage::kGlobalNotFoundError); it->second->bPersistent = pRuntime->ToBoolean(params[1]); - return CJS_Return(); + return CJS_Return::Success(); } void CJS_Global::UpdateGlobalPersistentVariables() { @@ -505,7 +505,7 @@ CJS_Return CJS_Global::SetGlobalVariables(const ByteString& propname, v8::Local<v8::Object> pData, bool bDefaultPersistent) { if (propname.IsEmpty()) - return CJS_Return(JSMessage::kUnknownProperty); + return CJS_Return::Failure(JSMessage::kUnknownProperty); auto it = m_MapGlobal.find(propname); if (it != m_MapGlobal.end()) { @@ -533,9 +533,9 @@ CJS_Return CJS_Global::SetGlobalVariables(const ByteString& propname, case JS_GlobalDataType::NULLOBJ: break; default: - return CJS_Return(JSMessage::kObjectTypeError); + return CJS_Return::Failure(JSMessage::kObjectTypeError); } - return CJS_Return(); + return CJS_Return::Success(); } auto pNewData = pdfium::MakeUnique<JSGlobalData>(); @@ -565,8 +565,8 @@ CJS_Return CJS_Global::SetGlobalVariables(const ByteString& propname, pNewData->bPersistent = bDefaultPersistent; break; default: - return CJS_Return(JSMessage::kObjectTypeError); + return CJS_Return::Failure(JSMessage::kObjectTypeError); } m_MapGlobal[propname] = std::move(pNewData); - return CJS_Return(); + return CJS_Return::Success(); } |