diff options
author | Lei Zhang <thestig@chromium.org> | 2018-07-11 13:04:43 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-07-11 13:04:43 +0000 |
commit | ad1f7b410cd6885bd22d9ee49d9f80d3017f131f (patch) | |
tree | 6a7a9fa616004ab6c457c46682dd00125952913b /fxjs/js_define.h | |
parent | b1a4db5551ca7c211c8acbec2b657d25fa7d7f1d (diff) | |
download | pdfium-ad1f7b410cd6885bd22d9ee49d9f80d3017f131f.tar.xz |
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>
Diffstat (limited to 'fxjs/js_define.h')
-rw-r--r-- | fxjs/js_define.h | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/fxjs/js_define.h b/fxjs/js_define.h index 01dfb15e2d..629cf1a02b 100644 --- a/fxjs/js_define.h +++ b/fxjs/js_define.h @@ -57,20 +57,31 @@ static void JSConstructor(CFXJS_Engine* pEngine, v8::Local<v8::Object> obj) { // CJS_Object has virtual dtor, template not required. void JSDestructor(v8::Local<v8::Object> obj); +template <class C> +C* JSGetObject(v8::Local<v8::Object> obj) { + if (CFXJS_Engine::GetObjDefnID(obj) != C::GetObjDefnID()) + return nullptr; + + CJS_Object* pJSObj = CFXJS_Engine::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, v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) { - CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(info.Holder()); - if (!pJSObj) + C* pObj = JSGetObject<C>(info.Holder()); + if (!pObj) return; - CJS_Runtime* pRuntime = pJSObj->GetRuntime(); + CJS_Runtime* pRuntime = pObj->GetRuntime(); if (!pRuntime) 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, @@ -88,15 +99,14 @@ void JSPropSetter(const char* prop_name_string, v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) { - CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(info.Holder()); - if (!pJSObj) + C* pObj = JSGetObject<C>(info.Holder()); + if (!pObj) return; - CJS_Runtime* pRuntime = pJSObj->GetRuntime(); + CJS_Runtime* pRuntime = pObj->GetRuntime(); if (!pRuntime) 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, @@ -110,11 +120,11 @@ template <class C, void JSMethod(const char* method_name_string, const char* class_name_string, const v8::FunctionCallbackInfo<v8::Value>& info) { - CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(info.Holder()); - if (!pJSObj) + C* pObj = JSGetObject<C>(info.Holder()); + if (!pObj) return; - CJS_Runtime* pRuntime = pJSObj->GetRuntime(); + CJS_Runtime* pRuntime = pObj->GetRuntime(); if (!pRuntime) return; @@ -122,7 +132,6 @@ void JSMethod(const char* method_name_string, 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, |