From 409726af056ddeab7f6fe4cf2a844bc954e77e0f Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 30 Oct 2017 16:49:42 +0000 Subject: Move JS_Object to cjs_object This CL moves JS_Object.{cpp|h} to cjs_object.{cpp|h} and splits the cjs_embedobj out to its own files. Change-Id: I8eced9c613455638f4adeefd60e67f38c0c3c1a6 Reviewed-on: https://pdfium-review.googlesource.com/17036 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fpdfsdk/javascript/JS_Define.h | 2 +- fpdfsdk/javascript/JS_Object.cpp | 54 --------------------- fpdfsdk/javascript/JS_Object.h | 84 --------------------------------- fpdfsdk/javascript/JS_Value.cpp | 2 +- fpdfsdk/javascript/PublicMethods.cpp | 2 +- fpdfsdk/javascript/app.cpp | 2 +- fpdfsdk/javascript/cjs_annot.cpp | 2 +- fpdfsdk/javascript/cjs_embedobj.cpp | 13 +++++ fpdfsdk/javascript/cjs_embedobj.h | 25 ++++++++++ fpdfsdk/javascript/cjs_eventhandler.cpp | 2 +- fpdfsdk/javascript/cjs_global.cpp | 2 +- fpdfsdk/javascript/cjs_object.cpp | 47 ++++++++++++++++++ fpdfsdk/javascript/cjs_object.h | 68 ++++++++++++++++++++++++++ fpdfsdk/javascript/cjs_runtime.cpp | 2 +- fpdfsdk/javascript/color.cpp | 2 +- fpdfsdk/javascript/console.cpp | 2 +- fpdfsdk/javascript/event.cpp | 2 +- fpdfsdk/javascript/report.cpp | 2 +- fpdfsdk/javascript/util.cpp | 2 +- 19 files changed, 166 insertions(+), 151 deletions(-) delete mode 100644 fpdfsdk/javascript/JS_Object.cpp delete mode 100644 fpdfsdk/javascript/JS_Object.h create mode 100644 fpdfsdk/javascript/cjs_embedobj.cpp create mode 100644 fpdfsdk/javascript/cjs_embedobj.h create mode 100644 fpdfsdk/javascript/cjs_object.cpp create mode 100644 fpdfsdk/javascript/cjs_object.h (limited to 'fpdfsdk') diff --git a/fpdfsdk/javascript/JS_Define.h b/fpdfsdk/javascript/JS_Define.h index e0535fa6fc..5824011665 100644 --- a/fpdfsdk/javascript/JS_Define.h +++ b/fpdfsdk/javascript/JS_Define.h @@ -9,8 +9,8 @@ #include -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" +#include "fpdfsdk/javascript/cjs_object.h" #include "fpdfsdk/javascript/resource.h" #include "fxjs/fxjs_v8.h" diff --git a/fpdfsdk/javascript/JS_Object.cpp b/fpdfsdk/javascript/JS_Object.cpp deleted file mode 100644 index b6e63b540b..0000000000 --- a/fpdfsdk/javascript/JS_Object.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/javascript/JS_Object.h" - -#include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/cjs_event_context.h" - -CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : m_pJSObject(pJSObject) {} - -CJS_EmbedObj::~CJS_EmbedObj() {} - -// static -void CJS_Object::DefineConsts(CFXJS_Engine* pEngine, - int objId, - const JSConstSpec consts[]) { - for (size_t i = 0; consts[i].pName != 0; ++i) { - pEngine->DefineObjConst( - objId, consts[i].pName, - consts[i].eType == JSConstSpec::Number - ? pEngine->NewNumber(consts[i].number).As() - : pEngine->NewString(consts[i].pStr).As()); - } -} - -// static -void CJS_Object::DefineProps(CFXJS_Engine* pEngine, - int objId, - const JSPropertySpec props[]) { - for (size_t i = 0; props[i].pName != 0; ++i) { - pEngine->DefineObjProperty(objId, props[i].pName, props[i].pPropGet, - props[i].pPropPut); - } -} - -// static -void CJS_Object::DefineMethods(CFXJS_Engine* pEngine, - int objId, - const JSMethodSpec methods[]) { - for (size_t i = 0; methods[i].pName != 0; ++i) - pEngine->DefineObjMethod(objId, methods[i].pName, methods[i].pMethodCall); -} - -CJS_Object::CJS_Object(v8::Local pObject) { - m_pIsolate = pObject->GetIsolate(); - m_pV8Object.Reset(m_pIsolate, pObject); -} - -CJS_Object::~CJS_Object() {} - -void CJS_Object::InitInstance(IJS_Runtime* pIRuntime) {} diff --git a/fpdfsdk/javascript/JS_Object.h b/fpdfsdk/javascript/JS_Object.h deleted file mode 100644 index 20d5203397..0000000000 --- a/fpdfsdk/javascript/JS_Object.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ -#define FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ - -#include -#include - -#include "fpdfsdk/fsdk_define.h" -#include "fpdfsdk/javascript/cjs_runtime.h" -#include "fxjs/fxjs_v8.h" - -class CJS_EventContext; -class CJS_Object; -class CPDFSDK_FormFillEnvironment; - -struct JSConstSpec { - enum Type { Number = 0, String = 1 }; - - const char* pName; - Type eType; - double number; - const char* pStr; -}; - -struct JSPropertySpec { - const char* pName; - v8::AccessorGetterCallback pPropGet; - v8::AccessorSetterCallback pPropPut; -}; - -struct JSMethodSpec { - const char* pName; - v8::FunctionCallback pMethodCall; -}; - -class CJS_EmbedObj { - public: - explicit CJS_EmbedObj(CJS_Object* pJSObject); - virtual ~CJS_EmbedObj(); - - CJS_Object* GetJSObject() const { return m_pJSObject.Get(); } - - protected: - UnownedPtr const m_pJSObject; -}; - -class CJS_Object { - public: - static void DefineConsts(CFXJS_Engine* pEngine, - int objId, - const JSConstSpec consts[]); - static void DefineProps(CFXJS_Engine* pEngine, - int objId, - const JSPropertySpec props[]); - static void DefineMethods(CFXJS_Engine* pEngine, - int objId, - const JSMethodSpec methods[]); - - explicit CJS_Object(v8::Local pObject); - virtual ~CJS_Object(); - - virtual void InitInstance(IJS_Runtime* pIRuntime); - - v8::Local ToV8Object() { return m_pV8Object.Get(m_pIsolate); } - - // Takes ownership of |pObj|. - void SetEmbedObject(CJS_EmbedObj* pObj) { m_pEmbedObj.reset(pObj); } - CJS_EmbedObj* GetEmbedObject() const { return m_pEmbedObj.get(); } - - v8::Isolate* GetIsolate() const { return m_pIsolate; } - - protected: - std::unique_ptr m_pEmbedObj; - v8::Global m_pV8Object; - v8::Isolate* m_pIsolate; -}; - - -#endif // FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp index b8582e9b10..da09ff28ac 100644 --- a/fpdfsdk/javascript/JS_Value.cpp +++ b/fpdfsdk/javascript/JS_Value.cpp @@ -14,8 +14,8 @@ #include #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/cjs_document.h" +#include "fpdfsdk/javascript/cjs_object.h" namespace { diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index b4cc7bfa28..b2469ad218 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -20,11 +20,11 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/cjs_event_context.h" #include "fpdfsdk/javascript/cjs_eventhandler.h" #include "fpdfsdk/javascript/cjs_field.h" +#include "fpdfsdk/javascript/cjs_object.h" #include "fpdfsdk/javascript/cjs_runtime.h" #include "fpdfsdk/javascript/color.h" #include "fpdfsdk/javascript/resource.h" diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index 93af088b5c..8a91a1da39 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -13,11 +13,11 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/cjs_document.h" #include "fpdfsdk/javascript/cjs_event_context.h" #include "fpdfsdk/javascript/cjs_eventhandler.h" +#include "fpdfsdk/javascript/cjs_object.h" #include "fpdfsdk/javascript/cjs_runtime.h" #include "fpdfsdk/javascript/resource.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/javascript/cjs_annot.cpp b/fpdfsdk/javascript/cjs_annot.cpp index 84c8007309..fa7773fab4 100644 --- a/fpdfsdk/javascript/cjs_annot.cpp +++ b/fpdfsdk/javascript/cjs_annot.cpp @@ -7,9 +7,9 @@ #include "fpdfsdk/javascript/cjs_annot.h" #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/cjs_event_context.h" +#include "fpdfsdk/javascript/cjs_object.h" namespace { diff --git a/fpdfsdk/javascript/cjs_embedobj.cpp b/fpdfsdk/javascript/cjs_embedobj.cpp new file mode 100644 index 0000000000..fe17862e69 --- /dev/null +++ b/fpdfsdk/javascript/cjs_embedobj.cpp @@ -0,0 +1,13 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/javascript/cjs_embedobj.h" + +#include "fpdfsdk/javascript/cjs_object.h" + +CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : m_pJSObject(pJSObject) {} + +CJS_EmbedObj::~CJS_EmbedObj() {} diff --git a/fpdfsdk/javascript/cjs_embedobj.h b/fpdfsdk/javascript/cjs_embedobj.h new file mode 100644 index 0000000000..edc9ac5c11 --- /dev/null +++ b/fpdfsdk/javascript/cjs_embedobj.h @@ -0,0 +1,25 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_JAVASCRIPT_CJS_EMBEDOBJ_H_ +#define FPDFSDK_JAVASCRIPT_CJS_EMBEDOBJ_H_ + +#include "core/fxcrt/unowned_ptr.h" + +class CJS_Object; + +class CJS_EmbedObj { + public: + explicit CJS_EmbedObj(CJS_Object* pJSObject); + virtual ~CJS_EmbedObj(); + + CJS_Object* GetJSObject() const { return m_pJSObject.Get(); } + + protected: + UnownedPtr const m_pJSObject; +}; + +#endif // FPDFSDK_JAVASCRIPT_CJS_EMBEDOBJ_H_ diff --git a/fpdfsdk/javascript/cjs_eventhandler.cpp b/fpdfsdk/javascript/cjs_eventhandler.cpp index 9dcc029ce9..002f6b0fd8 100644 --- a/fpdfsdk/javascript/cjs_eventhandler.cpp +++ b/fpdfsdk/javascript/cjs_eventhandler.cpp @@ -8,11 +8,11 @@ #include "core/fpdfdoc/cpdf_formfield.h" #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/cjs_document.h" #include "fpdfsdk/javascript/cjs_event_context.h" #include "fpdfsdk/javascript/cjs_field.h" +#include "fpdfsdk/javascript/cjs_object.h" #include "fpdfsdk/javascript/cjs_runtime.h" CJS_EventHandler::CJS_EventHandler(CJS_EventContext* pContext) diff --git a/fpdfsdk/javascript/cjs_global.cpp b/fpdfsdk/javascript/cjs_global.cpp index 658cc86f16..5ef4d09894 100644 --- a/fpdfsdk/javascript/cjs_global.cpp +++ b/fpdfsdk/javascript/cjs_global.cpp @@ -15,10 +15,10 @@ #include "fpdfsdk/javascript/JS_Define.h" #include "fpdfsdk/javascript/JS_GlobalData.h" #include "fpdfsdk/javascript/JS_KeyValue.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/cjs_event_context.h" #include "fpdfsdk/javascript/cjs_eventhandler.h" +#include "fpdfsdk/javascript/cjs_object.h" #include "fpdfsdk/javascript/resource.h" namespace { diff --git a/fpdfsdk/javascript/cjs_object.cpp b/fpdfsdk/javascript/cjs_object.cpp new file mode 100644 index 0000000000..282dfaf83d --- /dev/null +++ b/fpdfsdk/javascript/cjs_object.cpp @@ -0,0 +1,47 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/javascript/cjs_object.h" + +// static +void CJS_Object::DefineConsts(CFXJS_Engine* pEngine, + int objId, + const JSConstSpec consts[]) { + for (size_t i = 0; consts[i].pName != 0; ++i) { + pEngine->DefineObjConst( + objId, consts[i].pName, + consts[i].eType == JSConstSpec::Number + ? pEngine->NewNumber(consts[i].number).As() + : pEngine->NewString(consts[i].pStr).As()); + } +} + +// static +void CJS_Object::DefineProps(CFXJS_Engine* pEngine, + int objId, + const JSPropertySpec props[]) { + for (size_t i = 0; props[i].pName != 0; ++i) { + pEngine->DefineObjProperty(objId, props[i].pName, props[i].pPropGet, + props[i].pPropPut); + } +} + +// static +void CJS_Object::DefineMethods(CFXJS_Engine* pEngine, + int objId, + const JSMethodSpec methods[]) { + for (size_t i = 0; methods[i].pName != 0; ++i) + pEngine->DefineObjMethod(objId, methods[i].pName, methods[i].pMethodCall); +} + +CJS_Object::CJS_Object(v8::Local pObject) { + m_pIsolate = pObject->GetIsolate(); + m_pV8Object.Reset(m_pIsolate, pObject); +} + +CJS_Object::~CJS_Object() {} + +void CJS_Object::InitInstance(IJS_Runtime* pIRuntime) {} diff --git a/fpdfsdk/javascript/cjs_object.h b/fpdfsdk/javascript/cjs_object.h new file mode 100644 index 0000000000..85dd19ccce --- /dev/null +++ b/fpdfsdk/javascript/cjs_object.h @@ -0,0 +1,68 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_JAVASCRIPT_CJS_OBJECT_H_ +#define FPDFSDK_JAVASCRIPT_CJS_OBJECT_H_ + +#include + +#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/javascript/cjs_embedobj.h" +#include "fpdfsdk/javascript/cjs_runtime.h" +#include "fxjs/fxjs_v8.h" + +struct JSConstSpec { + enum Type { Number = 0, String = 1 }; + + const char* pName; + Type eType; + double number; + const char* pStr; +}; + +struct JSPropertySpec { + const char* pName; + v8::AccessorGetterCallback pPropGet; + v8::AccessorSetterCallback pPropPut; +}; + +struct JSMethodSpec { + const char* pName; + v8::FunctionCallback pMethodCall; +}; + +class CJS_Object { + public: + static void DefineConsts(CFXJS_Engine* pEngine, + int objId, + const JSConstSpec consts[]); + static void DefineProps(CFXJS_Engine* pEngine, + int objId, + const JSPropertySpec props[]); + static void DefineMethods(CFXJS_Engine* pEngine, + int objId, + const JSMethodSpec methods[]); + + explicit CJS_Object(v8::Local pObject); + virtual ~CJS_Object(); + + virtual void InitInstance(IJS_Runtime* pIRuntime); + + v8::Local ToV8Object() { return m_pV8Object.Get(m_pIsolate); } + + // Takes ownership of |pObj|. + void SetEmbedObject(CJS_EmbedObj* pObj) { m_pEmbedObj.reset(pObj); } + CJS_EmbedObj* GetEmbedObject() const { return m_pEmbedObj.get(); } + + v8::Isolate* GetIsolate() const { return m_pIsolate; } + + protected: + std::unique_ptr m_pEmbedObj; + v8::Global m_pV8Object; + v8::Isolate* m_pIsolate; +}; + +#endif // FPDFSDK_JAVASCRIPT_CJS_OBJECT_H_ diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index 177a6f43ac..64123ce395 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -11,7 +11,6 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/javascript/JS_Define.h" #include "fpdfsdk/javascript/JS_GlobalData.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/PublicMethods.h" #include "fpdfsdk/javascript/app.h" @@ -28,6 +27,7 @@ #include "fpdfsdk/javascript/cjs_globalconsts.h" #include "fpdfsdk/javascript/cjs_highlight.h" #include "fpdfsdk/javascript/cjs_icon.h" +#include "fpdfsdk/javascript/cjs_object.h" #include "fpdfsdk/javascript/cjs_position.h" #include "fpdfsdk/javascript/cjs_printparamsobj.h" #include "fpdfsdk/javascript/cjs_scalehow.h" diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp index cb6503a06a..405f12d0f3 100644 --- a/fpdfsdk/javascript/color.cpp +++ b/fpdfsdk/javascript/color.cpp @@ -9,10 +9,10 @@ #include #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/cjs_event_context.h" #include "fpdfsdk/javascript/cjs_eventhandler.h" +#include "fpdfsdk/javascript/cjs_object.h" #include "fpdfsdk/javascript/cjs_runtime.h" const JSPropertySpec CJS_Color::PropertySpecs[] = { diff --git a/fpdfsdk/javascript/console.cpp b/fpdfsdk/javascript/console.cpp index c3cb8b7da7..81db44d2a1 100644 --- a/fpdfsdk/javascript/console.cpp +++ b/fpdfsdk/javascript/console.cpp @@ -9,10 +9,10 @@ #include #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/cjs_event_context.h" #include "fpdfsdk/javascript/cjs_eventhandler.h" +#include "fpdfsdk/javascript/cjs_object.h" const JSMethodSpec CJS_Console::MethodSpecs[] = {{"clear", clear_static}, {"hide", hide_static}, diff --git a/fpdfsdk/javascript/event.cpp b/fpdfsdk/javascript/event.cpp index cd40c204e7..7682a64033 100644 --- a/fpdfsdk/javascript/event.cpp +++ b/fpdfsdk/javascript/event.cpp @@ -7,11 +7,11 @@ #include "fpdfsdk/javascript/event.h" #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/cjs_event_context.h" #include "fpdfsdk/javascript/cjs_eventhandler.h" #include "fpdfsdk/javascript/cjs_field.h" +#include "fpdfsdk/javascript/cjs_object.h" const JSPropertySpec CJS_Event::PropertySpecs[] = { {"change", get_change_static, set_change_static}, diff --git a/fpdfsdk/javascript/report.cpp b/fpdfsdk/javascript/report.cpp index 3e18cb8909..676451af82 100644 --- a/fpdfsdk/javascript/report.cpp +++ b/fpdfsdk/javascript/report.cpp @@ -9,8 +9,8 @@ #include #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" +#include "fpdfsdk/javascript/cjs_object.h" const JSMethodSpec CJS_Report::MethodSpecs[] = {{"save", save_static}, {"writeText", writeText_static}, diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp index 4b0db62583..a8f5486c35 100644 --- a/fpdfsdk/javascript/util.cpp +++ b/fpdfsdk/javascript/util.cpp @@ -16,11 +16,11 @@ #include "core/fxcrt/fx_extension.h" #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/JS_Object.h" #include "fpdfsdk/javascript/JS_Value.h" #include "fpdfsdk/javascript/PublicMethods.h" #include "fpdfsdk/javascript/cjs_event_context.h" #include "fpdfsdk/javascript/cjs_eventhandler.h" +#include "fpdfsdk/javascript/cjs_object.h" #include "fpdfsdk/javascript/cjs_runtime.h" #include "fpdfsdk/javascript/resource.h" -- cgit v1.2.3