1*3ac0a46fSAndroid Build Coastguard Worker // Copyright 2017 The PDFium Authors 2*3ac0a46fSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*3ac0a46fSAndroid Build Coastguard Worker // found in the LICENSE file. 4*3ac0a46fSAndroid Build Coastguard Worker 5*3ac0a46fSAndroid Build Coastguard Worker // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6*3ac0a46fSAndroid Build Coastguard Worker 7*3ac0a46fSAndroid Build Coastguard Worker #ifndef FXJS_CFX_V8_H_ 8*3ac0a46fSAndroid Build Coastguard Worker #define FXJS_CFX_V8_H_ 9*3ac0a46fSAndroid Build Coastguard Worker 10*3ac0a46fSAndroid Build Coastguard Worker #include <stddef.h> 11*3ac0a46fSAndroid Build Coastguard Worker 12*3ac0a46fSAndroid Build Coastguard Worker #include <vector> 13*3ac0a46fSAndroid Build Coastguard Worker 14*3ac0a46fSAndroid Build Coastguard Worker #include "core/fxcrt/fx_string.h" 15*3ac0a46fSAndroid Build Coastguard Worker #include "core/fxcrt/unowned_ptr.h" 16*3ac0a46fSAndroid Build Coastguard Worker #include "v8/include/v8-forward.h" 17*3ac0a46fSAndroid Build Coastguard Worker 18*3ac0a46fSAndroid Build Coastguard Worker class CFX_V8 { 19*3ac0a46fSAndroid Build Coastguard Worker public: 20*3ac0a46fSAndroid Build Coastguard Worker explicit CFX_V8(v8::Isolate* pIsolate); 21*3ac0a46fSAndroid Build Coastguard Worker virtual ~CFX_V8(); 22*3ac0a46fSAndroid Build Coastguard Worker GetIsolate()23*3ac0a46fSAndroid Build Coastguard Worker v8::Isolate* GetIsolate() const { return m_pIsolate; } 24*3ac0a46fSAndroid Build Coastguard Worker 25*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value> NewNull(); 26*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value> NewUndefined(); 27*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Array> NewArray(); 28*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Object> NewObject(); 29*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Number> NewNumber(int number); 30*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Number> NewNumber(double number); 31*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Number> NewNumber(float number); 32*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Boolean> NewBoolean(bool b); 33*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::String> NewString(ByteStringView str); 34*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::String> NewString(WideStringView str); 35*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Date> NewDate(double d); 36*3ac0a46fSAndroid Build Coastguard Worker 37*3ac0a46fSAndroid Build Coastguard Worker int ToInt32(v8::Local<v8::Value> pValue); 38*3ac0a46fSAndroid Build Coastguard Worker bool ToBoolean(v8::Local<v8::Value> pValue); 39*3ac0a46fSAndroid Build Coastguard Worker double ToDouble(v8::Local<v8::Value> pValue); 40*3ac0a46fSAndroid Build Coastguard Worker WideString ToWideString(v8::Local<v8::Value> pValue); 41*3ac0a46fSAndroid Build Coastguard Worker ByteString ToByteString(v8::Local<v8::Value> pValue); 42*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Object> ToObject(v8::Local<v8::Value> pValue); 43*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Array> ToArray(v8::Local<v8::Value> pValue); 44*3ac0a46fSAndroid Build Coastguard Worker 45*3ac0a46fSAndroid Build Coastguard Worker // Arrays. 46*3ac0a46fSAndroid Build Coastguard Worker size_t GetArrayLength(v8::Local<v8::Array> pArray); 47*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value> GetArrayElement(v8::Local<v8::Array> pArray, 48*3ac0a46fSAndroid Build Coastguard Worker size_t index); 49*3ac0a46fSAndroid Build Coastguard Worker void PutArrayElement(v8::Local<v8::Array> pArray, 50*3ac0a46fSAndroid Build Coastguard Worker size_t index, 51*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value> pValue); 52*3ac0a46fSAndroid Build Coastguard Worker 53*3ac0a46fSAndroid Build Coastguard Worker // Objects. 54*3ac0a46fSAndroid Build Coastguard Worker std::vector<WideString> GetObjectPropertyNames(v8::Local<v8::Object> pObj); 55*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value> GetObjectProperty(v8::Local<v8::Object> pObj, 56*3ac0a46fSAndroid Build Coastguard Worker ByteStringView bsUTF8PropertyName); 57*3ac0a46fSAndroid Build Coastguard Worker void PutObjectProperty(v8::Local<v8::Object> pObj, 58*3ac0a46fSAndroid Build Coastguard Worker ByteStringView bsUTF8PropertyName, 59*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value> pValue); 60*3ac0a46fSAndroid Build Coastguard Worker 61*3ac0a46fSAndroid Build Coastguard Worker protected: SetIsolate(v8::Isolate * pIsolate)62*3ac0a46fSAndroid Build Coastguard Worker void SetIsolate(v8::Isolate* pIsolate) { m_pIsolate = pIsolate; } 63*3ac0a46fSAndroid Build Coastguard Worker void DisposeIsolate(); 64*3ac0a46fSAndroid Build Coastguard Worker 65*3ac0a46fSAndroid Build Coastguard Worker private: 66*3ac0a46fSAndroid Build Coastguard Worker UnownedPtr<v8::Isolate> m_pIsolate; 67*3ac0a46fSAndroid Build Coastguard Worker }; 68*3ac0a46fSAndroid Build Coastguard Worker 69*3ac0a46fSAndroid Build Coastguard Worker // Use with std::unique_ptr<v8::Isolate> to dispose of isolates correctly. 70*3ac0a46fSAndroid Build Coastguard Worker struct CFX_V8IsolateDeleter { 71*3ac0a46fSAndroid Build Coastguard Worker void operator()(v8::Isolate* ptr); 72*3ac0a46fSAndroid Build Coastguard Worker }; 73*3ac0a46fSAndroid Build Coastguard Worker 74*3ac0a46fSAndroid Build Coastguard Worker #endif // FXJS_CFX_V8_H_ 75