diff options
author | dsinclair <dsinclair@chromium.org> | 2016-07-12 10:37:52 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-12 10:37:52 -0700 |
commit | 08fea801054f3afadb95d0a54efe7da6683c5c5d (patch) | |
tree | dc81937c50050c91e6f3ca483d2c0d9d1feceed0 /fxjs/include | |
parent | 5a6c1398d0e559fb6a048cb0dca46ba9f9309a77 (diff) | |
download | pdfium-08fea801054f3afadb95d0a54efe7da6683c5c5d.tar.xz |
Rename fxjse/ to fxjs/ update files to match class names.
This Cl moves the fxjse/ directory to fxjs/ in anticipation of merging in
fpdfsdk/jsapi. In the process the filenames are updated to better match the
class contents. Static methods are moved to anonymous namespaces as possible.
Review-Url: https://codereview.chromium.org/2136213002
Diffstat (limited to 'fxjs/include')
-rw-r--r-- | fxjs/include/cfxjse_arguments.h | 38 | ||||
-rw-r--r-- | fxjs/include/cfxjse_class.h | 45 | ||||
-rw-r--r-- | fxjs/include/cfxjse_context.h | 65 | ||||
-rw-r--r-- | fxjs/include/cfxjse_value.h | 102 | ||||
-rw-r--r-- | fxjs/include/fxjse.h | 74 |
5 files changed, 324 insertions, 0 deletions
diff --git a/fxjs/include/cfxjse_arguments.h b/fxjs/include/cfxjse_arguments.h new file mode 100644 index 0000000000..e6c8659732 --- /dev/null +++ b/fxjs/include/cfxjse_arguments.h @@ -0,0 +1,38 @@ +// 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 <memory> + +#include "fxjs/include/fxjse.h" + +class CFXJSE_Class; + +class CFXJSE_Arguments { + public: + CFXJSE_Arguments(const v8::FunctionCallbackInfo<v8::Value>* pInfo, + CFXJSE_Value* pRetValue) + : m_pInfo(pInfo), m_pRetValue(pRetValue) {} + + v8::Isolate* GetRuntime() const; + int32_t GetLength() const; + std::unique_ptr<CFXJSE_Value> 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<v8::Value>* 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 new file mode 100644 index 0000000000..13eb1adb7d --- /dev/null +++ b/fxjs/include/cfxjse_class.h @@ -0,0 +1,45 @@ +// 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<v8::ObjectTemplate>& hObjectTemplate, + const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition); + + ~CFXJSE_Class(); + + CFXJSE_Context* GetContext() { return m_pContext; } + v8::Global<v8::FunctionTemplate>& 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<v8::FunctionTemplate> 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 new file mode 100644 index 0000000000..882258fe57 --- /dev/null +++ b/fxjs/include/cfxjse_context.h @@ -0,0 +1,65 @@ +// 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 <memory> +#include <vector> + +#include "core/fxcrt/include/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<CFXJSE_Value> 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<v8::Context> m_hContext; + v8::Isolate* m_pIsolate; + std::vector<std::unique_ptr<CFXJSE_Class>> m_rgClasses; +}; + +v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate, + v8::TryCatch& trycatch); + +v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext( + const v8::Local<v8::Context>& hContext); + +void FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject, + CFXJSE_HostObject* lpNewBinding = nullptr); + +CFXJSE_HostObject* FXJSE_RetrieveObjectBinding( + const v8::Local<v8::Object>& 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 new file mode 100644 index 0000000000..7bb2c2d235 --- /dev/null +++ b/fxjs/include/cfxjse_value.h @@ -0,0 +1,102 @@ +// 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/include/fx_string.h" +#include "core/fxcrt/include/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<v8::Value>& DirectGetValue() const { return m_hValue; } + void ForceSetValue(v8::Local<v8::Value> 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<v8::Value> m_hValue; +}; + +#endif // FXJS_INCLUDE_CFXJSE_VALUE_H_ diff --git a/fxjs/include/fxjse.h b/fxjs/include/fxjse.h new file mode 100644 index 0000000000..79c32b053a --- /dev/null +++ b/fxjs/include/fxjse.h @@ -0,0 +1,74 @@ +// 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/include/fx_string.h" +#include "core/fxcrt/include/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_ |