John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 7 | #ifndef FXJS_CJS_OBJECT_H_ |
| 8 | #define FXJS_CJS_OBJECT_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Tom Sepez | 36aae4f | 2018-06-04 19:44:37 +0000 | [diff] [blame] | 10 | #include "core/fxcrt/unowned_ptr.h" |
Dan Sinclair | 00d47a6 | 2018-03-28 18:39:04 +0000 | [diff] [blame] | 11 | #include "fpdfsdk/cpdfsdk_helpers.h" |
Tom Sepez | b7c7df6 | 2018-02-09 19:08:59 +0000 | [diff] [blame] | 12 | #include "fxjs/cfxjs_engine.h" |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 13 | #include "fxjs/cjs_runtime.h" |
Tom Sepez | 8b4ddeb | 2018-06-11 15:55:17 +0000 | [diff] [blame] | 14 | #include "third_party/base/span.h" |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 15 | |
Dan Sinclair | d808dfd | 2017-10-26 15:04:17 -0400 | [diff] [blame] | 16 | struct JSConstSpec { |
| 17 | enum Type { Number = 0, String = 1 }; |
| 18 | |
| 19 | const char* pName; |
| 20 | Type eType; |
| 21 | double number; |
| 22 | const char* pStr; |
| 23 | }; |
| 24 | |
| 25 | struct JSPropertySpec { |
| 26 | const char* pName; |
| 27 | v8::AccessorGetterCallback pPropGet; |
| 28 | v8::AccessorSetterCallback pPropPut; |
| 29 | }; |
| 30 | |
| 31 | struct JSMethodSpec { |
| 32 | const char* pName; |
| 33 | v8::FunctionCallback pMethodCall; |
| 34 | }; |
| 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | class CJS_Object { |
| 37 | public: |
Dan Sinclair | d808dfd | 2017-10-26 15:04:17 -0400 | [diff] [blame] | 38 | static void DefineConsts(CFXJS_Engine* pEngine, |
| 39 | int objId, |
Tom Sepez | 8b4ddeb | 2018-06-11 15:55:17 +0000 | [diff] [blame] | 40 | pdfium::span<const JSConstSpec> consts); |
Dan Sinclair | d808dfd | 2017-10-26 15:04:17 -0400 | [diff] [blame] | 41 | static void DefineProps(CFXJS_Engine* pEngine, |
| 42 | int objId, |
Tom Sepez | 8b4ddeb | 2018-06-11 15:55:17 +0000 | [diff] [blame] | 43 | pdfium::span<const JSPropertySpec> consts); |
Dan Sinclair | d808dfd | 2017-10-26 15:04:17 -0400 | [diff] [blame] | 44 | static void DefineMethods(CFXJS_Engine* pEngine, |
| 45 | int objId, |
Tom Sepez | 8b4ddeb | 2018-06-11 15:55:17 +0000 | [diff] [blame] | 46 | pdfium::span<const JSMethodSpec> consts); |
Dan Sinclair | d808dfd | 2017-10-26 15:04:17 -0400 | [diff] [blame] | 47 | |
Tom Sepez | 36aae4f | 2018-06-04 19:44:37 +0000 | [diff] [blame] | 48 | CJS_Object(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 49 | virtual ~CJS_Object(); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 50 | |
Tom Sepez | 36aae4f | 2018-06-04 19:44:37 +0000 | [diff] [blame] | 51 | v8::Local<v8::Object> ToV8Object() { return m_pV8Object.Get(GetIsolate()); } |
| 52 | v8::Isolate* GetIsolate() const { return m_pIsolate.Get(); } |
| 53 | CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 54 | |
Tom Sepez | 36aae4f | 2018-06-04 19:44:37 +0000 | [diff] [blame] | 55 | private: |
| 56 | UnownedPtr<v8::Isolate> m_pIsolate; |
Tom Sepez | 116e4ad | 2015-09-21 09:22:05 -0700 | [diff] [blame] | 57 | v8::Global<v8::Object> m_pV8Object; |
Tom Sepez | 36aae4f | 2018-06-04 19:44:37 +0000 | [diff] [blame] | 58 | CJS_Runtime::ObservedPtr m_pRuntime; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 61 | #endif // FXJS_CJS_OBJECT_H_ |