summaryrefslogtreecommitdiff
path: root/xfa/src/fxjse/src/value.h
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/src/fxjse/src/value.h')
-rw-r--r--xfa/src/fxjse/src/value.h236
1 files changed, 236 insertions, 0 deletions
diff --git a/xfa/src/fxjse/src/value.h b/xfa/src/fxjse/src/value.h
new file mode 100644
index 0000000000..aca23bf310
--- /dev/null
+++ b/xfa/src/fxjse/src/value.h
@@ -0,0 +1,236 @@
+// 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 FXJSE_VALUE_H_
+#define FXJSE_VALUE_H_
+#include "scope_inline.h"
+class CFXJSE_Value : public CFX_Object
+{
+public:
+ CFXJSE_Value(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {}
+protected:
+ CFXJSE_Value();
+ CFXJSE_Value(const CFXJSE_Value&);
+ CFXJSE_Value& operator = (const CFXJSE_Value&);
+public:
+ V8_INLINE FX_BOOL IsUndefined() const
+ {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsUndefined();
+ }
+ V8_INLINE FX_BOOL IsNull() const
+ {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsNull();
+ }
+ V8_INLINE FX_BOOL IsBoolean() const
+ {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsBoolean();
+ }
+ V8_INLINE FX_BOOL IsString() const
+ {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsString();
+ }
+ V8_INLINE FX_BOOL IsNumber() const
+ {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsNumber();
+ }
+ V8_INLINE FX_BOOL IsInteger() const
+ {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsInt32();
+ }
+ V8_INLINE FX_BOOL IsObject() const
+ {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsObject();
+ }
+ V8_INLINE FX_BOOL IsArray() const
+ {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsArray();
+ }
+ V8_INLINE FX_BOOL IsFunction() const
+ {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsFunction();
+ }
+ V8_INLINE FX_BOOL IsDate() const
+ {
+ if (m_hValue.IsEmpty()) {
+ return FALSE;
+ }
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return hValue->IsDate();
+ }
+public:
+ V8_INLINE FX_BOOL ToBoolean() const
+ {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return static_cast<FX_BOOL>(hValue->BooleanValue());
+ }
+ V8_INLINE FX_FLOAT ToFloat() const
+ {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return static_cast<FX_FLOAT>(hValue->NumberValue());
+ }
+ V8_INLINE FXJSE_DOUBLE ToDouble() const
+ {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return static_cast<FXJSE_DOUBLE>(hValue->NumberValue());
+ }
+ V8_INLINE FX_INT32 ToInteger() const
+ {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ return static_cast<FX_INT32>(hValue->NumberValue());
+ }
+ V8_INLINE void ToString(CFX_ByteString& szStrOutput) const
+ {
+ ASSERT(!m_hValue.IsEmpty());
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
+ v8::Local<v8::String> hString = hValue->ToString();
+ v8::String::Utf8Value hStringVal(hString);
+ szStrOutput = *hStringVal;
+ }
+ FX_LPVOID ToObject(CFXJSE_Class* lpClass) const;
+public:
+ V8_INLINE void SetUndefined()
+ {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Undefined(m_pIsolate);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetNull()
+ {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Null(m_pIsolate);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetBoolean(FX_BOOL bBoolean)
+ {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Boolean::New(m_pIsolate, bBoolean != FALSE);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetInteger(FX_INT32 nInteger)
+ {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Integer::New(m_pIsolate, nInteger);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetDouble(FXJSE_DOUBLE dDouble)
+ {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Number::New(m_pIsolate, dDouble);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetString(FX_BSTR szString)
+ {
+ CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::String::NewFromUtf8(m_pIsolate,
+ reinterpret_cast<const char*>(szString.GetPtr()),
+ v8::String::kNormalString, szString.GetLength());
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void SetFloat(FX_FLOAT fFloat);
+ V8_INLINE void SetJSObject()
+ {
+ CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
+ v8::Local<v8::Value> hValue = v8::Object::New(m_pIsolate);
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ void SetHostObject(FX_LPVOID lpObject, CFXJSE_Class* lpClass);
+ void SetArray(FX_UINT32 uValueCount, CFXJSE_Value** rgValues);
+ void SetDate(FXJSE_DOUBLE dDouble);
+public:
+ FX_BOOL GetObjectProperty(FX_BSTR szPropName, CFXJSE_Value* lpPropValue);
+ FX_BOOL SetObjectProperty(FX_BSTR szPropName, CFXJSE_Value* lpPropValue);
+ FX_BOOL GetObjectProperty(FX_UINT32 uPropIdx, CFXJSE_Value* lpPropValue);
+ FX_BOOL SetObjectProperty(FX_UINT32 uPropIdx, CFXJSE_Value* lpPropValue);
+ FX_BOOL DeleteObjectProperty(FX_BSTR szPropName);
+ FX_BOOL HasObjectOwnProperty(FX_BSTR szPropName, FX_BOOL bUseTypeGetter);
+ FX_BOOL SetObjectOwnProperty(FX_BSTR szPropName, CFXJSE_Value* lpPropValue);
+ FX_BOOL SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis);
+ FX_BOOL Call(CFXJSE_Value* lpReceiver, CFXJSE_Value* lpRetValue, FX_UINT32 nArgCount, FXJSE_HVALUE* lpArgs);
+public:
+ V8_INLINE v8::Isolate* GetIsolate() const
+ {
+ return m_pIsolate;
+ }
+ V8_INLINE const v8::Persistent<v8::Value>& DirectGetValue() const
+ {
+ return m_hValue;
+ }
+ V8_INLINE void ForceSetValue(v8::Local<v8::Value> hValue)
+ {
+ m_hValue.Reset(m_pIsolate, hValue);
+ }
+ V8_INLINE void Assign(const CFXJSE_Value* lpValue)
+ {
+ if(lpValue) {
+ m_hValue.Reset(m_pIsolate, lpValue->m_hValue);
+ } else {
+ m_hValue.Reset();
+ }
+ }
+public:
+ static CFXJSE_Value* Create(v8::Isolate* pIsolate);
+protected:
+ v8::Isolate* m_pIsolate;
+ v8::Persistent<v8::Value> m_hValue;
+ friend class CFXJSE_Context;
+ friend class CFXJSE_Class;
+};
+#endif