Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1205)

Side by Side Diff: fpdfsdk/javascript/JS_Value.cpp

Issue 2227673005: Remove backpointer to CJS_Runtime from CJS_Value (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "fpdfsdk/javascript/JS_Value.h" 7 #include "fpdfsdk/javascript/JS_Value.h"
8 8
9 #include <time.h> 9 #include <time.h>
10 10
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 27
28 double 28 double
29 MakeDate(int year, int mon, int day, int hour, int min, int sec, int ms) { 29 MakeDate(int year, int mon, int day, int hour, int min, int sec, int ms) {
30 return JS_MakeDate(JS_MakeDay(year, mon, day), 30 return JS_MakeDate(JS_MakeDay(year, mon, day),
31 JS_MakeTime(hour, min, sec, ms)); 31 JS_MakeTime(hour, min, sec, ms));
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 CJS_Value::CJS_Value(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {} 36 CJS_Value::CJS_Value(CJS_Runtime* pRuntime) {}
37 37
38 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue) 38 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue)
39 : m_pValue(pValue), m_pJSRuntime(pRuntime) {} 39 : m_pValue(pValue) {}
40 40
41 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue) 41 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue)
42 : m_pJSRuntime(pRuntime) { 42 : m_pValue(FXJS_NewNumber(pRuntime->GetIsolate(), iValue)) {}
43 operator=(iValue);
44 }
45 43
46 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const bool& bValue) 44 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const bool& bValue)
47 : m_pJSRuntime(pRuntime) { 45 : m_pValue(FXJS_NewBoolean(pRuntime->GetIsolate(), bValue)) {}
48 operator=(bValue);
49 }
50 46
51 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const float& fValue) 47 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const float& fValue)
52 : m_pJSRuntime(pRuntime) { 48 : m_pValue(FXJS_NewNumber(pRuntime->GetIsolate(), fValue)) {}
53 operator=(fValue);
54 }
55 49
56 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const double& dValue) 50 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const double& dValue)
57 : m_pJSRuntime(pRuntime) { 51 : m_pValue(FXJS_NewNumber(pRuntime->GetIsolate(), dValue)) {}
58 operator=(dValue);
59 }
60 52
61 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pJsObj) 53 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pObj) {
62 : m_pJSRuntime(pRuntime) { 54 if (pObj)
63 operator=(pJsObj); 55 m_pValue = pObj->ToV8Object();
64 } 56 }
65 57
66 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr) 58 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr)
67 : m_pJSRuntime(pRuntime) { 59 : m_pValue(FXJS_NewString(pRuntime->GetIsolate(), (wchar_t*)pWstr)) {}
68 operator=(pWstr);
69 }
70 60
71 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr) 61 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr)
72 : m_pJSRuntime(pRuntime) { 62 : m_pValue(FXJS_NewString(pRuntime->GetIsolate(),
73 operator=(pStr); 63 CFX_WideString::FromLocal(pStr).c_str())) {}
74 }
75 64
76 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array) 65 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array)
77 : m_pValue(array.ToV8Array(pRuntime->GetIsolate())), 66 : m_pValue(array.ToV8Array(pRuntime->GetIsolate())) {}
78 m_pJSRuntime(pRuntime) {} 67
68 CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Date& date)
69 : m_pValue(date.ToV8Date(pRuntime->GetIsolate())) {}
79 70
80 CJS_Value::~CJS_Value() {} 71 CJS_Value::~CJS_Value() {}
81 72
82 CJS_Value::CJS_Value(const CJS_Value& other) = default; 73 CJS_Value::CJS_Value(const CJS_Value& other) = default;
83 74
84 void CJS_Value::Attach(v8::Local<v8::Value> pValue) { 75 void CJS_Value::Attach(v8::Local<v8::Value> pValue) {
85 m_pValue = pValue; 76 m_pValue = pValue;
86 } 77 }
87 78
88 void CJS_Value::Detach() { 79 void CJS_Value::Detach() {
89 m_pValue = v8::Local<v8::Value>(); 80 m_pValue = v8::Local<v8::Value>();
90 } 81 }
91 82
92 int CJS_Value::ToInt() const { 83 int CJS_Value::ToInt(v8::Isolate* pIsolate) const {
dsinclair 2016/08/09 19:25:33 Why not store the isolate in the constructor? Just
Tom Sepez 2016/08/09 20:33:24 Nah, I want to get to a point where a CJS_Value on
93 return FXJS_ToInt32(m_pJSRuntime->GetIsolate(), m_pValue); 84 return FXJS_ToInt32(pIsolate, m_pValue);
94 } 85 }
95 86
96 bool CJS_Value::ToBool() const { 87 bool CJS_Value::ToBool(v8::Isolate* pIsolate) const {
97 return FXJS_ToBoolean(m_pJSRuntime->GetIsolate(), m_pValue); 88 return FXJS_ToBoolean(pIsolate, m_pValue);
98 } 89 }
99 90
100 double CJS_Value::ToDouble() const { 91 double CJS_Value::ToDouble(v8::Isolate* pIsolate) const {
101 return FXJS_ToNumber(m_pJSRuntime->GetIsolate(), m_pValue); 92 return FXJS_ToNumber(pIsolate, m_pValue);
102 } 93 }
103 94
104 float CJS_Value::ToFloat() const { 95 float CJS_Value::ToFloat(v8::Isolate* pIsolate) const {
105 return (float)ToDouble(); 96 return (float)ToDouble(pIsolate);
106 } 97 }
107 98
108 CJS_Object* CJS_Value::ToCJSObject() const { 99 CJS_Object* CJS_Value::ToCJSObject(v8::Isolate* pIsolate) const {
109 v8::Local<v8::Object> pObj = 100 v8::Local<v8::Object> pObj = FXJS_ToObject(pIsolate, m_pValue);
110 FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue); 101 return (CJS_Object*)FXJS_GetPrivate(pIsolate, pObj);
111 return (CJS_Object*)FXJS_GetPrivate(m_pJSRuntime->GetIsolate(), pObj);
112 } 102 }
113 103
114 v8::Local<v8::Object> CJS_Value::ToV8Object() const { 104 v8::Local<v8::Object> CJS_Value::ToV8Object(v8::Isolate* pIsolate) const {
115 return FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue); 105 return FXJS_ToObject(pIsolate, m_pValue);
116 } 106 }
117 107
118 CFX_WideString CJS_Value::ToCFXWideString() const { 108 CFX_WideString CJS_Value::ToCFXWideString(v8::Isolate* pIsolate) const {
119 return FXJS_ToString(m_pJSRuntime->GetIsolate(), m_pValue); 109 return FXJS_ToString(pIsolate, m_pValue);
120 } 110 }
121 111
122 CFX_ByteString CJS_Value::ToCFXByteString() const { 112 CFX_ByteString CJS_Value::ToCFXByteString(v8::Isolate* pIsolate) const {
123 return CFX_ByteString::FromUnicode(ToCFXWideString()); 113 return CFX_ByteString::FromUnicode(ToCFXWideString(pIsolate));
124 } 114 }
125 115
126 v8::Local<v8::Value> CJS_Value::ToV8Value() const { 116 v8::Local<v8::Value> CJS_Value::ToV8Value(v8::Isolate* pIsolate) const {
127 return m_pValue; 117 return m_pValue;
128 } 118 }
129 119
130 v8::Local<v8::Array> CJS_Value::ToV8Array() const { 120 v8::Local<v8::Array> CJS_Value::ToV8Array(v8::Isolate* pIsolate) const {
131 if (IsArrayObject()) 121 if (IsArrayObject())
132 return v8::Local<v8::Array>::Cast( 122 return v8::Local<v8::Array>::Cast(FXJS_ToObject(pIsolate, m_pValue));
133 FXJS_ToObject(m_pJSRuntime->GetIsolate(), m_pValue));
134 return v8::Local<v8::Array>(); 123 return v8::Local<v8::Array>();
135 } 124 }
136 125
137 void CJS_Value::MaybeCoerceToNumber() { 126 void CJS_Value::SetNull(CJS_Runtime* pRuntime) {
127 m_pValue = FXJS_NewNull(pRuntime->GetIsolate());
128 }
129
130 void CJS_Value::MaybeCoerceToNumber(v8::Isolate* pIsolate) {
138 bool bAllowNaN = false; 131 bool bAllowNaN = false;
139 if (GetType() == VT_string) { 132 if (GetType() == VT_string) {
140 CFX_ByteString bstr = ToCFXByteString(); 133 CFX_ByteString bstr = ToCFXByteString(pIsolate);
141 if (bstr.GetLength() == 0) 134 if (bstr.GetLength() == 0)
142 return; 135 return;
143 if (bstr == "NaN") 136 if (bstr == "NaN")
144 bAllowNaN = true; 137 bAllowNaN = true;
145 } 138 }
146 v8::TryCatch try_catch(m_pJSRuntime->GetIsolate()); 139 v8::TryCatch try_catch(pIsolate);
147 v8::MaybeLocal<v8::Number> maybeNum = 140 v8::MaybeLocal<v8::Number> maybeNum =
148 m_pValue->ToNumber(m_pJSRuntime->GetIsolate()->GetCurrentContext()); 141 m_pValue->ToNumber(pIsolate->GetCurrentContext());
149 if (maybeNum.IsEmpty()) 142 if (maybeNum.IsEmpty())
150 return; 143 return;
151 v8::Local<v8::Number> num = maybeNum.ToLocalChecked(); 144 v8::Local<v8::Number> num = maybeNum.ToLocalChecked();
152 if (std::isnan(num->Value()) && !bAllowNaN) 145 if (std::isnan(num->Value()) && !bAllowNaN)
153 return; 146 return;
154 m_pValue = num; 147 m_pValue = num;
155 } 148 }
156 149
157 void CJS_Value::operator=(int iValue) {
158 m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), iValue);
159 }
160
161 void CJS_Value::operator=(bool bValue) {
162 m_pValue = FXJS_NewBoolean(m_pJSRuntime->GetIsolate(), bValue);
163 }
164
165 void CJS_Value::operator=(double dValue) {
166 m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), dValue);
167 }
168
169 void CJS_Value::operator=(float fValue) {
170 m_pValue = FXJS_NewNumber(m_pJSRuntime->GetIsolate(), fValue);
171 }
172
173 void CJS_Value::operator=(v8::Local<v8::Object> pObj) {
174 m_pValue = pObj;
175 }
176
177 void CJS_Value::operator=(CJS_Object* pObj) {
178 if (pObj)
179 operator=(pObj->ToV8Object());
180 }
181
182 void CJS_Value::operator=(const FX_WCHAR* pWstr) {
183 m_pValue = FXJS_NewString(m_pJSRuntime->GetIsolate(), (wchar_t*)pWstr);
184 }
185
186 void CJS_Value::SetNull() {
187 m_pValue = FXJS_NewNull(m_pJSRuntime->GetIsolate());
188 }
189
190 void CJS_Value::operator=(const FX_CHAR* pStr) {
191 operator=(CFX_WideString::FromLocal(pStr).c_str());
192 }
193
194 void CJS_Value::operator=(const CJS_Value& value) {
195 ASSERT(m_pJSRuntime == value.m_pJSRuntime);
196 m_pValue = value.ToV8Value();
197 }
198
199 // static 150 // static
200 CJS_Value::Type CJS_Value::GetValueType(v8::Local<v8::Value> value) { 151 CJS_Value::Type CJS_Value::GetValueType(v8::Local<v8::Value> value) {
201 if (value.IsEmpty()) 152 if (value.IsEmpty())
202 return VT_unknown; 153 return VT_unknown;
203 if (value->IsString()) 154 if (value->IsString())
204 return VT_string; 155 return VT_string;
205 if (value->IsNumber()) 156 if (value->IsNumber())
206 return VT_number; 157 return VT_number;
207 if (value->IsBoolean()) 158 if (value->IsBoolean())
208 return VT_boolean; 159 return VT_boolean;
209 if (value->IsDate()) 160 if (value->IsDate())
210 return VT_date; 161 return VT_date;
211 if (value->IsObject()) 162 if (value->IsObject())
212 return VT_object; 163 return VT_object;
213 if (value->IsNull()) 164 if (value->IsNull())
214 return VT_null; 165 return VT_null;
215 if (value->IsUndefined()) 166 if (value->IsUndefined())
216 return VT_undefined; 167 return VT_undefined;
217 return VT_unknown; 168 return VT_unknown;
218 } 169 }
219 170
220 FX_BOOL CJS_Value::IsArrayObject() const { 171 bool CJS_Value::IsArrayObject() const {
221 if (m_pValue.IsEmpty()) 172 return !m_pValue.IsEmpty() && m_pValue->IsArray();
222 return FALSE;
223 return m_pValue->IsArray();
224 } 173 }
225 174
226 FX_BOOL CJS_Value::IsDateObject() const { 175 bool CJS_Value::IsDateObject() const {
227 if (m_pValue.IsEmpty()) 176 return !m_pValue.IsEmpty() && m_pValue->IsDate();
228 return FALSE;
229 return m_pValue->IsDate();
230 } 177 }
231 178
232 // CJS_Value::operator CJS_Array() 179 bool CJS_Value::ConvertToArray(v8::Isolate* pIsolate, CJS_Array& array) const {
233 FX_BOOL CJS_Value::ConvertToArray(CJS_Array& array) const { 180 if (!IsArrayObject())
234 if (IsArrayObject()) { 181 return false;
235 array.Attach(FXJS_ToArray(m_pJSRuntime->GetIsolate(), m_pValue)); 182 array.Attach(FXJS_ToArray(pIsolate, m_pValue));
236 return TRUE; 183 return true;
237 }
238
239 return FALSE;
240 } 184 }
241 185
242 FX_BOOL CJS_Value::ConvertToDate(CJS_Date& date) const { 186 bool CJS_Value::ConvertToDate(v8::Isolate* pIsolate, CJS_Date& date) const {
243 if (IsDateObject()) { 187 if (!IsDateObject())
244 v8::Local<v8::Value> mutable_value = m_pValue; 188 return false;
245 date.Attach(mutable_value.As<v8::Date>()); 189 v8::Local<v8::Value> mutable_value = m_pValue;
246 return TRUE; 190 date.Attach(mutable_value.As<v8::Date>());
247 } 191 return true;
248
249 return FALSE;
250 } 192 }
251 193
252 CJS_PropValue::CJS_PropValue(const CJS_Value& value) 194 CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime)
dsinclair 2016/08/09 19:25:33 It looks like, if the CJS_Value is changed to take
Tom Sepez 2016/08/09 20:33:24 Yeah, same deal. The propvalue isn't a real value
253 : CJS_Value(value), m_bIsSetting(0) {} 195 : m_bIsSetting(0), m_Value(pRuntime), m_pJSRuntime(pRuntime) {}
254 196
255 CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime) 197 CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime, const CJS_Value& value)
256 : CJS_Value(pRuntime), m_bIsSetting(0) {} 198 : m_bIsSetting(0), m_Value(value), m_pJSRuntime(pRuntime) {}
257 199
258 CJS_PropValue::~CJS_PropValue() {} 200 CJS_PropValue::~CJS_PropValue() {}
259 201
260 void CJS_PropValue::operator<<(int iValue) { 202 void CJS_PropValue::operator<<(int iValue) {
261 ASSERT(!m_bIsSetting); 203 ASSERT(!m_bIsSetting);
262 CJS_Value::operator=(iValue); 204 m_Value = CJS_Value(m_pJSRuntime, iValue);
263 } 205 }
264 206
265 void CJS_PropValue::operator>>(int& iValue) const { 207 void CJS_PropValue::operator>>(int& iValue) const {
266 ASSERT(m_bIsSetting); 208 ASSERT(m_bIsSetting);
267 iValue = CJS_Value::ToInt(); 209 iValue = m_Value.ToInt(m_pJSRuntime->GetIsolate());
268 } 210 }
269 211
270 void CJS_PropValue::operator<<(bool bValue) { 212 void CJS_PropValue::operator<<(bool bValue) {
271 ASSERT(!m_bIsSetting); 213 ASSERT(!m_bIsSetting);
272 CJS_Value::operator=(bValue); 214 m_Value = CJS_Value(m_pJSRuntime, bValue);
273 } 215 }
274 216
275 void CJS_PropValue::operator>>(bool& bValue) const { 217 void CJS_PropValue::operator>>(bool& bValue) const {
276 ASSERT(m_bIsSetting); 218 ASSERT(m_bIsSetting);
277 bValue = CJS_Value::ToBool(); 219 bValue = m_Value.ToBool(m_pJSRuntime->GetIsolate());
278 } 220 }
279 221
280 void CJS_PropValue::operator<<(double dValue) { 222 void CJS_PropValue::operator<<(double dValue) {
281 ASSERT(!m_bIsSetting); 223 ASSERT(!m_bIsSetting);
282 CJS_Value::operator=(dValue); 224 m_Value = CJS_Value(m_pJSRuntime, dValue);
283 } 225 }
284 226
285 void CJS_PropValue::operator>>(double& dValue) const { 227 void CJS_PropValue::operator>>(double& dValue) const {
286 ASSERT(m_bIsSetting); 228 ASSERT(m_bIsSetting);
287 dValue = CJS_Value::ToDouble(); 229 dValue = m_Value.ToDouble(m_pJSRuntime->GetIsolate());
288 } 230 }
289 231
290 void CJS_PropValue::operator<<(CJS_Object* pObj) { 232 void CJS_PropValue::operator<<(CJS_Object* pObj) {
291 ASSERT(!m_bIsSetting); 233 ASSERT(!m_bIsSetting);
292 CJS_Value::operator=(pObj); 234 m_Value = CJS_Value(m_pJSRuntime, pObj);
293 } 235 }
294 236
295 void CJS_PropValue::operator>>(CJS_Object*& ppObj) const { 237 void CJS_PropValue::operator>>(CJS_Object*& ppObj) const {
296 ASSERT(m_bIsSetting); 238 ASSERT(m_bIsSetting);
297 ppObj = CJS_Value::ToCJSObject(); 239 ppObj = m_Value.ToCJSObject(m_pJSRuntime->GetIsolate());
298 } 240 }
299 241
300 void CJS_PropValue::operator<<(CJS_Document* pJsDoc) { 242 void CJS_PropValue::operator<<(CJS_Document* pJsDoc) {
301 ASSERT(!m_bIsSetting); 243 ASSERT(!m_bIsSetting);
302 CJS_Value::operator=(pJsDoc); 244 m_Value = CJS_Value(m_pJSRuntime, pJsDoc);
303 } 245 }
304 246
305 void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const { 247 void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const {
306 ASSERT(m_bIsSetting); 248 ASSERT(m_bIsSetting);
307 ppJsDoc = static_cast<CJS_Document*>(CJS_Value::ToCJSObject()); 249 ppJsDoc = static_cast<CJS_Document*>(
250 m_Value.ToCJSObject(m_pJSRuntime->GetIsolate()));
308 } 251 }
309 252
310 void CJS_PropValue::operator<<(v8::Local<v8::Object> pObj) { 253 void CJS_PropValue::operator<<(v8::Local<v8::Object> pObj) {
311 ASSERT(!m_bIsSetting); 254 ASSERT(!m_bIsSetting);
312 CJS_Value::operator=(pObj); 255 m_Value = CJS_Value(m_pJSRuntime, pObj);
313 } 256 }
314 257
315 void CJS_PropValue::operator>>(v8::Local<v8::Object>& ppObj) const { 258 void CJS_PropValue::operator>>(v8::Local<v8::Object>& ppObj) const {
316 ASSERT(m_bIsSetting); 259 ASSERT(m_bIsSetting);
317 ppObj = CJS_Value::ToV8Object(); 260 ppObj = m_Value.ToV8Object(m_pJSRuntime->GetIsolate());
318 } 261 }
319 262
320 void CJS_PropValue::operator<<(CFX_ByteString str) { 263 void CJS_PropValue::operator<<(CFX_ByteString str) {
321 ASSERT(!m_bIsSetting); 264 ASSERT(!m_bIsSetting);
322 CJS_Value::operator=(str.c_str()); 265 m_Value = CJS_Value(m_pJSRuntime, str.c_str());
323 } 266 }
324 267
325 void CJS_PropValue::operator>>(CFX_ByteString& str) const { 268 void CJS_PropValue::operator>>(CFX_ByteString& str) const {
326 ASSERT(m_bIsSetting); 269 ASSERT(m_bIsSetting);
327 str = CJS_Value::ToCFXByteString(); 270 str = m_Value.ToCFXByteString(m_pJSRuntime->GetIsolate());
328 } 271 }
329 272
330 void CJS_PropValue::operator<<(const FX_WCHAR* c_string) { 273 void CJS_PropValue::operator<<(const FX_WCHAR* str) {
331 ASSERT(!m_bIsSetting); 274 ASSERT(!m_bIsSetting);
332 CJS_Value::operator=(c_string); 275 m_Value = CJS_Value(m_pJSRuntime, str);
333 } 276 }
334 277
335 void CJS_PropValue::operator>>(CFX_WideString& wide_string) const { 278 void CJS_PropValue::operator>>(CFX_WideString& wide_string) const {
336 ASSERT(m_bIsSetting); 279 ASSERT(m_bIsSetting);
337 wide_string = CJS_Value::ToCFXWideString(); 280 wide_string = m_Value.ToCFXWideString(m_pJSRuntime->GetIsolate());
338 } 281 }
339 282
340 void CJS_PropValue::operator<<(CFX_WideString wide_string) { 283 void CJS_PropValue::operator<<(CFX_WideString wide_string) {
341 ASSERT(!m_bIsSetting); 284 ASSERT(!m_bIsSetting);
342 CJS_Value::operator=(wide_string.c_str()); 285 m_Value = CJS_Value(m_pJSRuntime, wide_string.c_str());
343 } 286 }
344 287
345 void CJS_PropValue::operator>>(CJS_Array& array) const { 288 void CJS_PropValue::operator>>(CJS_Array& array) const {
346 ASSERT(m_bIsSetting); 289 ASSERT(m_bIsSetting);
347 ConvertToArray(array); 290 m_Value.ConvertToArray(m_pJSRuntime->GetIsolate(), array);
348 } 291 }
349 292
350 void CJS_PropValue::operator<<(CJS_Array& array) { 293 void CJS_PropValue::operator<<(CJS_Array& array) {
351 ASSERT(!m_bIsSetting); 294 ASSERT(!m_bIsSetting);
352 m_pValue = array.ToV8Array(m_pJSRuntime->GetIsolate()); 295 m_Value =
296 CJS_Value(m_pJSRuntime, array.ToV8Array(m_pJSRuntime->GetIsolate()));
353 } 297 }
354 298
355 void CJS_PropValue::operator>>(CJS_Date& date) const { 299 void CJS_PropValue::operator>>(CJS_Date& date) const {
356 ASSERT(m_bIsSetting); 300 ASSERT(m_bIsSetting);
357 ConvertToDate(date); 301 m_Value.ConvertToDate(m_pJSRuntime->GetIsolate(), date);
358 } 302 }
359 303
360 void CJS_PropValue::operator<<(CJS_Date& date) { 304 void CJS_PropValue::operator<<(CJS_Date& date) {
361 ASSERT(!m_bIsSetting); 305 ASSERT(!m_bIsSetting);
362 m_pValue = date.ToV8Date(m_pJSRuntime->GetIsolate()); 306 m_Value = CJS_Value(m_pJSRuntime, date);
363 } 307 }
364 308
365 CJS_Array::CJS_Array() {} 309 CJS_Array::CJS_Array() {}
366 310
367 CJS_Array::CJS_Array(const CJS_Array& other) = default; 311 CJS_Array::CJS_Array(const CJS_Array& other) = default;
368 312
369 CJS_Array::~CJS_Array() {} 313 CJS_Array::~CJS_Array() {}
370 314
371 void CJS_Array::Attach(v8::Local<v8::Array> pArray) { 315 void CJS_Array::Attach(v8::Local<v8::Array> pArray) {
372 m_pArray = pArray; 316 m_pArray = pArray;
373 } 317 }
374 318
375 void CJS_Array::GetElement(v8::Isolate* pIsolate, 319 void CJS_Array::GetElement(v8::Isolate* pIsolate,
376 unsigned index, 320 unsigned index,
377 CJS_Value& value) const { 321 CJS_Value& value) const {
378 if (!m_pArray.IsEmpty()) 322 if (!m_pArray.IsEmpty())
379 value.Attach(FXJS_GetArrayElement(pIsolate, m_pArray, index)); 323 value.Attach(FXJS_GetArrayElement(pIsolate, m_pArray, index));
380 } 324 }
381 325
382 void CJS_Array::SetElement(v8::Isolate* pIsolate, 326 void CJS_Array::SetElement(v8::Isolate* pIsolate,
383 unsigned index, 327 unsigned index,
384 const CJS_Value& value) { 328 const CJS_Value& value) {
385 if (m_pArray.IsEmpty()) 329 if (m_pArray.IsEmpty())
386 m_pArray = FXJS_NewArray(pIsolate); 330 m_pArray = FXJS_NewArray(pIsolate);
387 331
388 FXJS_PutArrayElement(pIsolate, m_pArray, index, value.ToV8Value()); 332 FXJS_PutArrayElement(pIsolate, m_pArray, index, value.ToV8Value(pIsolate));
389 } 333 }
390 334
391 int CJS_Array::GetLength() const { 335 int CJS_Array::GetLength() const {
392 if (m_pArray.IsEmpty()) 336 if (m_pArray.IsEmpty())
393 return 0; 337 return 0;
394 return FXJS_GetArrayLength(m_pArray); 338 return FXJS_GetArrayLength(m_pArray);
395 } 339 }
396 340
397 v8::Local<v8::Array> CJS_Array::ToV8Array(v8::Isolate* pIsolate) const { 341 v8::Local<v8::Array> CJS_Array::ToV8Array(v8::Isolate* pIsolate) const {
398 if (m_pArray.IsEmpty()) 342 if (m_pArray.IsEmpty())
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 756
813 std::vector<CJS_Value> result(nKeywords, CJS_Value(pRuntime)); 757 std::vector<CJS_Value> result(nKeywords, CJS_Value(pRuntime));
814 size_t size = std::min(originals.size(), nKeywords); 758 size_t size = std::min(originals.size(), nKeywords);
815 for (size_t i = 0; i < size; ++i) 759 for (size_t i = 0; i < size; ++i)
816 result[i] = originals[i]; 760 result[i] = originals[i];
817 761
818 if (originals.size() != 1 || originals[0].GetType() != CJS_Value::VT_object || 762 if (originals.size() != 1 || originals[0].GetType() != CJS_Value::VT_object ||
819 originals[0].IsArrayObject()) { 763 originals[0].IsArrayObject()) {
820 return result; 764 return result;
821 } 765 }
822 v8::Local<v8::Object> pObj = originals[0].ToV8Object(); 766 v8::Local<v8::Object> pObj = originals[0].ToV8Object(pRuntime->GetIsolate());
823 result[0] = CJS_Value(pRuntime); // Make unknown. 767 result[0] = CJS_Value(pRuntime); // Make unknown.
824 768
825 va_list ap; 769 va_list ap;
826 va_start(ap, nKeywords); 770 va_start(ap, nKeywords);
827 for (size_t i = 0; i < nKeywords; ++i) { 771 for (size_t i = 0; i < nKeywords; ++i) {
828 const wchar_t* property = va_arg(ap, const wchar_t*); 772 const wchar_t* property = va_arg(ap, const wchar_t*);
829 v8::Local<v8::Value> v8Value = 773 v8::Local<v8::Value> v8Value =
830 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property); 774 FXJS_GetObjectElement(pRuntime->GetIsolate(), pObj, property);
831 if (!v8Value->IsUndefined()) 775 if (!v8Value->IsUndefined())
832 result[i] = CJS_Value(pRuntime, v8Value); 776 result[i] = CJS_Value(pRuntime, v8Value);
833 } 777 }
834 va_end(ap); 778 va_end(ap);
835 return result; 779 return result;
836 } 780 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698