John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 7 | #include "JS_Value.h" |
| 8 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 9 | #include <time.h> |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 10 | #include <algorithm> |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 11 | #include <cmath> |
| 12 | #include <limits> |
| 13 | |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 14 | #include "Document.h" |
| 15 | #include "JS_Define.h" |
| 16 | #include "JS_Object.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 18 | static const FX_DWORD g_nan[2] = {0, 0x7FF80000}; |
| 19 | static double GetNan() { |
| 20 | return *(double*)g_nan; |
| 21 | } |
| 22 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 23 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime) |
| 24 | : m_eType(VT_unknown), m_pJSRuntime(pRuntime) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 25 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 27 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue, Type t) |
| 28 | : m_eType(t), m_pValue(pValue), m_pJSRuntime(pRuntime) { |
| 29 | } |
| 30 | |
| 31 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue) |
| 32 | : m_pJSRuntime(pRuntime) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | operator=(iValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 36 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const bool& bValue) |
| 37 | : m_pJSRuntime(pRuntime) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | operator=(bValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 41 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const float& fValue) |
| 42 | : m_pJSRuntime(pRuntime) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 43 | operator=(fValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 46 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const double& dValue) |
| 47 | : m_pJSRuntime(pRuntime) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | operator=(dValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 51 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Object> pJsObj) |
| 52 | : m_pJSRuntime(pRuntime) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | operator=(pJsObj); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 56 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pJsObj) |
| 57 | : m_pJSRuntime(pRuntime) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | operator=(pJsObj); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 61 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Document* pJsDoc) |
| 62 | : m_pJSRuntime(pRuntime) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | m_eType = VT_object; |
| 64 | if (pJsDoc) |
Tom Sepez | 116e4ad | 2015-09-21 09:22:05 -0700 | [diff] [blame] | 65 | m_pValue = pJsDoc->ToV8Object(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 68 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr) |
| 69 | : m_pJSRuntime(pRuntime) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | operator=(pWstr); |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 73 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr) |
| 74 | : m_pJSRuntime(pRuntime) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | operator=(pStr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 78 | CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Array& array) |
| 79 | : m_pJSRuntime(pRuntime) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | operator=(array); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | CJS_Value::~CJS_Value() {} |
| 84 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 85 | void CJS_Value::Attach(v8::Local<v8::Value> pValue, Type t) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | m_pValue = pValue; |
| 87 | m_eType = t; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | void CJS_Value::Attach(CJS_Value* pValue) { |
| 91 | if (pValue) |
| 92 | Attach(pValue->ToV8Value(), pValue->GetType()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 95 | void CJS_Value::Detach() { |
| 96 | m_pValue = v8::Local<v8::Value>(); |
| 97 | m_eType = VT_unknown; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | int CJS_Value::ToInt() const { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 101 | return FXJS_ToInt32(m_pJSRuntime->GetIsolate(), m_pValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | bool CJS_Value::ToBool() const { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 105 | return FXJS_ToBoolean(m_pJSRuntime->GetIsolate(), m_pValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | double CJS_Value::ToDouble() const { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 109 | return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | float CJS_Value::ToFloat() const { |
| 113 | return (float)ToDouble(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | CJS_Object* CJS_Value::ToCJSObject() const { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 117 | v8::Local<v8::Object> pObj = |
| 118 | FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue); |
| 119 | return (CJS_Object*)FXJS_GetPrivate(m_pJSRuntime->GetIsolate(), pObj); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 122 | v8::Local<v8::Object> CJS_Value::ToV8Object() const { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 123 | return FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 126 | CFX_WideString CJS_Value::ToCFXWideString() const { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 127 | return FXJS_ToString(m_pJSRuntime->GetIsolate(), m_pValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | CFX_ByteString CJS_Value::ToCFXByteString() const { |
| 131 | return CFX_ByteString::FromUnicode(ToCFXWideString()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | v8::Local<v8::Value> CJS_Value::ToV8Value() const { |
| 135 | return m_pValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 138 | v8::Local<v8::Array> CJS_Value::ToV8Array() const { |
| 139 | if (IsArrayObject()) |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 140 | return v8::Local<v8::Array>::Cast( |
| 141 | FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | return v8::Local<v8::Array>(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 145 | void CJS_Value::MaybeCoerceToNumber() { |
| 146 | bool bAllowNaN = false; |
| 147 | if (m_eType == VT_string) { |
| 148 | CFX_ByteString bstr = ToCFXByteString(); |
| 149 | if (bstr.GetLength() == 0) |
| 150 | return; |
| 151 | if (bstr == "NaN") |
| 152 | bAllowNaN = true; |
| 153 | } |
| 154 | v8::TryCatch(m_pJSRuntime->GetIsolate()); |
| 155 | v8::MaybeLocal<v8::Number> maybeNum = |
| 156 | m_pValue->ToNumber(m_pJSRuntime->GetIsolate()->GetCurrentContext()); |
| 157 | if (maybeNum.IsEmpty()) |
| 158 | return; |
| 159 | v8::Local<v8::Number> num = maybeNum.ToLocalChecked(); |
| 160 | if (std::isnan(num->Value()) && !bAllowNaN) |
| 161 | return; |
| 162 | m_pValue = num; |
| 163 | m_eType = VT_number; |
| 164 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | |
| 166 | void CJS_Value::operator=(int iValue) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 167 | m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), iValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 168 | m_eType = VT_number; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | void CJS_Value::operator=(bool bValue) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 172 | m_pValue = FXJS_NewBoolean(m_pJSRuntime->GetIsolate(), bValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | m_eType = VT_boolean; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | void CJS_Value::operator=(double dValue) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 177 | m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), dValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | m_eType = VT_number; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 181 | void CJS_Value::operator=(float fValue) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 182 | m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), fValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | m_eType = VT_number; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 186 | void CJS_Value::operator=(v8::Local<v8::Object> pObj) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 187 | m_pValue = FXJS_NewObject(m_pJSRuntime->GetIsolate(), pObj); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 188 | m_eType = VT_fxobject; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 191 | void CJS_Value::operator=(CJS_Object* pObj) { |
| 192 | if (pObj) |
Tom Sepez | 116e4ad | 2015-09-21 09:22:05 -0700 | [diff] [blame] | 193 | operator=(pObj->ToV8Object()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 196 | void CJS_Value::operator=(CJS_Document* pJsDoc) { |
| 197 | m_eType = VT_object; |
| 198 | if (pJsDoc) { |
Tom Sepez | 116e4ad | 2015-09-21 09:22:05 -0700 | [diff] [blame] | 199 | m_pValue = pJsDoc->ToV8Object(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | void CJS_Value::operator=(const FX_WCHAR* pWstr) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 204 | m_pValue = FXJS_NewString(m_pJSRuntime->GetIsolate(), (wchar_t*)pWstr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | m_eType = VT_string; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | void CJS_Value::SetNull() { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 209 | m_pValue = FXJS_NewNull(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 210 | m_eType = VT_null; |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | void CJS_Value::operator=(const FX_CHAR* pStr) { |
| 214 | operator=(CFX_WideString::FromLocal(pStr).c_str()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 217 | void CJS_Value::operator=(CJS_Array& array) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 218 | m_pValue = |
| 219 | FXJS_NewObject2(m_pJSRuntime->GetIsolate(), (v8::Local<v8::Array>)array); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 220 | m_eType = VT_object; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 223 | void CJS_Value::operator=(CJS_Date& date) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 224 | m_pValue = FXJS_NewDate(m_pJSRuntime->GetIsolate(), (double)date); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 225 | m_eType = VT_date; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 228 | void CJS_Value::operator=(CJS_Value value) { |
| 229 | m_pValue = value.ToV8Value(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 230 | m_eType = value.m_eType; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 231 | m_pJSRuntime = value.m_pJSRuntime; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 234 | CJS_Value::Type CJS_Value::GetType() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 235 | if (m_pValue.IsEmpty()) |
| 236 | return VT_unknown; |
| 237 | if (m_pValue->IsString()) |
| 238 | return VT_string; |
| 239 | if (m_pValue->IsNumber()) |
| 240 | return VT_number; |
| 241 | if (m_pValue->IsBoolean()) |
| 242 | return VT_boolean; |
| 243 | if (m_pValue->IsDate()) |
| 244 | return VT_date; |
| 245 | if (m_pValue->IsObject()) |
| 246 | return VT_object; |
| 247 | if (m_pValue->IsNull()) |
| 248 | return VT_null; |
| 249 | if (m_pValue->IsUndefined()) |
| 250 | return VT_undefined; |
| 251 | return VT_unknown; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 254 | FX_BOOL CJS_Value::IsArrayObject() const { |
| 255 | if (m_pValue.IsEmpty()) |
| 256 | return FALSE; |
| 257 | return m_pValue->IsArray(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 260 | FX_BOOL CJS_Value::IsDateObject() const { |
| 261 | if (m_pValue.IsEmpty()) |
| 262 | return FALSE; |
| 263 | return m_pValue->IsDate(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 266 | // CJS_Value::operator CJS_Array() |
| 267 | FX_BOOL CJS_Value::ConvertToArray(CJS_Array& array) const { |
| 268 | if (IsArrayObject()) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 269 | array.Attach(FXJS_ToArray(m_pJSRuntime->GetIsolate(), m_pValue)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | return TRUE; |
| 271 | } |
| 272 | |
| 273 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | FX_BOOL CJS_Value::ConvertToDate(CJS_Date& date) const { |
| 277 | // if (GetType() == VT_date) |
| 278 | // { |
| 279 | // date = (double)(*this); |
| 280 | // return TRUE; |
| 281 | // } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 282 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 283 | if (IsDateObject()) { |
| 284 | date.Attach(m_pValue); |
| 285 | return TRUE; |
| 286 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 287 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 288 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /* ---------------------------- CJS_PropValue ---------------------------- */ |
| 292 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 293 | CJS_PropValue::CJS_PropValue(const CJS_Value& value) |
| 294 | : CJS_Value(value), m_bIsSetting(0) {} |
| 295 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 296 | CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime) |
| 297 | : CJS_Value(pRuntime), m_bIsSetting(0) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 300 | CJS_PropValue::~CJS_PropValue() { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 303 | void CJS_PropValue::operator<<(int iValue) { |
| 304 | ASSERT(!m_bIsSetting); |
| 305 | CJS_Value::operator=(iValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 308 | void CJS_PropValue::operator>>(int& iValue) const { |
| 309 | ASSERT(m_bIsSetting); |
| 310 | iValue = CJS_Value::ToInt(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | void CJS_PropValue::operator<<(bool bValue) { |
| 314 | ASSERT(!m_bIsSetting); |
| 315 | CJS_Value::operator=(bValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 318 | void CJS_PropValue::operator>>(bool& bValue) const { |
| 319 | ASSERT(m_bIsSetting); |
| 320 | bValue = CJS_Value::ToBool(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 323 | void CJS_PropValue::operator<<(double dValue) { |
| 324 | ASSERT(!m_bIsSetting); |
| 325 | CJS_Value::operator=(dValue); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 328 | void CJS_PropValue::operator>>(double& dValue) const { |
| 329 | ASSERT(m_bIsSetting); |
| 330 | dValue = CJS_Value::ToDouble(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 333 | void CJS_PropValue::operator<<(CJS_Object* pObj) { |
| 334 | ASSERT(!m_bIsSetting); |
| 335 | CJS_Value::operator=(pObj); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 338 | void CJS_PropValue::operator>>(CJS_Object*& ppObj) const { |
| 339 | ASSERT(m_bIsSetting); |
| 340 | ppObj = CJS_Value::ToCJSObject(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 343 | void CJS_PropValue::operator<<(CJS_Document* pJsDoc) { |
| 344 | ASSERT(!m_bIsSetting); |
| 345 | CJS_Value::operator=(pJsDoc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 348 | void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const { |
| 349 | ASSERT(m_bIsSetting); |
| 350 | ppJsDoc = static_cast<CJS_Document*>(CJS_Value::ToCJSObject()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 353 | void CJS_PropValue::operator<<(v8::Local<v8::Object> pObj) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | ASSERT(!m_bIsSetting); |
| 355 | CJS_Value::operator=(pObj); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 358 | void CJS_PropValue::operator>>(v8::Local<v8::Object>& ppObj) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 359 | ASSERT(m_bIsSetting); |
| 360 | ppObj = CJS_Value::ToV8Object(); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 363 | void CJS_PropValue::StartSetting() { |
| 364 | m_bIsSetting = 1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | void CJS_PropValue::StartGetting() { |
| 368 | m_bIsSetting = 0; |
| 369 | } |
| 370 | void CJS_PropValue::operator<<(CFX_ByteString string) { |
| 371 | ASSERT(!m_bIsSetting); |
| 372 | CJS_Value::operator=(string.c_str()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 375 | void CJS_PropValue::operator>>(CFX_ByteString& string) const { |
| 376 | ASSERT(m_bIsSetting); |
| 377 | string = CJS_Value::ToCFXByteString(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 380 | void CJS_PropValue::operator<<(const FX_WCHAR* c_string) { |
| 381 | ASSERT(!m_bIsSetting); |
| 382 | CJS_Value::operator=(c_string); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 385 | void CJS_PropValue::operator>>(CFX_WideString& wide_string) const { |
| 386 | ASSERT(m_bIsSetting); |
| 387 | wide_string = CJS_Value::ToCFXWideString(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 390 | void CJS_PropValue::operator<<(CFX_WideString wide_string) { |
| 391 | ASSERT(!m_bIsSetting); |
| 392 | CJS_Value::operator=(wide_string.c_str()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 395 | void CJS_PropValue::operator>>(CJS_Array& array) const { |
| 396 | ASSERT(m_bIsSetting); |
| 397 | ConvertToArray(array); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 400 | void CJS_PropValue::operator<<(CJS_Array& array) { |
| 401 | ASSERT(!m_bIsSetting); |
| 402 | CJS_Value::operator=(array); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 405 | void CJS_PropValue::operator>>(CJS_Date& date) const { |
| 406 | ASSERT(m_bIsSetting); |
| 407 | ConvertToDate(date); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 410 | void CJS_PropValue::operator<<(CJS_Date& date) { |
| 411 | ASSERT(!m_bIsSetting); |
| 412 | CJS_Value::operator=(date); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 415 | CJS_PropValue::operator v8::Local<v8::Value>() const { |
| 416 | return m_pValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 419 | CJS_Array::CJS_Array(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) { |
| 420 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 421 | |
| 422 | CJS_Array::~CJS_Array() {} |
| 423 | |
| 424 | void CJS_Array::Attach(v8::Local<v8::Array> pArray) { |
| 425 | m_pArray = pArray; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | FX_BOOL CJS_Array::IsAttached() { |
| 429 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 432 | void CJS_Array::GetElement(unsigned index, CJS_Value& value) { |
| 433 | if (m_pArray.IsEmpty()) |
| 434 | return; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 435 | v8::Local<v8::Value> p = |
| 436 | FXJS_GetArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 437 | value.Attach(p, CJS_Value::VT_object); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | void CJS_Array::SetElement(unsigned index, CJS_Value value) { |
| 441 | if (m_pArray.IsEmpty()) |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 442 | m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 443 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 444 | FXJS_PutArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index, |
| 445 | value.ToV8Value()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 448 | int CJS_Array::GetLength() { |
| 449 | if (m_pArray.IsEmpty()) |
| 450 | return 0; |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 451 | return FXJS_GetArrayLength(m_pArray); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 454 | CJS_Array::operator v8::Local<v8::Array>() { |
| 455 | if (m_pArray.IsEmpty()) |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 456 | m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 457 | |
| 458 | return m_pArray; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 461 | CJS_Date::CJS_Date(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 464 | CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime) |
| 465 | : m_pJSRuntime(pRuntime) { |
| 466 | m_pDate = FXJS_NewDate(pRuntime->GetIsolate(), dMsecTime); |
| 467 | } |
| 468 | |
| 469 | CJS_Date::CJS_Date(CJS_Runtime* pRuntime, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | int year, |
| 471 | int mon, |
| 472 | int day, |
| 473 | int hour, |
| 474 | int min, |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 475 | int sec) |
| 476 | : m_pJSRuntime(pRuntime) { |
| 477 | m_pDate = FXJS_NewDate(pRuntime->GetIsolate(), |
| 478 | MakeDate(year, mon, day, hour, min, sec, 0)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | double CJS_Date::MakeDate(int year, |
| 482 | int mon, |
| 483 | int day, |
| 484 | int hour, |
| 485 | int min, |
| 486 | int sec, |
| 487 | int ms) { |
| 488 | return JS_MakeDate(JS_MakeDay(year, mon, day), |
| 489 | JS_MakeTime(hour, min, sec, ms)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 492 | CJS_Date::~CJS_Date() {} |
| 493 | |
| 494 | FX_BOOL CJS_Date::IsValidDate() { |
| 495 | if (m_pDate.IsEmpty()) |
| 496 | return FALSE; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 497 | return !JS_PortIsNan(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | void CJS_Date::Attach(v8::Local<v8::Value> pDate) { |
| 501 | m_pDate = pDate; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 504 | int CJS_Date::GetYear() { |
| 505 | if (IsValidDate()) |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 506 | return JS_GetYearFromTime( |
| 507 | JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 508 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 509 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 512 | void CJS_Date::SetYear(int iYear) { |
| 513 | double date = MakeDate(iYear, GetMonth(), GetDay(), GetHours(), GetMinutes(), |
| 514 | GetSeconds(), 0); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 515 | FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 518 | int CJS_Date::GetMonth() { |
| 519 | if (IsValidDate()) |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 520 | return JS_GetMonthFromTime( |
| 521 | JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 522 | |
| 523 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 526 | void CJS_Date::SetMonth(int iMonth) { |
| 527 | double date = MakeDate(GetYear(), iMonth, GetDay(), GetHours(), GetMinutes(), |
| 528 | GetSeconds(), 0); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 529 | FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 532 | int CJS_Date::GetDay() { |
| 533 | if (IsValidDate()) |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 534 | return JS_GetDayFromTime( |
| 535 | JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 536 | |
| 537 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 540 | void CJS_Date::SetDay(int iDay) { |
| 541 | double date = MakeDate(GetYear(), GetMonth(), iDay, GetHours(), GetMinutes(), |
| 542 | GetSeconds(), 0); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 543 | FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 546 | int CJS_Date::GetHours() { |
| 547 | if (IsValidDate()) |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 548 | return JS_GetHourFromTime( |
| 549 | JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | |
| 551 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 554 | void CJS_Date::SetHours(int iHours) { |
| 555 | double date = MakeDate(GetYear(), GetMonth(), GetDay(), iHours, GetMinutes(), |
| 556 | GetSeconds(), 0); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 557 | FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 560 | int CJS_Date::GetMinutes() { |
| 561 | if (IsValidDate()) |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 562 | return JS_GetMinFromTime( |
| 563 | JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | |
| 565 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 568 | void CJS_Date::SetMinutes(int minutes) { |
| 569 | double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), minutes, |
| 570 | GetSeconds(), 0); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 571 | FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 574 | int CJS_Date::GetSeconds() { |
| 575 | if (IsValidDate()) |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 576 | return JS_GetSecFromTime( |
| 577 | JS_LocalTime(FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 578 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 579 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 582 | void CJS_Date::SetSeconds(int seconds) { |
| 583 | double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), |
| 584 | GetMinutes(), seconds, 0); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 585 | FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_pJSRuntime->GetIsolate(), date)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 588 | CJS_Date::operator v8::Local<v8::Value>() { |
| 589 | return m_pDate; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 592 | CJS_Date::operator double() const { |
| 593 | if (m_pDate.IsEmpty()) |
| 594 | return 0.0; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 595 | return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pDate); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 598 | CFX_WideString CJS_Date::ToString() const { |
| 599 | if (m_pDate.IsEmpty()) |
| 600 | return L""; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 601 | return FXJS_ToString(m_pJSRuntime->GetIsolate(), m_pDate); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | double _getLocalTZA() { |
| 605 | if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
| 606 | return 0; |
| 607 | time_t t = 0; |
| 608 | time(&t); |
| 609 | localtime(&t); |
| 610 | #if _MSC_VER >= 1900 |
| 611 | // In gcc and in Visual Studio prior to VS 2015 'timezone' is a global |
| 612 | // variable declared in time.h. That variable was deprecated and in VS 2015 |
| 613 | // is removed, with _get_timezone replacing it. |
| 614 | long timezone = 0; |
| 615 | _get_timezone(&timezone); |
| 616 | #endif |
| 617 | return (double)(-(timezone * 1000)); |
| 618 | } |
| 619 | |
| 620 | int _getDaylightSavingTA(double d) { |
| 621 | if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
| 622 | return 0; |
| 623 | time_t t = (time_t)(d / 1000); |
| 624 | struct tm* tmp = localtime(&t); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 625 | if (!tmp) |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 626 | return 0; |
| 627 | if (tmp->tm_isdst > 0) |
| 628 | // One hour. |
| 629 | return (int)60 * 60 * 1000; |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | double _Mod(double x, double y) { |
| 634 | double r = fmod(x, y); |
| 635 | if (r < 0) |
| 636 | r += y; |
| 637 | return r; |
| 638 | } |
| 639 | |
| 640 | int _isfinite(double v) { |
| 641 | #if _MSC_VER |
| 642 | return ::_finite(v); |
| 643 | #else |
| 644 | return std::fabs(v) < std::numeric_limits<double>::max(); |
| 645 | #endif |
| 646 | } |
| 647 | |
| 648 | double _toInteger(double n) { |
| 649 | return (n >= 0) ? FXSYS_floor(n) : -FXSYS_floor(-n); |
| 650 | } |
| 651 | |
| 652 | bool _isLeapYear(int year) { |
| 653 | return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 != 0)); |
| 654 | } |
| 655 | |
| 656 | int _DayFromYear(int y) { |
| 657 | return (int)(365 * (y - 1970.0) + FXSYS_floor((y - 1969.0) / 4) - |
| 658 | FXSYS_floor((y - 1901.0) / 100) + |
| 659 | FXSYS_floor((y - 1601.0) / 400)); |
| 660 | } |
| 661 | |
| 662 | double _TimeFromYear(int y) { |
Lei Zhang | 1ac47eb | 2015-12-21 11:04:44 -0800 | [diff] [blame] | 663 | return 86400000.0 * _DayFromYear(y); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | double _TimeFromYearMonth(int y, int m) { |
| 667 | static int daysMonth[12] = { |
| 668 | 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; |
| 669 | static int leapDaysMonth[12] = { |
| 670 | 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}; |
| 671 | int* pMonth = daysMonth; |
| 672 | if (_isLeapYear(y)) |
| 673 | pMonth = leapDaysMonth; |
| 674 | return _TimeFromYear(y) + ((double)pMonth[m]) * 86400000; |
| 675 | } |
| 676 | |
| 677 | int _Day(double t) { |
| 678 | return (int)FXSYS_floor(t / 86400000); |
| 679 | } |
| 680 | |
| 681 | int _YearFromTime(double t) { |
| 682 | // estimate the time. |
Lei Zhang | 1ac47eb | 2015-12-21 11:04:44 -0800 | [diff] [blame] | 683 | int y = 1970 + static_cast<int>(t / (365.2425 * 86400000)); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 684 | if (_TimeFromYear(y) <= t) { |
| 685 | while (_TimeFromYear(y + 1) <= t) |
| 686 | y++; |
| 687 | } else |
Lei Zhang | 1ac47eb | 2015-12-21 11:04:44 -0800 | [diff] [blame] | 688 | while (_TimeFromYear(y) > t) |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 689 | y--; |
| 690 | return y; |
| 691 | } |
| 692 | |
| 693 | int _DayWithinYear(double t) { |
| 694 | int year = _YearFromTime(t); |
| 695 | int day = _Day(t); |
| 696 | return day - _DayFromYear(year); |
| 697 | } |
| 698 | |
| 699 | int _MonthFromTime(double t) { |
| 700 | int day = _DayWithinYear(t); |
| 701 | int year = _YearFromTime(t); |
| 702 | if (0 <= day && day < 31) |
| 703 | return 0; |
| 704 | if (31 <= day && day < 59 + _isLeapYear(year)) |
| 705 | return 1; |
| 706 | if ((59 + _isLeapYear(year)) <= day && day < (90 + _isLeapYear(year))) |
| 707 | return 2; |
| 708 | if ((90 + _isLeapYear(year)) <= day && day < (120 + _isLeapYear(year))) |
| 709 | return 3; |
| 710 | if ((120 + _isLeapYear(year)) <= day && day < (151 + _isLeapYear(year))) |
| 711 | return 4; |
| 712 | if ((151 + _isLeapYear(year)) <= day && day < (181 + _isLeapYear(year))) |
| 713 | return 5; |
| 714 | if ((181 + _isLeapYear(year)) <= day && day < (212 + _isLeapYear(year))) |
| 715 | return 6; |
| 716 | if ((212 + _isLeapYear(year)) <= day && day < (243 + _isLeapYear(year))) |
| 717 | return 7; |
| 718 | if ((243 + _isLeapYear(year)) <= day && day < (273 + _isLeapYear(year))) |
| 719 | return 8; |
| 720 | if ((273 + _isLeapYear(year)) <= day && day < (304 + _isLeapYear(year))) |
| 721 | return 9; |
| 722 | if ((304 + _isLeapYear(year)) <= day && day < (334 + _isLeapYear(year))) |
| 723 | return 10; |
| 724 | if ((334 + _isLeapYear(year)) <= day && day < (365 + _isLeapYear(year))) |
| 725 | return 11; |
| 726 | |
| 727 | return -1; |
| 728 | } |
| 729 | |
| 730 | int _DateFromTime(double t) { |
| 731 | int day = _DayWithinYear(t); |
| 732 | int year = _YearFromTime(t); |
| 733 | bool leap = _isLeapYear(year); |
| 734 | int month = _MonthFromTime(t); |
| 735 | switch (month) { |
| 736 | case 0: |
| 737 | return day + 1; |
| 738 | case 1: |
| 739 | return day - 30; |
| 740 | case 2: |
| 741 | return day - 58 - leap; |
| 742 | case 3: |
| 743 | return day - 89 - leap; |
| 744 | case 4: |
| 745 | return day - 119 - leap; |
| 746 | case 5: |
| 747 | return day - 150 - leap; |
| 748 | case 6: |
| 749 | return day - 180 - leap; |
| 750 | case 7: |
| 751 | return day - 211 - leap; |
| 752 | case 8: |
| 753 | return day - 242 - leap; |
| 754 | case 9: |
| 755 | return day - 272 - leap; |
| 756 | case 10: |
| 757 | return day - 303 - leap; |
| 758 | case 11: |
| 759 | return day - 333 - leap; |
| 760 | default: |
| 761 | return 0; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | double JS_GetDateTime() { |
| 766 | if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
| 767 | return 0; |
| 768 | time_t t = time(NULL); |
| 769 | struct tm* pTm = localtime(&t); |
| 770 | |
| 771 | int year = pTm->tm_year + 1900; |
| 772 | double t1 = _TimeFromYear(year); |
| 773 | |
| 774 | return t1 + pTm->tm_yday * 86400000.0 + pTm->tm_hour * 3600000.0 + |
| 775 | pTm->tm_min * 60000.0 + pTm->tm_sec * 1000.0; |
| 776 | } |
| 777 | |
| 778 | int JS_GetYearFromTime(double dt) { |
| 779 | return _YearFromTime(dt); |
| 780 | } |
| 781 | |
| 782 | int JS_GetMonthFromTime(double dt) { |
| 783 | return _MonthFromTime(dt); |
| 784 | } |
| 785 | |
| 786 | int JS_GetDayFromTime(double dt) { |
| 787 | return _DateFromTime(dt); |
| 788 | } |
| 789 | |
| 790 | int JS_GetHourFromTime(double dt) { |
| 791 | return (int)_Mod(FXSYS_floor((double)(dt / (60 * 60 * 1000))), 24); |
| 792 | } |
| 793 | |
| 794 | int JS_GetMinFromTime(double dt) { |
| 795 | return (int)_Mod(FXSYS_floor((double)(dt / (60 * 1000))), 60); |
| 796 | } |
| 797 | |
| 798 | int JS_GetSecFromTime(double dt) { |
| 799 | return (int)_Mod(FXSYS_floor((double)(dt / 1000)), 60); |
| 800 | } |
| 801 | |
| 802 | double JS_DateParse(const wchar_t* string) { |
| 803 | v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); |
| 804 | v8::Isolate::Scope isolate_scope(pIsolate); |
| 805 | v8::HandleScope scope(pIsolate); |
| 806 | |
| 807 | v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
| 808 | |
| 809 | // Use the built-in object method. |
| 810 | v8::Local<v8::Value> v = |
| 811 | context->Global() |
| 812 | ->Get(context, v8::String::NewFromUtf8(pIsolate, "Date", |
| 813 | v8::NewStringType::kNormal) |
| 814 | .ToLocalChecked()) |
| 815 | .ToLocalChecked(); |
| 816 | if (v->IsObject()) { |
| 817 | v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked(); |
| 818 | v = o->Get(context, v8::String::NewFromUtf8(pIsolate, "parse", |
| 819 | v8::NewStringType::kNormal) |
| 820 | .ToLocalChecked()).ToLocalChecked(); |
| 821 | if (v->IsFunction()) { |
| 822 | v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v); |
| 823 | |
| 824 | const int argc = 1; |
| 825 | v8::Local<v8::String> timeStr = FXJS_WSToJSString(pIsolate, string); |
| 826 | v8::Local<v8::Value> argv[argc] = {timeStr}; |
| 827 | v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); |
| 828 | if (v->IsNumber()) { |
| 829 | double date = v->ToNumber(context).ToLocalChecked()->Value(); |
| 830 | if (!_isfinite(date)) |
| 831 | return date; |
| 832 | return date + _getLocalTZA() + _getDaylightSavingTA(date); |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | double JS_MakeDay(int nYear, int nMonth, int nDate) { |
| 840 | if (!_isfinite(nYear) || !_isfinite(nMonth) || !_isfinite(nDate)) |
| 841 | return GetNan(); |
| 842 | double y = _toInteger(nYear); |
| 843 | double m = _toInteger(nMonth); |
| 844 | double dt = _toInteger(nDate); |
| 845 | double ym = y + FXSYS_floor((double)m / 12); |
| 846 | double mn = _Mod(m, 12); |
| 847 | |
| 848 | double t = _TimeFromYearMonth((int)ym, (int)mn); |
| 849 | |
| 850 | if (_YearFromTime(t) != ym || _MonthFromTime(t) != mn || |
| 851 | _DateFromTime(t) != 1) |
| 852 | return GetNan(); |
| 853 | return _Day(t) + dt - 1; |
| 854 | } |
| 855 | |
| 856 | double JS_MakeTime(int nHour, int nMin, int nSec, int nMs) { |
| 857 | if (!_isfinite(nHour) || !_isfinite(nMin) || !_isfinite(nSec) || |
| 858 | !_isfinite(nMs)) |
| 859 | return GetNan(); |
| 860 | |
| 861 | double h = _toInteger(nHour); |
| 862 | double m = _toInteger(nMin); |
| 863 | double s = _toInteger(nSec); |
| 864 | double milli = _toInteger(nMs); |
| 865 | |
| 866 | return h * 3600000 + m * 60000 + s * 1000 + milli; |
| 867 | } |
| 868 | |
| 869 | double JS_MakeDate(double day, double time) { |
| 870 | if (!_isfinite(day) || !_isfinite(time)) |
| 871 | return GetNan(); |
| 872 | |
| 873 | return day * 86400000 + time; |
| 874 | } |
| 875 | |
| 876 | bool JS_PortIsNan(double d) { |
| 877 | return d != d; |
| 878 | } |
| 879 | |
| 880 | double JS_LocalTime(double d) { |
| 881 | return JS_GetDateTime() + _getDaylightSavingTA(d); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 882 | } |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 883 | |
| 884 | std::vector<CJS_Value> JS_ExpandKeywordParams( |
| 885 | CJS_Runtime* pRuntime, |
| 886 | const std::vector<CJS_Value>& originals, |
| 887 | size_t nKeywords, |
| 888 | ...) { |
| 889 | ASSERT(nKeywords); |
| 890 | |
| 891 | std::vector<CJS_Value> result(nKeywords, CJS_Value(pRuntime)); |
| 892 | size_t size = std::min(originals.size(), nKeywords); |
| 893 | for (size_t i = 0; i < size; ++i) |
| 894 | result[i] = originals[i]; |
| 895 | |
| 896 | if (originals.size() != 1 || originals[0].GetType() != CJS_Value::VT_object || |
| 897 | originals[0].IsArrayObject()) { |
| 898 | return result; |
| 899 | } |
| 900 | v8::Local<v8::Object> pObj = originals[0].ToV8Object(); |
| 901 | result[0] = CJS_Value(pRuntime); // Make unknown. |
| 902 | |
| 903 | va_list ap; |
| 904 | va_start(ap, nKeywords); |
| 905 | for (int i = 0; i < nKeywords; ++i) { |
| 906 | const wchar_t* property = va_arg(ap, const wchar_t*); |
| 907 | v8::Local<v8::Value> v8Value = |
| 908 | FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); |
| 909 | if (!v8Value->IsUndefined()) |
| 910 | result[i] = CJS_Value(pRuntime, v8Value, CJS_Value::VT_unknown); |
| 911 | } |
| 912 | va_end(ap); |
| 913 | return result; |
| 914 | } |