| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #ifndef FXJSE_INCLUDE_CFXJSE_VALUE_H_ | |
| 8 #define FXJSE_INCLUDE_CFXJSE_VALUE_H_ | |
| 9 | |
| 10 #include "fxjse/scope_inline.h" | |
| 11 | |
| 12 class CFXJSE_Value { | |
| 13 public: | |
| 14 explicit CFXJSE_Value(v8::Isolate* pIsolate); | |
| 15 ~CFXJSE_Value(); | |
| 16 | |
| 17 FX_BOOL IsUndefined() const { | |
| 18 if (m_hValue.IsEmpty()) { | |
| 19 return FALSE; | |
| 20 } | |
| 21 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 22 v8::Local<v8::Value> hValue = | |
| 23 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 24 return hValue->IsUndefined(); | |
| 25 } | |
| 26 FX_BOOL IsNull() const { | |
| 27 if (m_hValue.IsEmpty()) { | |
| 28 return FALSE; | |
| 29 } | |
| 30 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 31 v8::Local<v8::Value> hValue = | |
| 32 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 33 return hValue->IsNull(); | |
| 34 } | |
| 35 FX_BOOL IsBoolean() const { | |
| 36 if (m_hValue.IsEmpty()) { | |
| 37 return FALSE; | |
| 38 } | |
| 39 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 40 v8::Local<v8::Value> hValue = | |
| 41 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 42 return hValue->IsBoolean(); | |
| 43 } | |
| 44 FX_BOOL IsString() const { | |
| 45 if (m_hValue.IsEmpty()) { | |
| 46 return FALSE; | |
| 47 } | |
| 48 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 49 v8::Local<v8::Value> hValue = | |
| 50 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 51 return hValue->IsString(); | |
| 52 } | |
| 53 FX_BOOL IsNumber() const { | |
| 54 if (m_hValue.IsEmpty()) { | |
| 55 return FALSE; | |
| 56 } | |
| 57 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 58 v8::Local<v8::Value> hValue = | |
| 59 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 60 return hValue->IsNumber(); | |
| 61 } | |
| 62 FX_BOOL IsInteger() const { | |
| 63 if (m_hValue.IsEmpty()) { | |
| 64 return FALSE; | |
| 65 } | |
| 66 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 67 v8::Local<v8::Value> hValue = | |
| 68 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 69 return hValue->IsInt32(); | |
| 70 } | |
| 71 FX_BOOL IsObject() const { | |
| 72 if (m_hValue.IsEmpty()) { | |
| 73 return FALSE; | |
| 74 } | |
| 75 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 76 v8::Local<v8::Value> hValue = | |
| 77 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 78 return hValue->IsObject(); | |
| 79 } | |
| 80 FX_BOOL IsArray() const { | |
| 81 if (m_hValue.IsEmpty()) { | |
| 82 return FALSE; | |
| 83 } | |
| 84 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 85 v8::Local<v8::Value> hValue = | |
| 86 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 87 return hValue->IsArray(); | |
| 88 } | |
| 89 FX_BOOL IsFunction() const { | |
| 90 if (m_hValue.IsEmpty()) { | |
| 91 return FALSE; | |
| 92 } | |
| 93 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 94 v8::Local<v8::Value> hValue = | |
| 95 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 96 return hValue->IsFunction(); | |
| 97 } | |
| 98 FX_BOOL IsDate() const { | |
| 99 if (m_hValue.IsEmpty()) { | |
| 100 return FALSE; | |
| 101 } | |
| 102 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 103 v8::Local<v8::Value> hValue = | |
| 104 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 105 return hValue->IsDate(); | |
| 106 } | |
| 107 | |
| 108 FX_BOOL ToBoolean() const { | |
| 109 ASSERT(!m_hValue.IsEmpty()); | |
| 110 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | |
| 111 v8::Local<v8::Value> hValue = | |
| 112 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 113 return static_cast<FX_BOOL>(hValue->BooleanValue()); | |
| 114 } | |
| 115 FX_FLOAT ToFloat() const { | |
| 116 ASSERT(!m_hValue.IsEmpty()); | |
| 117 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | |
| 118 v8::Local<v8::Value> hValue = | |
| 119 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 120 return static_cast<FX_FLOAT>(hValue->NumberValue()); | |
| 121 } | |
| 122 double ToDouble() const { | |
| 123 ASSERT(!m_hValue.IsEmpty()); | |
| 124 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | |
| 125 v8::Local<v8::Value> hValue = | |
| 126 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 127 return static_cast<double>(hValue->NumberValue()); | |
| 128 } | |
| 129 int32_t ToInteger() const { | |
| 130 ASSERT(!m_hValue.IsEmpty()); | |
| 131 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | |
| 132 v8::Local<v8::Value> hValue = | |
| 133 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 134 return static_cast<int32_t>(hValue->NumberValue()); | |
| 135 } | |
| 136 CFX_ByteString ToString() const { | |
| 137 ASSERT(!m_hValue.IsEmpty()); | |
| 138 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | |
| 139 v8::Local<v8::Value> hValue = | |
| 140 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | |
| 141 v8::Local<v8::String> hString = hValue->ToString(); | |
| 142 v8::String::Utf8Value hStringVal(hString); | |
| 143 return CFX_ByteString(*hStringVal); | |
| 144 } | |
| 145 CFX_WideString ToWideString() const { | |
| 146 return CFX_WideString::FromUTF8(ToString().AsStringC()); | |
| 147 } | |
| 148 CFXJSE_HostObject* ToHostObject(CFXJSE_Class* lpClass) const; | |
| 149 | |
| 150 void SetUndefined() { | |
| 151 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 152 v8::Local<v8::Value> hValue = v8::Undefined(m_pIsolate); | |
| 153 m_hValue.Reset(m_pIsolate, hValue); | |
| 154 } | |
| 155 void SetNull() { | |
| 156 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 157 v8::Local<v8::Value> hValue = v8::Null(m_pIsolate); | |
| 158 m_hValue.Reset(m_pIsolate, hValue); | |
| 159 } | |
| 160 void SetBoolean(FX_BOOL bBoolean) { | |
| 161 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 162 v8::Local<v8::Value> hValue = | |
| 163 v8::Boolean::New(m_pIsolate, bBoolean != FALSE); | |
| 164 m_hValue.Reset(m_pIsolate, hValue); | |
| 165 } | |
| 166 void SetInteger(int32_t nInteger) { | |
| 167 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 168 v8::Local<v8::Value> hValue = v8::Integer::New(m_pIsolate, nInteger); | |
| 169 m_hValue.Reset(m_pIsolate, hValue); | |
| 170 } | |
| 171 void SetDouble(double dDouble) { | |
| 172 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 173 v8::Local<v8::Value> hValue = v8::Number::New(m_pIsolate, dDouble); | |
| 174 m_hValue.Reset(m_pIsolate, hValue); | |
| 175 } | |
| 176 void SetString(const CFX_ByteStringC& szString) { | |
| 177 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | |
| 178 v8::Local<v8::Value> hValue = v8::String::NewFromUtf8( | |
| 179 m_pIsolate, reinterpret_cast<const char*>(szString.raw_str()), | |
| 180 v8::String::kNormalString, szString.GetLength()); | |
| 181 m_hValue.Reset(m_pIsolate, hValue); | |
| 182 } | |
| 183 void SetFloat(FX_FLOAT fFloat); | |
| 184 void SetJSObject() { | |
| 185 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | |
| 186 v8::Local<v8::Value> hValue = v8::Object::New(m_pIsolate); | |
| 187 m_hValue.Reset(m_pIsolate, hValue); | |
| 188 } | |
| 189 | |
| 190 void SetObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* pClass); | |
| 191 void SetHostObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* lpClass); | |
| 192 void SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues); | |
| 193 void SetDate(double dDouble); | |
| 194 | |
| 195 FX_BOOL GetObjectProperty(const CFX_ByteStringC& szPropName, | |
| 196 CFXJSE_Value* lpPropValue); | |
| 197 FX_BOOL SetObjectProperty(const CFX_ByteStringC& szPropName, | |
| 198 CFXJSE_Value* lpPropValue); | |
| 199 FX_BOOL GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); | |
| 200 FX_BOOL SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); | |
| 201 FX_BOOL DeleteObjectProperty(const CFX_ByteStringC& szPropName); | |
| 202 FX_BOOL HasObjectOwnProperty(const CFX_ByteStringC& szPropName, | |
| 203 FX_BOOL bUseTypeGetter); | |
| 204 FX_BOOL SetObjectOwnProperty(const CFX_ByteStringC& szPropName, | |
| 205 CFXJSE_Value* lpPropValue); | |
| 206 FX_BOOL SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis); | |
| 207 FX_BOOL Call(CFXJSE_Value* lpReceiver, | |
| 208 CFXJSE_Value* lpRetValue, | |
| 209 uint32_t nArgCount, | |
| 210 CFXJSE_Value** lpArgs); | |
| 211 | |
| 212 v8::Isolate* GetIsolate() const { return m_pIsolate; } | |
| 213 const v8::Global<v8::Value>& DirectGetValue() const { return m_hValue; } | |
| 214 void ForceSetValue(v8::Local<v8::Value> hValue) { | |
| 215 m_hValue.Reset(m_pIsolate, hValue); | |
| 216 } | |
| 217 void Assign(const CFXJSE_Value* lpValue) { | |
| 218 ASSERT(lpValue); | |
| 219 if (lpValue) { | |
| 220 m_hValue.Reset(m_pIsolate, lpValue->m_hValue); | |
| 221 } else { | |
| 222 m_hValue.Reset(); | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 private: | |
| 227 friend class CFXJSE_Class; | |
| 228 friend class CFXJSE_Context; | |
| 229 | |
| 230 CFXJSE_Value(); | |
| 231 CFXJSE_Value(const CFXJSE_Value&); | |
| 232 CFXJSE_Value& operator=(const CFXJSE_Value&); | |
| 233 | |
| 234 v8::Isolate* m_pIsolate; | |
| 235 v8::Global<v8::Value> m_hValue; | |
| 236 }; | |
| 237 | |
| 238 #endif // FXJSE_INCLUDE_CFXJSE_VALUE_H_ | |
| OLD | NEW |