• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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_XFA_CFXJSE_CONTEXT_H_
8 #define FXJS_XFA_CFXJSE_CONTEXT_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/fx_string.h"
14 #include "core/fxcrt/unowned_ptr.h"
15 #include "v8/include/v8.h"
16 
17 class CFXJS_Engine;
18 class CFXJSE_Class;
19 class CFXJSE_HostObject;
20 class CFXJSE_Value;
21 struct FXJSE_CLASS_DESCRIPTOR;
22 
23 class CFXJSE_Context {
24  public:
25   static std::unique_ptr<CFXJSE_Context> Create(
26       v8::Isolate* pIsolate,
27       const FXJSE_CLASS_DESCRIPTOR* pGlobalClass,
28       CFXJSE_HostObject* pGlobalObject);
29 
30   explicit CFXJSE_Context(v8::Isolate* pIsolate);
31   ~CFXJSE_Context();
32 
GetIsolate()33   v8::Isolate* GetIsolate() const { return m_pIsolate.Get(); }
34   v8::Local<v8::Context> GetContext();
35   std::unique_ptr<CFXJSE_Value> GetGlobalObject();
36   void AddClass(std::unique_ptr<CFXJSE_Class> pClass);
37   CFXJSE_Class* GetClassByName(ByteStringView szName) const;
38   void EnableCompatibleMode();
39   bool ExecuteScript(const char* szScript,
40                      CFXJSE_Value* lpRetValue,
41                      CFXJSE_Value* lpNewThisObject);
42 
43  private:
44   CFXJSE_Context(const CFXJSE_Context&) = delete;
45   CFXJSE_Context& operator=(const CFXJSE_Context&) = delete;
46 
47   v8::Global<v8::Context> m_hContext;
48   UnownedPtr<v8::Isolate> m_pIsolate;
49   std::vector<std::unique_ptr<CFXJSE_Class>> m_rgClasses;
50 };
51 
52 void FXJSE_UpdateObjectBinding(v8::Local<v8::Object> hObject,
53                                CFXJSE_HostObject* lpNewBinding);
54 
55 void FXJSE_ClearObjectBinding(v8::Local<v8::Object> hJSObject);
56 CFXJSE_HostObject* FXJSE_RetrieveObjectBinding(v8::Local<v8::Object> hJSObject);
57 
58 #endif  // FXJS_XFA_CFXJSE_CONTEXT_H_
59