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_CFXJSE_CONTEXT_H_ 8 #define FXJS_CFXJSE_CONTEXT_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "fxjs/fxjse.h" 14 #include "v8/include/v8.h" 15 16 class CFXJSE_Class; 17 class CFXJSE_Value; 18 struct FXJSE_CLASS_DESCRIPTOR; 19 20 class CFXJSE_Context { 21 public: 22 static std::unique_ptr<CFXJSE_Context> Create( 23 v8::Isolate* pIsolate, 24 const FXJSE_CLASS_DESCRIPTOR* pGlobalClass, 25 CFXJSE_HostObject* pGlobalObject); 26 27 explicit CFXJSE_Context(v8::Isolate* pIsolate); 28 ~CFXJSE_Context(); 29 GetIsolate()30 v8::Isolate* GetIsolate() const { return m_pIsolate; } 31 v8::Local<v8::Context> GetContext(); 32 std::unique_ptr<CFXJSE_Value> GetGlobalObject(); 33 void AddClass(std::unique_ptr<CFXJSE_Class> pClass); 34 CFXJSE_Class* GetClassByName(const ByteStringView& szName) const; 35 void EnableCompatibleMode(); 36 bool ExecuteScript(const char* szScript, 37 CFXJSE_Value* lpRetValue, 38 CFXJSE_Value* lpNewThisObject = nullptr); 39 40 protected: 41 friend class CFXJSE_ScopeUtil_IsolateHandleContext; 42 43 CFXJSE_Context(); 44 CFXJSE_Context(const CFXJSE_Context&); 45 CFXJSE_Context& operator=(const CFXJSE_Context&); 46 47 v8::Global<v8::Context> m_hContext; 48 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 = nullptr); 54 55 CFXJSE_HostObject* FXJSE_RetrieveObjectBinding(v8::Local<v8::Object> hJSObject, 56 CFXJSE_Class* lpClass = nullptr); 57 58 #endif // FXJS_CFXJSE_CONTEXT_H_ 59