• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The PDFium Authors
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/span.h"
11 #include "core/fxcrt/unowned_ptr.h"
12 #include "fxjs/cfxjs_engine.h"
13 #include "fxjs/cjs_runtime.h"
14 
15 struct JSConstSpec {
16   enum Type { Number = 0, String = 1 };
17 
18   const char* pName;
19   Type eType;
20   double number;
21   const char* pStr;
22 };
23 
24 struct JSPropertySpec {
25   const char* pName;
26   v8::AccessorNameGetterCallback pPropGet;
27   v8::AccessorNameSetterCallback pPropPut;
28 };
29 
30 struct JSMethodSpec {
31   const char* pName;
32   v8::FunctionCallback pMethodCall;
33 };
34 
35 class CJS_Object : public CFXJS_PerObjectData::Binding {
36  public:
37   static void DefineConsts(CFXJS_Engine* pEngine,
38                            uint32_t nObjDefnID,
39                            pdfium::span<const JSConstSpec> consts);
40   static void DefineProps(CFXJS_Engine* pEngine,
41                           uint32_t nObjDefnID,
42                           pdfium::span<const JSPropertySpec> consts);
43   static void DefineMethods(CFXJS_Engine* pEngine,
44                             uint32_t nObjDefnID,
45                             pdfium::span<const JSMethodSpec> consts);
46 
47   CJS_Object(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime);
48   ~CJS_Object() override;
49 
ToV8Object()50   v8::Local<v8::Object> ToV8Object() {
51     return m_pV8Object.Get(GetRuntime()->GetIsolate());
52   }
GetRuntime()53   CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); }
54 
55  private:
56   v8::Global<v8::Object> m_pV8Object;
57   ObservedPtr<CJS_Runtime> m_pRuntime;
58 };
59 
60 #endif  // FXJS_CJS_OBJECT_H_
61