From 435546810a7c48f09889c00600ad344850b71f95 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 29 Sep 2016 17:29:48 -0700 Subject: Move fxjs/include to fxjs BUG=pdfium:611 Review-Url: https://codereview.chromium.org/2380713005 --- fxjs/include/cfxjse_arguments.h | 38 ------ fxjs/include/cfxjse_class.h | 45 ------- fxjs/include/cfxjse_context.h | 65 ---------- fxjs/include/cfxjse_value.h | 102 ---------------- fxjs/include/fxjs_v8.h | 262 ---------------------------------------- fxjs/include/fxjse.h | 74 ------------ 6 files changed, 586 deletions(-) delete mode 100644 fxjs/include/cfxjse_arguments.h delete mode 100644 fxjs/include/cfxjse_class.h delete mode 100644 fxjs/include/cfxjse_context.h delete mode 100644 fxjs/include/cfxjse_value.h delete mode 100644 fxjs/include/fxjs_v8.h delete mode 100644 fxjs/include/fxjse.h (limited to 'fxjs/include') diff --git a/fxjs/include/cfxjse_arguments.h b/fxjs/include/cfxjse_arguments.h deleted file mode 100644 index e6c8659732..0000000000 --- a/fxjs/include/cfxjse_arguments.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2016 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_INCLUDE_CFXJSE_ARGUMENTS_H_ -#define FXJS_INCLUDE_CFXJSE_ARGUMENTS_H_ - -#include - -#include "fxjs/include/fxjse.h" - -class CFXJSE_Class; - -class CFXJSE_Arguments { - public: - CFXJSE_Arguments(const v8::FunctionCallbackInfo* pInfo, - CFXJSE_Value* pRetValue) - : m_pInfo(pInfo), m_pRetValue(pRetValue) {} - - v8::Isolate* GetRuntime() const; - int32_t GetLength() const; - std::unique_ptr GetValue(int32_t index) const; - FX_BOOL GetBoolean(int32_t index) const; - int32_t GetInt32(int32_t index) const; - FX_FLOAT GetFloat(int32_t index) const; - CFX_ByteString GetUTF8String(int32_t index) const; - CFXJSE_HostObject* GetObject(int32_t index, - CFXJSE_Class* pClass = nullptr) const; - CFXJSE_Value* GetReturnValue(); - - private: - const v8::FunctionCallbackInfo* m_pInfo; - CFXJSE_Value* m_pRetValue; -}; - -#endif // FXJS_INCLUDE_CFXJSE_ARGUMENTS_H_ diff --git a/fxjs/include/cfxjse_class.h b/fxjs/include/cfxjse_class.h deleted file mode 100644 index 13eb1adb7d..0000000000 --- a/fxjs/include/cfxjse_class.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2014 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_INCLUDE_CFXJSE_CLASS_H_ -#define FXJS_INCLUDE_CFXJSE_CLASS_H_ - -#include "fxjs/include/cfxjse_arguments.h" -#include "fxjs/include/fxjse.h" -#include "v8/include/v8.h" - -class CFXJSE_Context; -class CFXJSE_Value; - -class CFXJSE_Class { - public: - static CFXJSE_Class* Create(CFXJSE_Context* pContext, - const FXJSE_CLASS_DESCRIPTOR* lpClassDefintion, - FX_BOOL bIsJSGlobal = FALSE); - static CFXJSE_Class* GetClassFromContext(CFXJSE_Context* pContext, - const CFX_ByteStringC& szName); - static void SetUpNamedPropHandler( - v8::Isolate* pIsolate, - v8::Local& hObjectTemplate, - const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition); - - ~CFXJSE_Class(); - - CFXJSE_Context* GetContext() { return m_pContext; } - v8::Global& GetTemplate() { return m_hTemplate; } - - protected: - explicit CFXJSE_Class(CFXJSE_Context* lpContext); - - CFX_ByteString m_szClassName; - const FXJSE_CLASS_DESCRIPTOR* m_lpClassDefinition; - CFXJSE_Context* m_pContext; - v8::Global m_hTemplate; - friend class CFXJSE_Context; - friend class CFXJSE_Value; -}; - -#endif // FXJS_INCLUDE_CFXJSE_CLASS_H_ diff --git a/fxjs/include/cfxjse_context.h b/fxjs/include/cfxjse_context.h deleted file mode 100644 index 669fa89517..0000000000 --- a/fxjs/include/cfxjse_context.h +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2016 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_INCLUDE_CFXJSE_CONTEXT_H_ -#define FXJS_INCLUDE_CFXJSE_CONTEXT_H_ - -#include -#include - -#include "core/fxcrt/fx_basic.h" -#include "fxjs/include/fxjse.h" -#include "v8/include/v8.h" - -class CFXJSE_Class; -class CFXJSE_Value; -struct FXJSE_CLASS_DESCRIPTOR; - -class CFXJSE_Context { - public: - static CFXJSE_Context* Create( - v8::Isolate* pIsolate, - const FXJSE_CLASS_DESCRIPTOR* lpGlobalClass = nullptr, - CFXJSE_HostObject* lpGlobalObject = nullptr); - - ~CFXJSE_Context(); - - v8::Isolate* GetRuntime() { return m_pIsolate; } - std::unique_ptr GetGlobalObject(); - void EnableCompatibleMode(); - FX_BOOL ExecuteScript(const FX_CHAR* szScript, - CFXJSE_Value* lpRetValue, - CFXJSE_Value* lpNewThisObject = nullptr); - - protected: - friend class CFXJSE_Class; - friend class CFXJSE_ScopeUtil_IsolateHandleContext; - - CFXJSE_Context(); - CFXJSE_Context(const CFXJSE_Context&); - explicit CFXJSE_Context(v8::Isolate* pIsolate); - - CFXJSE_Context& operator=(const CFXJSE_Context&); - - v8::Global m_hContext; - v8::Isolate* m_pIsolate; - std::vector> m_rgClasses; -}; - -v8::Local FXJSE_CreateReturnValue(v8::Isolate* pIsolate, - v8::TryCatch& trycatch); - -v8::Local FXJSE_GetGlobalObjectFromContext( - const v8::Local& hContext); - -void FXJSE_UpdateObjectBinding(v8::Local& hObject, - CFXJSE_HostObject* lpNewBinding = nullptr); - -CFXJSE_HostObject* FXJSE_RetrieveObjectBinding( - const v8::Local& hJSObject, - CFXJSE_Class* lpClass = nullptr); - -#endif // FXJS_INCLUDE_CFXJSE_CONTEXT_H_ diff --git a/fxjs/include/cfxjse_value.h b/fxjs/include/cfxjse_value.h deleted file mode 100644 index 9fd1bee786..0000000000 --- a/fxjs/include/cfxjse_value.h +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2014 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_INCLUDE_CFXJSE_VALUE_H_ -#define FXJS_INCLUDE_CFXJSE_VALUE_H_ - -#include "v8/include/v8.h" - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "fxjs/cfxjse_isolatetracker.h" -#include "fxjs/cfxjse_runtimedata.h" - -class CFXJSE_Class; -class CFXJSE_HostObject; - -class CFXJSE_Value { - public: - explicit CFXJSE_Value(v8::Isolate* pIsolate); - ~CFXJSE_Value(); - - FX_BOOL IsUndefined() const; - FX_BOOL IsNull() const; - FX_BOOL IsBoolean() const; - FX_BOOL IsString() const; - FX_BOOL IsNumber() const; - FX_BOOL IsInteger() const; - FX_BOOL IsObject() const; - FX_BOOL IsArray() const; - FX_BOOL IsFunction() const; - FX_BOOL IsDate() const; - FX_BOOL ToBoolean() const; - FX_FLOAT ToFloat() const; - double ToDouble() const; - int32_t ToInteger() const; - CFX_ByteString ToString() const; - CFX_WideString ToWideString() const { - return CFX_WideString::FromUTF8(ToString().AsStringC()); - } - CFXJSE_HostObject* ToHostObject(CFXJSE_Class* lpClass) const; - - void SetUndefined(); - void SetNull(); - void SetBoolean(FX_BOOL bBoolean); - void SetInteger(int32_t nInteger); - void SetDouble(double dDouble); - void SetString(const CFX_ByteStringC& szString); - void SetFloat(FX_FLOAT fFloat); - void SetJSObject(); - - void SetObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* pClass); - void SetHostObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* lpClass); - void SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues); - void SetDate(double dDouble); - - FX_BOOL GetObjectProperty(const CFX_ByteStringC& szPropName, - CFXJSE_Value* lpPropValue); - FX_BOOL SetObjectProperty(const CFX_ByteStringC& szPropName, - CFXJSE_Value* lpPropValue); - FX_BOOL GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); - FX_BOOL SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); - FX_BOOL DeleteObjectProperty(const CFX_ByteStringC& szPropName); - FX_BOOL HasObjectOwnProperty(const CFX_ByteStringC& szPropName, - FX_BOOL bUseTypeGetter); - FX_BOOL SetObjectOwnProperty(const CFX_ByteStringC& szPropName, - CFXJSE_Value* lpPropValue); - FX_BOOL SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis); - FX_BOOL Call(CFXJSE_Value* lpReceiver, - CFXJSE_Value* lpRetValue, - uint32_t nArgCount, - CFXJSE_Value** lpArgs); - - v8::Isolate* GetIsolate() const { return m_pIsolate; } - const v8::Global& DirectGetValue() const { return m_hValue; } - void ForceSetValue(v8::Local hValue) { - m_hValue.Reset(m_pIsolate, hValue); - } - void Assign(const CFXJSE_Value* lpValue) { - ASSERT(lpValue); - if (lpValue) { - m_hValue.Reset(m_pIsolate, lpValue->m_hValue); - } else { - m_hValue.Reset(); - } - } - - private: - friend class CFXJSE_Class; - friend class CFXJSE_Context; - - CFXJSE_Value(); - CFXJSE_Value(const CFXJSE_Value&); - CFXJSE_Value& operator=(const CFXJSE_Value&); - - v8::Isolate* m_pIsolate; - v8::Global m_hValue; -}; - -#endif // FXJS_INCLUDE_CFXJSE_VALUE_H_ diff --git a/fxjs/include/fxjs_v8.h b/fxjs/include/fxjs_v8.h deleted file mode 100644 index a9064f3faf..0000000000 --- a/fxjs/include/fxjs_v8.h +++ /dev/null @@ -1,262 +0,0 @@ -// Copyright 2014 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 - -// FXJS_V8 is a layer that makes it easier to define native objects in V8, but -// has no knowledge of PDF-specific native objects. It could in theory be used -// to implement other sets of native objects. - -// PDFium code should include this file rather than including V8 headers -// directly. - -#ifndef FXJS_INCLUDE_FXJS_V8_H_ -#define FXJS_INCLUDE_FXJS_V8_H_ - -#include -#include - -#include -#include -#include - -#include "core/fxcrt/fx_string.h" -#ifdef PDF_ENABLE_XFA -// Header for CFXJSE_RuntimeData. FXJS_V8 doesn't interpret this class, -// it is just passed along to XFA. -#include "fxjs/cfxjse_runtimedata.h" -#endif // PDF_ENABLE_XFA - -class CFXJS_Engine; -class CFXJS_ObjDefinition; - -// FXJS_V8 places no restrictions on this class; it merely passes it -// on to caller-provided methods. -class IJS_Context; // A description of the event that caused JS execution. - -enum FXJSOBJTYPE { - FXJSOBJTYPE_DYNAMIC = 0, // Created by native method and returned to JS. - FXJSOBJTYPE_STATIC, // Created by init and hung off of global object. - FXJSOBJTYPE_GLOBAL, // The global object itself (may only appear once). -}; - -struct FXJSErr { - const wchar_t* message; - const wchar_t* srcline; - unsigned linnum; -}; - -// Global weak map to save dynamic objects. -class V8TemplateMapTraits : public v8::StdMapTraits { - public: - typedef v8::GlobalValueMap MapType; - typedef void WeakCallbackDataType; - - static WeakCallbackDataType* WeakCallbackParameter( - MapType* map, - void* key, - const v8::Local& value) { - return key; - } - static MapType* MapFromWeakCallbackInfo( - const v8::WeakCallbackInfo&); - - static void* KeyFromWeakCallbackInfo( - const v8::WeakCallbackInfo& data) { - return data.GetParameter(); - } - static const v8::PersistentContainerCallbackType kCallbackType = - v8::kWeakWithInternalFields; - static void DisposeWeak( - const v8::WeakCallbackInfo& data) {} - static void OnWeakCallback( - const v8::WeakCallbackInfo& data) {} - static void Dispose(v8::Isolate* isolate, - v8::Global value, - void* key); - static void DisposeCallbackData(WeakCallbackDataType* callbackData) {} -}; - -class V8TemplateMap { - public: - typedef v8::GlobalValueMap MapType; - - explicit V8TemplateMap(v8::Isolate* isolate); - ~V8TemplateMap(); - - void set(void* key, v8::Local handle); - - friend class V8TemplateMapTraits; - - private: - MapType m_map; -}; - -class FXJS_PerIsolateData { - public: - ~FXJS_PerIsolateData(); - - static void SetUp(v8::Isolate* pIsolate); - static FXJS_PerIsolateData* Get(v8::Isolate* pIsolate); - - std::vector> m_ObjectDefnArray; -#ifdef PDF_ENABLE_XFA - std::unique_ptr m_pFXJSERuntimeData; -#endif // PDF_ENABLE_XFA - std::unique_ptr m_pDynamicObjsMap; - - protected: - explicit FXJS_PerIsolateData(v8::Isolate* pIsolate); -}; - -class FXJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { - void* Allocate(size_t length) override; - void* AllocateUninitialized(size_t length) override; - void Free(void* data, size_t length) override; -}; - -void FXJS_Initialize(unsigned int embedderDataSlot, v8::Isolate* pIsolate); -void FXJS_Release(); - -// Gets the global isolate set by FXJS_Initialize(), or makes a new one each -// time if there is no such isolate. Returns true if a new isolate had to be -// created. -bool FXJS_GetIsolate(v8::Isolate** pResultIsolate); - -// Get the global isolate's ref count. -size_t FXJS_GlobalIsolateRefCount(); - -class CFXJS_Engine { - public: - explicit CFXJS_Engine(v8::Isolate* pIsolate); - ~CFXJS_Engine(); - - using Constructor = void (*)(CFXJS_Engine* pEngine, - v8::Local obj); - using Destructor = void (*)(CFXJS_Engine* pEngine, v8::Local obj); - - static CFXJS_Engine* CurrentEngineFromIsolate(v8::Isolate* pIsolate); - static int GetObjDefnID(v8::Local pObj); - -#ifdef PDF_ENABLE_XFA - // Called as part of FXJS_InitializeEngine, exposed so PDF can make its - // own contexts compatible with XFA or vice versa. - static void SetForV8Context(v8::Local v8Context, - CFXJS_Engine* pEngine); -#endif // PDF_ENABLE_XFA - - v8::Isolate* GetIsolate() const { return m_isolate; } - - // Always returns a valid, newly-created objDefnID. - int DefineObj(const wchar_t* sObjName, - FXJSOBJTYPE eObjType, - Constructor pConstructor, - Destructor pDestructor); - - void DefineObjMethod(int nObjDefnID, - const wchar_t* sMethodName, - v8::FunctionCallback pMethodCall); - void DefineObjProperty(int nObjDefnID, - const wchar_t* sPropName, - v8::AccessorGetterCallback pPropGet, - v8::AccessorSetterCallback pPropPut); - void DefineObjAllProperties(int nObjDefnID, - v8::NamedPropertyQueryCallback pPropQurey, - v8::NamedPropertyGetterCallback pPropGet, - v8::NamedPropertySetterCallback pPropPut, - v8::NamedPropertyDeleterCallback pPropDel); - void DefineObjConst(int nObjDefnID, - const wchar_t* sConstName, - v8::Local pDefault); - void DefineGlobalMethod(const wchar_t* sMethodName, - v8::FunctionCallback pMethodCall); - void DefineGlobalConst(const wchar_t* sConstName, - v8::FunctionCallback pConstGetter); - - // Called after FXJS_Define* calls made. - void InitializeEngine(); - void ReleaseEngine(); - - // Called after FXJS_InitializeEngine call made. - int Execute(const CFX_WideString& script, FXJSErr* perror); - - v8::Local NewLocalContext(); - v8::Local GetPersistentContext(); - - v8::Local NewNull(); - 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 wchar_t* str); - v8::Local NewDate(double d); - v8::Local NewFxDynamicObj(int nObjDefnID, bool bStatic = false); - - v8::Local GetThisObj(); - int ToInt32(v8::Local pValue); - bool ToBoolean(v8::Local pValue); - double ToNumber(v8::Local pValue); - CFX_WideString ToString(v8::Local pValue); - v8::Local ToObject(v8::Local pValue); - v8::Local ToArray(v8::Local pValue); - - unsigned GetArrayLength(v8::Local pArray); - v8::Local GetArrayElement(v8::Local pArray, - unsigned index); - unsigned PutArrayElement(v8::Local pArray, - unsigned index, - v8::Local pValue); - - std::vector GetObjectPropertyNames( - v8::Local pObj); - v8::Local GetObjectProperty(v8::Local pObj, - const CFX_WideString& PropertyName); - - void PutObjectString(v8::Local pObj, - const CFX_WideString& wsPropertyName, - const CFX_WideString& wsValue); - void PutObjectNumber(v8::Local pObj, - const CFX_WideString& PropertyName, - int nValue); - void PutObjectNumber(v8::Local pObj, - const CFX_WideString& PropertyName, - float fValue); - void PutObjectNumber(v8::Local pObj, - const CFX_WideString& PropertyName, - double dValue); - void PutObjectBoolean(v8::Local pObj, - const CFX_WideString& PropertyName, - bool bValue); - void PutObjectObject(v8::Local pObj, - const CFX_WideString& PropertyName, - v8::Local pPut); - void PutObjectNull(v8::Local pObj, - const CFX_WideString& PropertyName); - - // Native object binding. - void SetObjectPrivate(v8::Local pObj, void* p); - void* GetObjectPrivate(v8::Local pObj); - static void FreeObjectPrivate(void* p); - static void FreeObjectPrivate(v8::Local pObj); - - void SetConstArray(const CFX_WideString& name, v8::Local array); - v8::Local GetConstArray(const CFX_WideString& name); - - v8::Local WSToJSString(const CFX_WideString& wsPropertyName); - void Error(const CFX_WideString& message); - - protected: - CFXJS_Engine(); - - void SetIsolate(v8::Isolate* pIsolate) { m_isolate = pIsolate; } - - private: - v8::Isolate* m_isolate; - v8::Global m_V8PersistentContext; - std::vector*> m_StaticObjects; - std::map> m_ConstArrays; -}; - -#endif // FXJS_INCLUDE_FXJS_V8_H_ diff --git a/fxjs/include/fxjse.h b/fxjs/include/fxjse.h deleted file mode 100644 index eafae88d2d..0000000000 --- a/fxjs/include/fxjse.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2014 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_INCLUDE_FXJSE_H_ -#define FXJS_INCLUDE_FXJSE_H_ - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "v8/include/v8.h" - -class CFXJSE_Arguments; -class CFXJSE_Value; - -// C++ object which can be wrapped by CFXJSE_value. -class CFXJSE_HostObject { - public: - virtual ~CFXJSE_HostObject() {} -}; - -typedef void (*FXJSE_FuncCallback)(CFXJSE_Value* pThis, - const CFX_ByteStringC& szFuncName, - CFXJSE_Arguments& args); -typedef void (*FXJSE_PropAccessor)(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pValue); -typedef int32_t (*FXJSE_PropTypeGetter)(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName, - FX_BOOL bQueryIn); -typedef FX_BOOL (*FXJSE_PropDeleter)(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName); - -enum FXJSE_ClassPropTypes { - FXJSE_ClassPropType_None, - FXJSE_ClassPropType_Property, - FXJSE_ClassPropType_Method -}; - -struct FXJSE_FUNCTION_DESCRIPTOR { - const FX_CHAR* name; - FXJSE_FuncCallback callbackProc; -}; - -struct FXJSE_PROPERTY_DESCRIPTOR { - const FX_CHAR* name; - FXJSE_PropAccessor getProc; - FXJSE_PropAccessor setProc; -}; - -struct FXJSE_CLASS_DESCRIPTOR { - const FX_CHAR* name; - FXJSE_FuncCallback constructor; - const FXJSE_PROPERTY_DESCRIPTOR* properties; - const FXJSE_FUNCTION_DESCRIPTOR* methods; - int32_t propNum; - int32_t methNum; - FXJSE_PropTypeGetter dynPropTypeGetter; - FXJSE_PropAccessor dynPropGetter; - FXJSE_PropAccessor dynPropSetter; - FXJSE_PropDeleter dynPropDeleter; - FXJSE_FuncCallback dynMethodCall; -}; - -void FXJSE_Initialize(); -void FXJSE_Finalize(); - -v8::Isolate* FXJSE_Runtime_Create_Own(); -void FXJSE_Runtime_Release(v8::Isolate* pIsolate); - -void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Message); - -#endif // FXJS_INCLUDE_FXJSE_H_ -- cgit v1.2.3