summaryrefslogtreecommitdiff
path: root/fxjs/cjs_global.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-06-08 18:23:05 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-08 18:23:05 +0000
commit1699982f45d01cb18585eba80cce5326a63d3b67 (patch)
tree537d81d989632bab75fda37f5b587e1309e60d5d /fxjs/cjs_global.cpp
parentf29479d47156d180c0b71f6c98aa4de37c2a7ee2 (diff)
downloadpdfium-1699982f45d01cb18585eba80cce5326a63d3b67.tar.xz
Ensure CJS_Return() with error always includes a message.
Change the signature of the constructors to make it impossible to do this otherwise. Change-Id: I14e88d98a1128f2d599459ce9337cd6d079469fe Reviewed-on: https://pdfium-review.googlesource.com/34531 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/cjs_global.cpp')
-rw-r--r--fxjs/cjs_global.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index 1e01f96aee..5d5bc3ccf0 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -218,28 +218,30 @@ void CJS_Global::Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
}
CJS_Return CJS_Global::QueryProperty(const wchar_t* propname) {
- return CJS_Return(WideString(propname) != L"setPersistent");
+ if (WideString(propname) != L"setPersistent")
+ return CJS_Return(JSMessage::kUnknownProperty);
+ return CJS_Return();
}
CJS_Return CJS_Global::DelProperty(CJS_Runtime* pRuntime,
const wchar_t* propname) {
auto it = m_MapGlobal.find(ByteString::FromUnicode(propname));
if (it == m_MapGlobal.end())
- return CJS_Return(false);
+ return CJS_Return(JSMessage::kUnknownProperty);
it->second->bDeleted = true;
- return CJS_Return(true);
+ return CJS_Return();
}
CJS_Return CJS_Global::GetProperty(CJS_Runtime* pRuntime,
const wchar_t* propname) {
auto it = m_MapGlobal.find(ByteString::FromUnicode(propname));
if (it == m_MapGlobal.end())
- return CJS_Return(true);
+ return CJS_Return();
JSGlobalData* pData = it->second.get();
if (pData->bDeleted)
- return CJS_Return(true);
+ return CJS_Return();
switch (pData->nType) {
case JS_GlobalDataType::NUMBER:
@@ -257,7 +259,7 @@ CJS_Return CJS_Global::GetProperty(CJS_Runtime* pRuntime,
default:
break;
}
- return CJS_Return(false);
+ return CJS_Return(JSMessage::kObjectTypeError);
}
CJS_Return CJS_Global::SetProperty(CJS_Runtime* pRuntime,
@@ -290,24 +292,24 @@ CJS_Return CJS_Global::SetProperty(CJS_Runtime* pRuntime,
}
if (vp->IsUndefined()) {
DelProperty(pRuntime, propname);
- return CJS_Return(true);
+ return CJS_Return();
}
- return CJS_Return(false);
+ return CJS_Return(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(JSGetStringFromID(JSMessage::kParamError));
+ return CJS_Return(JSMessage::kParamError);
auto it = m_MapGlobal.find(
ByteString::FromUnicode(pRuntime->ToWideString(params[0])));
if (it == m_MapGlobal.end() || it->second->bDeleted)
- return CJS_Return(JSGetStringFromID(JSMessage::kGlobalNotFoundError));
+ return CJS_Return(JSMessage::kGlobalNotFoundError);
it->second->bPersistent = pRuntime->ToBoolean(params[1]);
- return CJS_Return(true);
+ return CJS_Return();
}
void CJS_Global::UpdateGlobalPersistentVariables() {
@@ -498,7 +500,7 @@ CJS_Return CJS_Global::SetGlobalVariables(const ByteString& propname,
v8::Local<v8::Object> pData,
bool bDefaultPersistent) {
if (propname.IsEmpty())
- return CJS_Return(false);
+ return CJS_Return(JSMessage::kUnknownProperty);
auto it = m_MapGlobal.find(propname);
if (it != m_MapGlobal.end()) {
@@ -526,9 +528,9 @@ CJS_Return CJS_Global::SetGlobalVariables(const ByteString& propname,
case JS_GlobalDataType::NULLOBJ:
break;
default:
- return CJS_Return(false);
+ return CJS_Return(JSMessage::kObjectTypeError);
}
- return CJS_Return(true);
+ return CJS_Return();
}
auto pNewData = pdfium::MakeUnique<JSGlobalData>();
@@ -558,8 +560,8 @@ CJS_Return CJS_Global::SetGlobalVariables(const ByteString& propname,
pNewData->bPersistent = bDefaultPersistent;
break;
default:
- return CJS_Return(false);
+ return CJS_Return(JSMessage::kObjectTypeError);
}
m_MapGlobal[propname] = std::move(pNewData);
- return CJS_Return(true);
+ return CJS_Return();
}