summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-07-17 21:33:37 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-17 21:33:37 +0000
commitb6b5a2dcd7cc4302d5f20e21ab637be1b03d1019 (patch)
tree18dd0ca96150a77d13077bf3f57b5ec33795adf3
parenta0f8d235c80192931ed1db0c4f300c67c361cd98 (diff)
downloadpdfium-b6b5a2dcd7cc4302d5f20e21ab637be1b03d1019.tar.xz
M68: Check GetObjDefnID() in various JS functions.
Consolidate all the checks into JSGetObject(), and add GetObjDefnID() methods for classes that are missing it. BUG=chromium:862059 Change-Id: I2c2b725a01dcd259ef712d2513fcf740cc410b15 Reviewed-on: https://pdfium-review.googlesource.com/37510 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> (cherry picked from commit ad1f7b410cd6885bd22d9ee49d9f80d3017f131f) Reviewed-on: https://pdfium-review.googlesource.com/38030 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r--fxjs/JS_Define.h27
-rw-r--r--fxjs/cjs_app.cpp5
-rw-r--r--fxjs/cjs_app.h1
-rw-r--r--fxjs/cjs_color.cpp5
-rw-r--r--fxjs/cjs_color.h1
-rw-r--r--fxjs/cjs_console.cpp5
-rw-r--r--fxjs/cjs_console.h1
-rw-r--r--fxjs/cjs_event.cpp5
-rw-r--r--fxjs/cjs_event.h1
-rw-r--r--fxjs/cjs_global.cpp5
-rw-r--r--fxjs/cjs_global.h1
-rw-r--r--fxjs/cjs_report.cpp5
-rw-r--r--fxjs/cjs_report.h1
-rw-r--r--fxjs/cjs_util.cpp5
-rw-r--r--fxjs/cjs_util.h1
15 files changed, 60 insertions, 9 deletions
diff --git a/fxjs/JS_Define.h b/fxjs/JS_Define.h
index d9ab139374..3e9c8734ef 100644
--- a/fxjs/JS_Define.h
+++ b/fxjs/JS_Define.h
@@ -58,6 +58,18 @@ static void JSConstructor(CFXJS_Engine* pEngine, v8::Local<v8::Object> obj) {
// CJS_Object has vitual dtor, template not required.
void JSDestructor(v8::Local<v8::Object> obj);
+template <class C>
+C* JSGetObject(CJS_Runtime* pRuntime, v8::Local<v8::Object> obj) {
+ if (CFXJS_Engine::GetObjDefnID(obj) != C::GetObjDefnID())
+ return nullptr;
+
+ CJS_Object* pJSObj = pRuntime->GetObjectPrivate(obj);
+ if (!pJSObj)
+ return nullptr;
+
+ return static_cast<C*>(pJSObj);
+}
+
template <class C, CJS_Return (C::*M)(CJS_Runtime*)>
void JSPropGetter(const char* prop_name_string,
const char* class_name_string,
@@ -68,11 +80,10 @@ void JSPropGetter(const char* prop_name_string,
if (!pRuntime)
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder());
- if (!pJSObj)
+ C* pObj = JSGetObject<C>(pRuntime, info.Holder());
+ if (!pObj)
return;
- C* pObj = static_cast<C*>(pJSObj);
CJS_Return result = (pObj->*M)(pRuntime);
if (result.HasError()) {
pRuntime->Error(JSFormatErrorString(class_name_string, prop_name_string,
@@ -95,11 +106,10 @@ void JSPropSetter(const char* prop_name_string,
if (!pRuntime)
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder());
- if (!pJSObj)
+ C* pObj = JSGetObject<C>(pRuntime, info.Holder());
+ if (!pObj)
return;
- C* pObj = static_cast<C*>(pJSObj);
CJS_Return result = (pObj->*M)(pRuntime, value);
if (result.HasError()) {
pRuntime->Error(JSFormatErrorString(class_name_string, prop_name_string,
@@ -118,15 +128,14 @@ void JSMethod(const char* method_name_string,
if (!pRuntime)
return;
- CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder());
- if (!pJSObj)
+ C* pObj = JSGetObject<C>(pRuntime, info.Holder());
+ if (!pObj)
return;
std::vector<v8::Local<v8::Value>> parameters;
for (unsigned int i = 0; i < (unsigned int)info.Length(); i++)
parameters.push_back(info[i]);
- C* pObj = static_cast<C*>(pJSObj);
CJS_Return result = (pObj->*M)(pRuntime, parameters);
if (result.HasError()) {
pRuntime->Error(JSFormatErrorString(class_name_string, method_name_string,
diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp
index 6c04c033b2..a791e773c4 100644
--- a/fxjs/cjs_app.cpp
+++ b/fxjs/cjs_app.cpp
@@ -84,6 +84,11 @@ int CJS_App::ObjDefnID = -1;
const char CJS_App::kName[] = "app";
// static
+int CJS_App::GetObjDefnID() {
+ return ObjDefnID;
+}
+
+// static
void CJS_App::DefineJSObjects(CFXJS_Engine* pEngine) {
ObjDefnID = pEngine->DefineObj(CJS_App::kName, FXJSOBJTYPE_STATIC,
JSConstructor<CJS_App>, JSDestructor);
diff --git a/fxjs/cjs_app.h b/fxjs/cjs_app.h
index e195c6db24..96db14845c 100644
--- a/fxjs/cjs_app.h
+++ b/fxjs/cjs_app.h
@@ -18,6 +18,7 @@ class GlobalTimer;
class CJS_App : public CJS_Object {
public:
+ static int GetObjDefnID();
static void DefineJSObjects(CFXJS_Engine* pEngine);
explicit CJS_App(v8::Local<v8::Object> pObject);
diff --git a/fxjs/cjs_color.cpp b/fxjs/cjs_color.cpp
index a0cb02a99c..6478b6f7fe 100644
--- a/fxjs/cjs_color.cpp
+++ b/fxjs/cjs_color.cpp
@@ -35,6 +35,11 @@ int CJS_Color::ObjDefnID = -1;
const char CJS_Color::kName[] = "color";
// static
+int CJS_Color::GetObjDefnID() {
+ return ObjDefnID;
+}
+
+// static
void CJS_Color::DefineJSObjects(CFXJS_Engine* pEngine) {
ObjDefnID = pEngine->DefineObj(CJS_Color::kName, FXJSOBJTYPE_STATIC,
JSConstructor<CJS_Color>, JSDestructor);
diff --git a/fxjs/cjs_color.h b/fxjs/cjs_color.h
index 667a13c21a..c1557ce653 100644
--- a/fxjs/cjs_color.h
+++ b/fxjs/cjs_color.h
@@ -14,6 +14,7 @@
class CJS_Color : public CJS_Object {
public:
+ static int GetObjDefnID();
static void DefineJSObjects(CFXJS_Engine* pEngine);
static v8::Local<v8::Array> ConvertPWLColorToArray(CJS_Runtime* pRuntime,
const CFX_Color& color);
diff --git a/fxjs/cjs_console.cpp b/fxjs/cjs_console.cpp
index 2b7c84ad78..5e160817d7 100644
--- a/fxjs/cjs_console.cpp
+++ b/fxjs/cjs_console.cpp
@@ -22,6 +22,11 @@ int CJS_Console::ObjDefnID = -1;
const char CJS_Console::kName[] = "console";
// static
+int CJS_Console::GetObjDefnID() {
+ return ObjDefnID;
+}
+
+// static
void CJS_Console::DefineJSObjects(CFXJS_Engine* pEngine) {
ObjDefnID = pEngine->DefineObj(CJS_Console::kName, FXJSOBJTYPE_STATIC,
JSConstructor<CJS_Console>, JSDestructor);
diff --git a/fxjs/cjs_console.h b/fxjs/cjs_console.h
index 56243cf6a5..09de94b788 100644
--- a/fxjs/cjs_console.h
+++ b/fxjs/cjs_console.h
@@ -13,6 +13,7 @@
class CJS_Console : public CJS_Object {
public:
+ static int GetObjDefnID();
static void DefineJSObjects(CFXJS_Engine* pEngine);
explicit CJS_Console(v8::Local<v8::Object> pObject);
diff --git a/fxjs/cjs_event.cpp b/fxjs/cjs_event.cpp
index 341bcc4147..4263689b9a 100644
--- a/fxjs/cjs_event.cpp
+++ b/fxjs/cjs_event.cpp
@@ -38,6 +38,11 @@ int CJS_Event::ObjDefnID = -1;
const char CJS_Event::kName[] = "event";
// static
+int CJS_Event::GetObjDefnID() {
+ return ObjDefnID;
+}
+
+// static
void CJS_Event::DefineJSObjects(CFXJS_Engine* pEngine) {
ObjDefnID = pEngine->DefineObj(CJS_Event::kName, FXJSOBJTYPE_STATIC,
JSConstructor<CJS_Event>, JSDestructor);
diff --git a/fxjs/cjs_event.h b/fxjs/cjs_event.h
index 291b6eb3cc..cb6b3fd527 100644
--- a/fxjs/cjs_event.h
+++ b/fxjs/cjs_event.h
@@ -11,6 +11,7 @@
class CJS_Event : public CJS_Object {
public:
+ static int GetObjDefnID();
static void DefineJSObjects(CFXJS_Engine* pEngine);
explicit CJS_Event(v8::Local<v8::Object> pObject);
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index 282b26210f..bf0f5efc10 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -198,6 +198,11 @@ void CJS_Global::DefineAllProperties(CFXJS_Engine* pEngine) {
}
// static
+int CJS_Global::GetObjDefnID() {
+ return ObjDefnID;
+}
+
+// static
void CJS_Global::DefineJSObjects(CFXJS_Engine* pEngine) {
ObjDefnID = pEngine->DefineObj("global", FXJSOBJTYPE_STATIC,
JSConstructor<CJS_Global>, JSDestructor);
diff --git a/fxjs/cjs_global.h b/fxjs/cjs_global.h
index 15ef603e45..7768405191 100644
--- a/fxjs/cjs_global.h
+++ b/fxjs/cjs_global.h
@@ -18,6 +18,7 @@ class CJS_GlobalData;
class CJS_Global : public CJS_Object {
public:
+ static int GetObjDefnID();
static void DefineJSObjects(CFXJS_Engine* pEngine);
static void DefineAllProperties(CFXJS_Engine* pEngine);
diff --git a/fxjs/cjs_report.cpp b/fxjs/cjs_report.cpp
index 2f5490c472..137ad4fca9 100644
--- a/fxjs/cjs_report.cpp
+++ b/fxjs/cjs_report.cpp
@@ -19,6 +19,11 @@ int CJS_Report::ObjDefnID = -1;
const char CJS_Report::kName[] = "Report";
// static
+int CJS_Report::GetObjDefnID() {
+ return ObjDefnID;
+}
+
+// static
void CJS_Report::DefineJSObjects(CFXJS_Engine* pEngine, FXJSOBJTYPE eObjType) {
ObjDefnID = pEngine->DefineObj(CJS_Report::kName, eObjType,
JSConstructor<CJS_Report>, JSDestructor);
diff --git a/fxjs/cjs_report.h b/fxjs/cjs_report.h
index 2a59206410..9c7d665c9c 100644
--- a/fxjs/cjs_report.h
+++ b/fxjs/cjs_report.h
@@ -13,6 +13,7 @@
class CJS_Report : public CJS_Object {
public:
+ static int GetObjDefnID();
static void DefineJSObjects(CFXJS_Engine* pEngine, FXJSOBJTYPE eObjType);
explicit CJS_Report(v8::Local<v8::Object> pObject);
diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp
index 883d022006..0184d44eb4 100644
--- a/fxjs/cjs_util.cpp
+++ b/fxjs/cjs_util.cpp
@@ -68,6 +68,11 @@ int CJS_Util::ObjDefnID = -1;
const char CJS_Util::kName[] = "util";
// static
+int CJS_Util::GetObjDefnID() {
+ return ObjDefnID;
+}
+
+// static
void CJS_Util::DefineJSObjects(CFXJS_Engine* pEngine) {
ObjDefnID = pEngine->DefineObj(CJS_Util::kName, FXJSOBJTYPE_STATIC,
JSConstructor<CJS_Util>, JSDestructor);
diff --git a/fxjs/cjs_util.h b/fxjs/cjs_util.h
index 0ad0fa101c..4055711b00 100644
--- a/fxjs/cjs_util.h
+++ b/fxjs/cjs_util.h
@@ -19,6 +19,7 @@
class CJS_Util : public CJS_Object {
public:
+ static int GetObjDefnID();
static void DefineJSObjects(CFXJS_Engine* pEngine);
explicit CJS_Util(v8::Local<v8::Object> pObject);