| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "JS_Value.h" | 7 #include "JS_Value.h" |
| 8 | 8 |
| 9 #include <time.h> | 9 #include <time.h> |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 #include <limits> | 11 #include <limits> |
| 12 | 12 |
| 13 #include "Document.h" | 13 #include "Document.h" |
| 14 #include "JS_Define.h" | 14 #include "JS_Define.h" |
| 15 #include "JS_Object.h" | 15 #include "JS_Object.h" |
| 16 | 16 |
| 17 static const FX_DWORD g_nan[2] = {0, 0x7FF80000}; | 17 static const FX_DWORD g_nan[2] = {0, 0x7FF80000}; |
| 18 static double GetNan() { | 18 static double GetNan() { |
| 19 return *(double*)g_nan; | 19 return *(double*)g_nan; |
| 20 } | 20 } |
| 21 | 21 |
| 22 /* ---------------------------- CJS_Value ---------------------------- */ | 22 /* ---------------------------- CJS_Value ---------------------------- */ |
| 23 | 23 |
| 24 CJS_Value::CJS_Value(v8::Isolate* isolate) | 24 CJS_Value::CJS_Value(CJS_Runtime* pRuntime) |
| 25 : m_eType(VT_unknown), m_isolate(isolate) {} | 25 : m_eType(VT_unknown), m_pJSRuntime(pRuntime) { |
| 26 CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, Type t) | |
| 27 : m_eType(t), m_pValue(pValue), m_isolate(isolate) { | |
| 28 } | 26 } |
| 29 | 27 |
| 30 CJS_Value::CJS_Value(v8::Isolate* isolate, const int& iValue) | 28 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue, Type t) |
| 31 : m_isolate(isolate) { | 29 : m_eType(t), m_pValue(pValue), m_pJSRuntime(pRuntime) { |
| 30 } |
| 31 |
| 32 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue) |
| 33 : m_pJSRuntime(pRuntime) { |
| 32 operator=(iValue); | 34 operator=(iValue); |
| 33 } | 35 } |
| 34 | 36 |
| 35 CJS_Value::CJS_Value(v8::Isolate* isolate, const bool& bValue) | 37 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const bool& bValue) |
| 36 : m_isolate(isolate) { | 38 : m_pJSRuntime(pRuntime) { |
| 37 operator=(bValue); | 39 operator=(bValue); |
| 38 } | 40 } |
| 39 | 41 |
| 40 CJS_Value::CJS_Value(v8::Isolate* isolate, const float& fValue) | 42 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const float& fValue) |
| 41 : m_isolate(isolate) { | 43 : m_pJSRuntime(pRuntime) { |
| 42 operator=(fValue); | 44 operator=(fValue); |
| 43 } | 45 } |
| 44 | 46 |
| 45 CJS_Value::CJS_Value(v8::Isolate* isolate, const double& dValue) | 47 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const double& dValue) |
| 46 : m_isolate(isolate) { | 48 : m_pJSRuntime(pRuntime) { |
| 47 operator=(dValue); | 49 operator=(dValue); |
| 48 } | 50 } |
| 49 | 51 |
| 50 CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Local<v8::Object> pJsObj) | 52 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Object> pJsObj) |
| 51 : m_isolate(isolate) { | 53 : m_pJSRuntime(pRuntime) { |
| 52 operator=(pJsObj); | 54 operator=(pJsObj); |
| 53 } | 55 } |
| 54 | 56 |
| 55 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Object* pJsObj) | 57 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pJsObj) |
| 56 : m_isolate(isolate) { | 58 : m_pJSRuntime(pRuntime) { |
| 57 operator=(pJsObj); | 59 operator=(pJsObj); |
| 58 } | 60 } |
| 59 | 61 |
| 60 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Document* pJsDoc) | 62 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Document* pJsDoc) |
| 61 : m_isolate(isolate) { | 63 : m_pJSRuntime(pRuntime) { |
| 62 m_eType = VT_object; | 64 m_eType = VT_object; |
| 63 if (pJsDoc) | 65 if (pJsDoc) |
| 64 m_pValue = pJsDoc->ToV8Object(); | 66 m_pValue = pJsDoc->ToV8Object(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr) | 69 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr) |
| 68 : m_isolate(isolate) { | 70 : m_pJSRuntime(pRuntime) { |
| 69 operator=(pWstr); | 71 operator=(pWstr); |
| 70 } | 72 } |
| 71 | 73 |
| 72 CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_CHAR* pStr) | 74 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr) |
| 73 : m_isolate(isolate) { | 75 : m_pJSRuntime(pRuntime) { |
| 74 operator=(pStr); | 76 operator=(pStr); |
| 75 } | 77 } |
| 76 | 78 |
| 77 CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array) | 79 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Array& array) |
| 78 : m_isolate(isolate) { | 80 : m_pJSRuntime(pRuntime) { |
| 79 operator=(array); | 81 operator=(array); |
| 80 } | 82 } |
| 81 | 83 |
| 82 CJS_Value::~CJS_Value() {} | 84 CJS_Value::~CJS_Value() {} |
| 83 | 85 |
| 84 void CJS_Value::Attach(v8::Local<v8::Value> pValue, Type t) { | 86 void CJS_Value::Attach(v8::Local<v8::Value> pValue, Type t) { |
| 85 m_pValue = pValue; | 87 m_pValue = pValue; |
| 86 m_eType = t; | 88 m_eType = t; |
| 87 } | 89 } |
| 88 | 90 |
| 89 void CJS_Value::Attach(CJS_Value* pValue) { | 91 void CJS_Value::Attach(CJS_Value* pValue) { |
| 90 if (pValue) | 92 if (pValue) |
| 91 Attach(pValue->ToV8Value(), pValue->GetType()); | 93 Attach(pValue->ToV8Value(), pValue->GetType()); |
| 92 } | 94 } |
| 93 | 95 |
| 94 void CJS_Value::Detach() { | 96 void CJS_Value::Detach() { |
| 95 m_pValue = v8::Local<v8::Value>(); | 97 m_pValue = v8::Local<v8::Value>(); |
| 96 m_eType = VT_unknown; | 98 m_eType = VT_unknown; |
| 97 } | 99 } |
| 98 | 100 |
| 99 /* -----------------------------------------------------------------------------
----------- | 101 /* -----------------------------------------------------------------------------
----------- |
| 100 */ | 102 */ |
| 101 | 103 |
| 102 int CJS_Value::ToInt() const { | 104 int CJS_Value::ToInt() const { |
| 103 return FXJS_ToInt32(m_isolate, m_pValue); | 105 return FXJS_ToInt32(m_pJSRuntime->GetIsolate(), m_pValue); |
| 104 } | 106 } |
| 105 | 107 |
| 106 bool CJS_Value::ToBool() const { | 108 bool CJS_Value::ToBool() const { |
| 107 return FXJS_ToBoolean(m_isolate, m_pValue); | 109 return FXJS_ToBoolean(m_pJSRuntime->GetIsolate(), m_pValue); |
| 108 } | 110 } |
| 109 | 111 |
| 110 double CJS_Value::ToDouble() const { | 112 double CJS_Value::ToDouble() const { |
| 111 return FXJS_ToNumber(m_isolate, m_pValue); | 113 return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pValue); |
| 112 } | 114 } |
| 113 | 115 |
| 114 float CJS_Value::ToFloat() const { | 116 float CJS_Value::ToFloat() const { |
| 115 return (float)ToDouble(); | 117 return (float)ToDouble(); |
| 116 } | 118 } |
| 117 | 119 |
| 118 CJS_Object* CJS_Value::ToCJSObject() const { | 120 CJS_Object* CJS_Value::ToCJSObject() const { |
| 119 v8::Local<v8::Object> pObj = FXJS_ToObject(m_isolate, m_pValue); | 121 v8::Local<v8::Object> pObj = |
| 120 return (CJS_Object*)FXJS_GetPrivate(m_isolate, pObj); | 122 FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue); |
| 123 return (CJS_Object*)FXJS_GetPrivate(m_pJSRuntime->GetIsolate(), pObj); |
| 121 } | 124 } |
| 122 | 125 |
| 123 v8::Local<v8::Object> CJS_Value::ToV8Object() const { | 126 v8::Local<v8::Object> CJS_Value::ToV8Object() const { |
| 124 return FXJS_ToObject(m_isolate, m_pValue); | 127 return FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue); |
| 125 } | 128 } |
| 126 | 129 |
| 127 CFX_WideString CJS_Value::ToCFXWideString() const { | 130 CFX_WideString CJS_Value::ToCFXWideString() const { |
| 128 return FXJS_ToString(m_isolate, m_pValue); | 131 return FXJS_ToString(m_pJSRuntime->GetIsolate(), m_pValue); |
| 129 } | 132 } |
| 130 | 133 |
| 131 CFX_ByteString CJS_Value::ToCFXByteString() const { | 134 CFX_ByteString CJS_Value::ToCFXByteString() const { |
| 132 return CFX_ByteString::FromUnicode(ToCFXWideString()); | 135 return CFX_ByteString::FromUnicode(ToCFXWideString()); |
| 133 } | 136 } |
| 134 | 137 |
| 135 v8::Local<v8::Value> CJS_Value::ToV8Value() const { | 138 v8::Local<v8::Value> CJS_Value::ToV8Value() const { |
| 136 return m_pValue; | 139 return m_pValue; |
| 137 } | 140 } |
| 138 | 141 |
| 139 v8::Local<v8::Array> CJS_Value::ToV8Array() const { | 142 v8::Local<v8::Array> CJS_Value::ToV8Array() const { |
| 140 if (IsArrayObject()) | 143 if (IsArrayObject()) |
| 141 return v8::Local<v8::Array>::Cast(FXJS_ToObject(m_isolate, m_pValue)); | 144 return v8::Local<v8::Array>::Cast( |
| 145 FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue)); |
| 142 return v8::Local<v8::Array>(); | 146 return v8::Local<v8::Array>(); |
| 143 } | 147 } |
| 144 | 148 |
| 145 /* -----------------------------------------------------------------------------
----------- | 149 /* -----------------------------------------------------------------------------
----------- |
| 146 */ | 150 */ |
| 147 | 151 |
| 148 void CJS_Value::operator=(int iValue) { | 152 void CJS_Value::operator=(int iValue) { |
| 149 m_pValue = FXJS_NewNumber(m_isolate, iValue); | 153 m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), iValue); |
| 150 m_eType = VT_number; | 154 m_eType = VT_number; |
| 151 } | 155 } |
| 152 | 156 |
| 153 void CJS_Value::operator=(bool bValue) { | 157 void CJS_Value::operator=(bool bValue) { |
| 154 m_pValue = FXJS_NewBoolean(m_isolate, bValue); | 158 m_pValue = FXJS_NewBoolean(m_pJSRuntime->GetIsolate(), bValue); |
| 155 m_eType = VT_boolean; | 159 m_eType = VT_boolean; |
| 156 } | 160 } |
| 157 | 161 |
| 158 void CJS_Value::operator=(double dValue) { | 162 void CJS_Value::operator=(double dValue) { |
| 159 m_pValue = FXJS_NewNumber(m_isolate, dValue); | 163 m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), dValue); |
| 160 m_eType = VT_number; | 164 m_eType = VT_number; |
| 161 } | 165 } |
| 162 | 166 |
| 163 void CJS_Value::operator=(float fValue) { | 167 void CJS_Value::operator=(float fValue) { |
| 164 m_pValue = FXJS_NewNumber(m_isolate, fValue); | 168 m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), fValue); |
| 165 m_eType = VT_number; | 169 m_eType = VT_number; |
| 166 } | 170 } |
| 167 | 171 |
| 168 void CJS_Value::operator=(v8::Local<v8::Object> pObj) { | 172 void CJS_Value::operator=(v8::Local<v8::Object> pObj) { |
| 169 m_pValue = FXJS_NewObject(m_isolate, pObj); | 173 m_pValue = FXJS_NewObject(m_pJSRuntime->GetIsolate(), pObj); |
| 170 m_eType = VT_fxobject; | 174 m_eType = VT_fxobject; |
| 171 } | 175 } |
| 172 | 176 |
| 173 void CJS_Value::operator=(CJS_Object* pObj) { | 177 void CJS_Value::operator=(CJS_Object* pObj) { |
| 174 if (pObj) | 178 if (pObj) |
| 175 operator=(pObj->ToV8Object()); | 179 operator=(pObj->ToV8Object()); |
| 176 } | 180 } |
| 177 | 181 |
| 178 void CJS_Value::operator=(CJS_Document* pJsDoc) { | 182 void CJS_Value::operator=(CJS_Document* pJsDoc) { |
| 179 m_eType = VT_object; | 183 m_eType = VT_object; |
| 180 if (pJsDoc) { | 184 if (pJsDoc) { |
| 181 m_pValue = pJsDoc->ToV8Object(); | 185 m_pValue = pJsDoc->ToV8Object(); |
| 182 } | 186 } |
| 183 } | 187 } |
| 184 | 188 |
| 185 void CJS_Value::operator=(const FX_WCHAR* pWstr) { | 189 void CJS_Value::operator=(const FX_WCHAR* pWstr) { |
| 186 m_pValue = FXJS_NewString(m_isolate, (wchar_t*)pWstr); | 190 m_pValue = FXJS_NewString(m_pJSRuntime->GetIsolate(), (wchar_t*)pWstr); |
| 187 m_eType = VT_string; | 191 m_eType = VT_string; |
| 188 } | 192 } |
| 189 | 193 |
| 190 void CJS_Value::SetNull() { | 194 void CJS_Value::SetNull() { |
| 191 m_pValue = FXJS_NewNull(); | 195 m_pValue = FXJS_NewNull(); |
| 192 m_eType = VT_null; | 196 m_eType = VT_null; |
| 193 } | 197 } |
| 194 | 198 |
| 195 void CJS_Value::operator=(const FX_CHAR* pStr) { | 199 void CJS_Value::operator=(const FX_CHAR* pStr) { |
| 196 operator=(CFX_WideString::FromLocal(pStr).c_str()); | 200 operator=(CFX_WideString::FromLocal(pStr).c_str()); |
| 197 } | 201 } |
| 198 | 202 |
| 199 void CJS_Value::operator=(CJS_Array& array) { | 203 void CJS_Value::operator=(CJS_Array& array) { |
| 200 m_pValue = FXJS_NewObject2(m_isolate, (v8::Local<v8::Array>)array); | 204 m_pValue = |
| 205 FXJS_NewObject2(m_pJSRuntime->GetIsolate(), (v8::Local<v8::Array>)array); |
| 201 m_eType = VT_object; | 206 m_eType = VT_object; |
| 202 } | 207 } |
| 203 | 208 |
| 204 void CJS_Value::operator=(CJS_Date& date) { | 209 void CJS_Value::operator=(CJS_Date& date) { |
| 205 m_pValue = FXJS_NewDate(m_isolate, (double)date); | 210 m_pValue = FXJS_NewDate(m_pJSRuntime->GetIsolate(), (double)date); |
| 206 m_eType = VT_date; | 211 m_eType = VT_date; |
| 207 } | 212 } |
| 208 | 213 |
| 209 void CJS_Value::operator=(CJS_Value value) { | 214 void CJS_Value::operator=(CJS_Value value) { |
| 210 m_pValue = value.ToV8Value(); | 215 m_pValue = value.ToV8Value(); |
| 211 m_eType = value.m_eType; | 216 m_eType = value.m_eType; |
| 212 m_isolate = value.m_isolate; | 217 m_pJSRuntime = value.m_pJSRuntime; |
| 213 } | 218 } |
| 214 | 219 |
| 215 /* -----------------------------------------------------------------------------
----------- | 220 /* -----------------------------------------------------------------------------
----------- |
| 216 */ | 221 */ |
| 217 | 222 |
| 218 CJS_Value::Type CJS_Value::GetType() const { | 223 CJS_Value::Type CJS_Value::GetType() const { |
| 219 if (m_pValue.IsEmpty()) | 224 if (m_pValue.IsEmpty()) |
| 220 return VT_unknown; | 225 return VT_unknown; |
| 221 if (m_pValue->IsString()) | 226 if (m_pValue->IsString()) |
| 222 return VT_string; | 227 return VT_string; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 243 | 248 |
| 244 FX_BOOL CJS_Value::IsDateObject() const { | 249 FX_BOOL CJS_Value::IsDateObject() const { |
| 245 if (m_pValue.IsEmpty()) | 250 if (m_pValue.IsEmpty()) |
| 246 return FALSE; | 251 return FALSE; |
| 247 return m_pValue->IsDate(); | 252 return m_pValue->IsDate(); |
| 248 } | 253 } |
| 249 | 254 |
| 250 // CJS_Value::operator CJS_Array() | 255 // CJS_Value::operator CJS_Array() |
| 251 FX_BOOL CJS_Value::ConvertToArray(CJS_Array& array) const { | 256 FX_BOOL CJS_Value::ConvertToArray(CJS_Array& array) const { |
| 252 if (IsArrayObject()) { | 257 if (IsArrayObject()) { |
| 253 array.Attach(FXJS_ToArray(m_isolate, m_pValue)); | 258 array.Attach(FXJS_ToArray(m_pJSRuntime->GetIsolate(), m_pValue)); |
| 254 return TRUE; | 259 return TRUE; |
| 255 } | 260 } |
| 256 | 261 |
| 257 return FALSE; | 262 return FALSE; |
| 258 } | 263 } |
| 259 | 264 |
| 260 FX_BOOL CJS_Value::ConvertToDate(CJS_Date& date) const { | 265 FX_BOOL CJS_Value::ConvertToDate(CJS_Date& date) const { |
| 261 // if (GetType() == VT_date) | 266 // if (GetType() == VT_date) |
| 262 // { | 267 // { |
| 263 // date = (double)(*this); | 268 // date = (double)(*this); |
| 264 // return TRUE; | 269 // return TRUE; |
| 265 // } | 270 // } |
| 266 | 271 |
| 267 if (IsDateObject()) { | 272 if (IsDateObject()) { |
| 268 date.Attach(m_pValue); | 273 date.Attach(m_pValue); |
| 269 return TRUE; | 274 return TRUE; |
| 270 } | 275 } |
| 271 | 276 |
| 272 return FALSE; | 277 return FALSE; |
| 273 } | 278 } |
| 274 | 279 |
| 275 /* ---------------------------- CJS_PropValue ---------------------------- */ | 280 /* ---------------------------- CJS_PropValue ---------------------------- */ |
| 276 | 281 |
| 277 CJS_PropValue::CJS_PropValue(const CJS_Value& value) | 282 CJS_PropValue::CJS_PropValue(const CJS_Value& value) |
| 278 : CJS_Value(value), m_bIsSetting(0) {} | 283 : CJS_Value(value), m_bIsSetting(0) {} |
| 279 | 284 |
| 280 CJS_PropValue::CJS_PropValue(v8::Isolate* isolate) | 285 CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime) |
| 281 : CJS_Value(isolate), m_bIsSetting(0) {} | 286 : CJS_Value(pRuntime), m_bIsSetting(0) { |
| 282 | |
| 283 CJS_PropValue::~CJS_PropValue() {} | |
| 284 | |
| 285 FX_BOOL CJS_PropValue::IsSetting() { | |
| 286 return m_bIsSetting; | |
| 287 } | 287 } |
| 288 | 288 |
| 289 FX_BOOL CJS_PropValue::IsGetting() { | 289 CJS_PropValue::~CJS_PropValue() { |
| 290 return !m_bIsSetting; | |
| 291 } | 290 } |
| 292 | 291 |
| 293 void CJS_PropValue::operator<<(int iValue) { | 292 void CJS_PropValue::operator<<(int iValue) { |
| 294 ASSERT(!m_bIsSetting); | 293 ASSERT(!m_bIsSetting); |
| 295 CJS_Value::operator=(iValue); | 294 CJS_Value::operator=(iValue); |
| 296 } | 295 } |
| 297 | 296 |
| 298 void CJS_PropValue::operator>>(int& iValue) const { | 297 void CJS_PropValue::operator>>(int& iValue) const { |
| 299 ASSERT(m_bIsSetting); | 298 ASSERT(m_bIsSetting); |
| 300 iValue = CJS_Value::ToInt(); | 299 iValue = CJS_Value::ToInt(); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 398 |
| 400 void CJS_PropValue::operator<<(CJS_Date& date) { | 399 void CJS_PropValue::operator<<(CJS_Date& date) { |
| 401 ASSERT(!m_bIsSetting); | 400 ASSERT(!m_bIsSetting); |
| 402 CJS_Value::operator=(date); | 401 CJS_Value::operator=(date); |
| 403 } | 402 } |
| 404 | 403 |
| 405 CJS_PropValue::operator v8::Local<v8::Value>() const { | 404 CJS_PropValue::operator v8::Local<v8::Value>() const { |
| 406 return m_pValue; | 405 return m_pValue; |
| 407 } | 406 } |
| 408 | 407 |
| 409 /* ======================================== CJS_Array | 408 CJS_Array::CJS_Array(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) { |
| 410 * ========================================= */ | 409 } |
| 411 CJS_Array::CJS_Array(v8::Isolate* isolate) : m_isolate(isolate) {} | |
| 412 | 410 |
| 413 CJS_Array::~CJS_Array() {} | 411 CJS_Array::~CJS_Array() {} |
| 414 | 412 |
| 415 void CJS_Array::Attach(v8::Local<v8::Array> pArray) { | 413 void CJS_Array::Attach(v8::Local<v8::Array> pArray) { |
| 416 m_pArray = pArray; | 414 m_pArray = pArray; |
| 417 } | 415 } |
| 418 | 416 |
| 419 FX_BOOL CJS_Array::IsAttached() { | 417 FX_BOOL CJS_Array::IsAttached() { |
| 420 return FALSE; | 418 return FALSE; |
| 421 } | 419 } |
| 422 | 420 |
| 423 void CJS_Array::GetElement(unsigned index, CJS_Value& value) { | 421 void CJS_Array::GetElement(unsigned index, CJS_Value& value) { |
| 424 if (m_pArray.IsEmpty()) | 422 if (m_pArray.IsEmpty()) |
| 425 return; | 423 return; |
| 426 v8::Local<v8::Value> p = FXJS_GetArrayElement(m_isolate, m_pArray, index); | 424 v8::Local<v8::Value> p = |
| 425 FXJS_GetArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index); |
| 427 value.Attach(p, CJS_Value::VT_object); | 426 value.Attach(p, CJS_Value::VT_object); |
| 428 } | 427 } |
| 429 | 428 |
| 430 void CJS_Array::SetElement(unsigned index, CJS_Value value) { | 429 void CJS_Array::SetElement(unsigned index, CJS_Value value) { |
| 431 if (m_pArray.IsEmpty()) | 430 if (m_pArray.IsEmpty()) |
| 432 m_pArray = FXJS_NewArray(m_isolate); | 431 m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate()); |
| 433 | 432 |
| 434 FXJS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value()); | 433 FXJS_PutArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index, |
| 434 value.ToV8Value()); |
| 435 } | 435 } |
| 436 | 436 |
| 437 int CJS_Array::GetLength() { | 437 int CJS_Array::GetLength() { |
| 438 if (m_pArray.IsEmpty()) | 438 if (m_pArray.IsEmpty()) |
| 439 return 0; | 439 return 0; |
| 440 return FXJS_GetArrayLength(m_pArray); | 440 return FXJS_GetArrayLength(m_pArray); |
| 441 } | 441 } |
| 442 | 442 |
| 443 CJS_Array::operator v8::Local<v8::Array>() { | 443 CJS_Array::operator v8::Local<v8::Array>() { |
| 444 if (m_pArray.IsEmpty()) | 444 if (m_pArray.IsEmpty()) |
| 445 m_pArray = FXJS_NewArray(m_isolate); | 445 m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate()); |
| 446 | 446 |
| 447 return m_pArray; | 447 return m_pArray; |
| 448 } | 448 } |
| 449 | 449 |
| 450 /* ======================================== CJS_Date | 450 CJS_Date::CJS_Date(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) { |
| 451 * ========================================= */ | |
| 452 | |
| 453 CJS_Date::CJS_Date(v8::Isolate* isolate) : m_isolate(isolate) {} | |
| 454 | |
| 455 CJS_Date::CJS_Date(v8::Isolate* isolate, double dMsec_time) { | |
| 456 m_isolate = isolate; | |
| 457 m_pDate = FXJS_NewDate(isolate, dMsec_time); | |
| 458 } | 451 } |
| 459 | 452 |
| 460 CJS_Date::CJS_Date(v8::Isolate* isolate, | 453 CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime) |
| 454 : m_pJSRuntime(pRuntime) { |
| 455 m_pDate = FXJS_NewDate(pRuntime->GetIsolate(), dMsecTime); |
| 456 } |
| 457 |
| 458 CJS_Date::CJS_Date(CJS_Runtime* pRuntime, |
| 461 int year, | 459 int year, |
| 462 int mon, | 460 int mon, |
| 463 int day, | 461 int day, |
| 464 int hour, | 462 int hour, |
| 465 int min, | 463 int min, |
| 466 int sec) { | 464 int sec) |
| 467 m_isolate = isolate; | 465 : m_pJSRuntime(pRuntime) { |
| 468 m_pDate = FXJS_NewDate(isolate, MakeDate(year, mon, day, hour, min, sec, 0)); | 466 m_pDate = FXJS_NewDate(pRuntime->GetIsolate(), |
| 467 MakeDate(year, mon, day, hour, min, sec, 0)); |
| 469 } | 468 } |
| 470 | 469 |
| 471 double CJS_Date::MakeDate(int year, | 470 double CJS_Date::MakeDate(int year, |
| 472 int mon, | 471 int mon, |
| 473 int day, | 472 int day, |
| 474 int hour, | 473 int hour, |
| 475 int min, | 474 int min, |
| 476 int sec, | 475 int sec, |
| 477 int ms) { | 476 int ms) { |
| 478 return JS_MakeDate(JS_MakeDay(year, mon, day), | 477 return JS_MakeDate(JS_MakeDay(year, mon, day), |
| 479 JS_MakeTime(hour, min, sec, ms)); | 478 JS_MakeTime(hour, min, sec, ms)); |
| 480 } | 479 } |
| 481 | 480 |
| 482 CJS_Date::~CJS_Date() {} | 481 CJS_Date::~CJS_Date() {} |
| 483 | 482 |
| 484 FX_BOOL CJS_Date::IsValidDate() { | 483 FX_BOOL CJS_Date::IsValidDate() { |
| 485 if (m_pDate.IsEmpty()) | 484 if (m_pDate.IsEmpty()) |
| 486 return FALSE; | 485 return FALSE; |
| 487 return !JS_PortIsNan(FXJS_ToNumber(m_isolate, m_pDate)); | 486 return !JS_PortIsNan(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)); |
| 488 } | 487 } |
| 489 | 488 |
| 490 void CJS_Date::Attach(v8::Local<v8::Value> pDate) { | 489 void CJS_Date::Attach(v8::Local<v8::Value> pDate) { |
| 491 m_pDate = pDate; | 490 m_pDate = pDate; |
| 492 } | 491 } |
| 493 | 492 |
| 494 int CJS_Date::GetYear() { | 493 int CJS_Date::GetYear() { |
| 495 if (IsValidDate()) | 494 if (IsValidDate()) |
| 496 return JS_GetYearFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate))); | 495 return JS_GetYearFromTime( |
| 496 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
| 497 | 497 |
| 498 return 0; | 498 return 0; |
| 499 } | 499 } |
| 500 | 500 |
| 501 void CJS_Date::SetYear(int iYear) { | 501 void CJS_Date::SetYear(int iYear) { |
| 502 double date = MakeDate(iYear, GetMonth(), GetDay(), GetHours(), GetMinutes(), | 502 double date = MakeDate(iYear, GetMonth(), GetDay(), GetHours(), GetMinutes(), |
| 503 GetSeconds(), 0); | 503 GetSeconds(), 0); |
| 504 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date)); | 504 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
| 505 } | 505 } |
| 506 | 506 |
| 507 int CJS_Date::GetMonth() { | 507 int CJS_Date::GetMonth() { |
| 508 if (IsValidDate()) | 508 if (IsValidDate()) |
| 509 return JS_GetMonthFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate))); | 509 return JS_GetMonthFromTime( |
| 510 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
| 510 | 511 |
| 511 return 0; | 512 return 0; |
| 512 } | 513 } |
| 513 | 514 |
| 514 void CJS_Date::SetMonth(int iMonth) { | 515 void CJS_Date::SetMonth(int iMonth) { |
| 515 double date = MakeDate(GetYear(), iMonth, GetDay(), GetHours(), GetMinutes(), | 516 double date = MakeDate(GetYear(), iMonth, GetDay(), GetHours(), GetMinutes(), |
| 516 GetSeconds(), 0); | 517 GetSeconds(), 0); |
| 517 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date)); | 518 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
| 518 } | 519 } |
| 519 | 520 |
| 520 int CJS_Date::GetDay() { | 521 int CJS_Date::GetDay() { |
| 521 if (IsValidDate()) | 522 if (IsValidDate()) |
| 522 return JS_GetDayFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate))); | 523 return JS_GetDayFromTime( |
| 524 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
| 523 | 525 |
| 524 return 0; | 526 return 0; |
| 525 } | 527 } |
| 526 | 528 |
| 527 void CJS_Date::SetDay(int iDay) { | 529 void CJS_Date::SetDay(int iDay) { |
| 528 double date = MakeDate(GetYear(), GetMonth(), iDay, GetHours(), GetMinutes(), | 530 double date = MakeDate(GetYear(), GetMonth(), iDay, GetHours(), GetMinutes(), |
| 529 GetSeconds(), 0); | 531 GetSeconds(), 0); |
| 530 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date)); | 532 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
| 531 } | 533 } |
| 532 | 534 |
| 533 int CJS_Date::GetHours() { | 535 int CJS_Date::GetHours() { |
| 534 if (IsValidDate()) | 536 if (IsValidDate()) |
| 535 return JS_GetHourFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate))); | 537 return JS_GetHourFromTime( |
| 538 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
| 536 | 539 |
| 537 return 0; | 540 return 0; |
| 538 } | 541 } |
| 539 | 542 |
| 540 void CJS_Date::SetHours(int iHours) { | 543 void CJS_Date::SetHours(int iHours) { |
| 541 double date = MakeDate(GetYear(), GetMonth(), GetDay(), iHours, GetMinutes(), | 544 double date = MakeDate(GetYear(), GetMonth(), GetDay(), iHours, GetMinutes(), |
| 542 GetSeconds(), 0); | 545 GetSeconds(), 0); |
| 543 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date)); | 546 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
| 544 } | 547 } |
| 545 | 548 |
| 546 int CJS_Date::GetMinutes() { | 549 int CJS_Date::GetMinutes() { |
| 547 if (IsValidDate()) | 550 if (IsValidDate()) |
| 548 return JS_GetMinFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate))); | 551 return JS_GetMinFromTime( |
| 552 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
| 549 | 553 |
| 550 return 0; | 554 return 0; |
| 551 } | 555 } |
| 552 | 556 |
| 553 void CJS_Date::SetMinutes(int minutes) { | 557 void CJS_Date::SetMinutes(int minutes) { |
| 554 double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), minutes, | 558 double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), minutes, |
| 555 GetSeconds(), 0); | 559 GetSeconds(), 0); |
| 556 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date)); | 560 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
| 557 } | 561 } |
| 558 | 562 |
| 559 int CJS_Date::GetSeconds() { | 563 int CJS_Date::GetSeconds() { |
| 560 if (IsValidDate()) | 564 if (IsValidDate()) |
| 561 return JS_GetSecFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate))); | 565 return JS_GetSecFromTime( |
| 566 JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
| 562 | 567 |
| 563 return 0; | 568 return 0; |
| 564 } | 569 } |
| 565 | 570 |
| 566 void CJS_Date::SetSeconds(int seconds) { | 571 void CJS_Date::SetSeconds(int seconds) { |
| 567 double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), | 572 double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), |
| 568 GetMinutes(), seconds, 0); | 573 GetMinutes(), seconds, 0); |
| 569 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date)); | 574 FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
| 570 } | 575 } |
| 571 | 576 |
| 572 CJS_Date::operator v8::Local<v8::Value>() { | 577 CJS_Date::operator v8::Local<v8::Value>() { |
| 573 return m_pDate; | 578 return m_pDate; |
| 574 } | 579 } |
| 575 | 580 |
| 576 CJS_Date::operator double() const { | 581 CJS_Date::operator double() const { |
| 577 if (m_pDate.IsEmpty()) | 582 if (m_pDate.IsEmpty()) |
| 578 return 0.0; | 583 return 0.0; |
| 579 return FXJS_ToNumber(m_isolate, m_pDate); | 584 return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate); |
| 580 } | 585 } |
| 581 | 586 |
| 582 CFX_WideString CJS_Date::ToString() const { | 587 CFX_WideString CJS_Date::ToString() const { |
| 583 if (m_pDate.IsEmpty()) | 588 if (m_pDate.IsEmpty()) |
| 584 return L""; | 589 return L""; |
| 585 return FXJS_ToString(m_isolate, m_pDate); | 590 return FXJS_ToString(m_pJSRuntime->GetIsolate(), m_pDate); |
| 586 } | 591 } |
| 587 | 592 |
| 588 double _getLocalTZA() { | 593 double _getLocalTZA() { |
| 589 if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) | 594 if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
| 590 return 0; | 595 return 0; |
| 591 time_t t = 0; | 596 time_t t = 0; |
| 592 time(&t); | 597 time(&t); |
| 593 localtime(&t); | 598 localtime(&t); |
| 594 #if _MSC_VER >= 1900 | 599 #if _MSC_VER >= 1900 |
| 595 // In gcc and in Visual Studio prior to VS 2015 'timezone' is a global | 600 // In gcc and in Visual Studio prior to VS 2015 'timezone' is a global |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 return day * 86400000 + time; | 862 return day * 86400000 + time; |
| 858 } | 863 } |
| 859 | 864 |
| 860 bool JS_PortIsNan(double d) { | 865 bool JS_PortIsNan(double d) { |
| 861 return d != d; | 866 return d != d; |
| 862 } | 867 } |
| 863 | 868 |
| 864 double JS_LocalTime(double d) { | 869 double JS_LocalTime(double d) { |
| 865 return JS_GetDateTime() + _getDaylightSavingTA(d); | 870 return JS_GetDateTime() + _getDaylightSavingTA(d); |
| 866 } | 871 } |
| OLD | NEW |