// Copyright 2017 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #ifndef FXJS_CJS_V8_H_ #define FXJS_CJS_V8_H_ #include #include #include #include #include "core/fxcrt/bytestring.h" #include "core/fxcrt/fx_string.h" #include "core/fxcrt/widestring.h" #ifdef PDF_ENABLE_XFA class CXFA_Object; #endif // PDF_ENABLE_XFA class CJS_V8 { public: explicit CJS_V8(v8::Isolate* pIsolate); virtual ~CJS_V8(); v8::Isolate* GetIsolate() const { return m_isolate; } v8::Local NewLocalContext(); v8::Local GetPersistentContext(); v8::Local NewNull(); v8::Local NewUndefined(); v8::Local NewArray(); v8::Local NewNumber(int number); v8::Local NewNumber(double number); v8::Local NewNumber(float number); v8::Local NewBoolean(bool b); v8::Local NewString(const ByteStringView& str); v8::Local NewString(const WideStringView& str); v8::Local NewDate(double d); int ToInt32(v8::Local pValue); bool ToBoolean(v8::Local pValue); double ToDouble(v8::Local pValue); WideString ToWideString(v8::Local pValue); ByteString ToByteString(v8::Local pValue); v8::Local ToObject(v8::Local pValue); v8::Local ToArray(v8::Local pValue); #ifdef PDF_ENABLE_XFA CXFA_Object* ToXFAObject(v8::Local obj); v8::Local NewXFAObject(CXFA_Object* obj, v8::Global& tmpl); #endif // PDF_ENABLE_XFA // Arrays. unsigned GetArrayLength(v8::Local pArray); v8::Local GetArrayElement(v8::Local pArray, unsigned index); unsigned PutArrayElement(v8::Local pArray, unsigned index, v8::Local pValue); void SetConstArray(const WideString& name, v8::Local array); v8::Local GetConstArray(const WideString& name); // Objects. std::vector GetObjectPropertyNames(v8::Local pObj); v8::Local GetObjectProperty(v8::Local pObj, const WideString& PropertyName); void PutObjectProperty(v8::Local pObj, const WideString& PropertyName, v8::Local pValue); protected: void SetIsolate(v8::Isolate* pIsolate) { m_isolate = pIsolate; } void ClearConstArray() { m_ConstArrays.clear(); } void ResetPersistentContext(v8::Local context) { m_V8PersistentContext.Reset(m_isolate, context); } void ReleasePersistentContext() { m_V8PersistentContext.Reset(); } private: v8::Isolate* m_isolate; std::map> m_ConstArrays; v8::Global m_V8PersistentContext; }; #endif // FXJS_CJS_V8_H_