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. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef FXJS_CJS_OBJECT_H_ 8 #define FXJS_CJS_OBJECT_H_ 9 10 #include "core/fxcrt/unowned_ptr.h" 11 #include "fxjs/cjs_runtime.h" 12 #include "third_party/base/span.h" 13 14 class CFXJS_Engine; 15 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 36 class CJS_Object { 37 public: 38 static void DefineConsts(CFXJS_Engine* pEngine, 39 int objId, 40 pdfium::span<const JSConstSpec> consts); 41 static void DefineProps(CFXJS_Engine* pEngine, 42 int objId, 43 pdfium::span<const JSPropertySpec> consts); 44 static void DefineMethods(CFXJS_Engine* pEngine, 45 int objId, 46 pdfium::span<const JSMethodSpec> consts); 47 48 CJS_Object(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime); 49 virtual ~CJS_Object(); 50 ToV8Object()51 v8::Local<v8::Object> ToV8Object() { return m_pV8Object.Get(GetIsolate()); } GetIsolate()52 v8::Isolate* GetIsolate() const { return m_pIsolate.Get(); } GetRuntime()53 CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); } 54 55 private: 56 UnownedPtr<v8::Isolate> m_pIsolate; 57 v8::Global<v8::Object> m_pV8Object; 58 ObservedPtr<CJS_Runtime> m_pRuntime; 59 }; 60 61 #endif // FXJS_CJS_OBJECT_H_ 62