summaryrefslogtreecommitdiff
path: root/fxjs/cjs_app.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-22 21:59:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-22 21:59:00 +0000
commit96c9517296c94cfa643d6197c8227879d88876d9 (patch)
tree51d8d168dd726e74bd86a39d2854778b8e5f9b85 /fxjs/cjs_app.cpp
parent0fe8910834a14fd79593dc4726e282d284417221 (diff)
downloadpdfium-96c9517296c94cfa643d6197c8227879d88876d9.tar.xz
Fix nits in fxjs.
- Make parameter checking more consistent in a several places. - Remove unnecessary parameter size checks. - Get rid of new statements / FX_Free() calls. Change-Id: I7bac8e678f590815a398a318cd62a2947e1dd973 Reviewed-on: https://pdfium-review.googlesource.com/32836 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxjs/cjs_app.cpp')
-rw-r--r--fxjs/cjs_app.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp
index 4e21ed994b..6c04c033b2 100644
--- a/fxjs/cjs_app.cpp
+++ b/fxjs/cjs_app.cpp
@@ -6,6 +6,8 @@
#include "fxjs/cjs_app.h"
+#include <utility>
+
#include "fpdfsdk/cpdfsdk_interform.h"
#include "fxjs/cjs_document.h"
#include "fxjs/cjs_timerobj.h"
@@ -276,11 +278,11 @@ CJS_Return CJS_App::alert(CJS_Runtime* pRuntime,
CJS_Return CJS_App::beep(CJS_Runtime* pRuntime,
const std::vector<v8::Local<v8::Value>>& params) {
- if (params.size() == 1) {
- pRuntime->GetFormFillEnv()->JS_appBeep(pRuntime->ToInt32(params[0]));
- return CJS_Return(true);
- }
- return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
+ if (params.size() != 1)
+ return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
+
+ pRuntime->GetFormFillEnv()->JS_appBeep(pRuntime->ToInt32(params[0]));
+ return CJS_Return(true);
}
CJS_Return CJS_App::findComponent(
@@ -306,18 +308,18 @@ CJS_Return CJS_App::set_fs(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
CJS_Return CJS_App::setInterval(
CJS_Runtime* pRuntime,
const std::vector<v8::Local<v8::Value>>& params) {
- if (params.size() > 2 || params.size() == 0)
+ if (params.size() == 0 || params.size() > 2)
return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
- WideString script =
- params.size() > 0 ? pRuntime->ToWideString(params[0]) : L"";
+ WideString script = pRuntime->ToWideString(params[0]);
if (script.IsEmpty())
return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError));
uint32_t dwInterval = params.size() > 1 ? pRuntime->ToInt32(params[1]) : 1000;
- GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(),
- pRuntime, 0, script, dwInterval, 0);
- m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
+ auto timerRef = pdfium::MakeUnique<GlobalTimer>(
+ this, pRuntime->GetFormFillEnv(), pRuntime, 0, script, dwInterval, 0);
+ GlobalTimer* pTimerRef = timerRef.get();
+ m_Timers.insert(std::move(timerRef));
v8::Local<v8::Object> pRetObj =
pRuntime->NewFXJSBoundObject(CJS_TimerObj::GetObjDefnID());
@@ -326,14 +328,14 @@ CJS_Return CJS_App::setInterval(
CJS_TimerObj* pJS_TimerObj =
static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
- pJS_TimerObj->SetTimer(timerRef);
+ pJS_TimerObj->SetTimer(pTimerRef);
return CJS_Return(pRetObj);
}
CJS_Return CJS_App::setTimeOut(
CJS_Runtime* pRuntime,
const std::vector<v8::Local<v8::Value>>& params) {
- if (params.size() > 2 || params.size() == 0)
+ if (params.size() == 0 || params.size() > 2)
return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
WideString script = pRuntime->ToWideString(params[0]);
@@ -341,10 +343,11 @@ CJS_Return CJS_App::setTimeOut(
return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError));
uint32_t dwTimeOut = params.size() > 1 ? pRuntime->ToInt32(params[1]) : 1000;
- GlobalTimer* timerRef =
- new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script,
- dwTimeOut, dwTimeOut);
- m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
+ auto timerRef = pdfium::MakeUnique<GlobalTimer>(
+ this, pRuntime->GetFormFillEnv(), pRuntime, 1, script, dwTimeOut,
+ dwTimeOut);
+ GlobalTimer* pTimerRef = timerRef.get();
+ m_Timers.insert(std::move(timerRef));
v8::Local<v8::Object> pRetObj =
pRuntime->NewFXJSBoundObject(CJS_TimerObj::GetObjDefnID());
@@ -353,8 +356,7 @@ CJS_Return CJS_App::setTimeOut(
CJS_TimerObj* pJS_TimerObj =
static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
- pJS_TimerObj->SetTimer(timerRef);
-
+ pJS_TimerObj->SetTimer(pTimerRef);
return CJS_Return(pRetObj);
}