OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "fpdfsdk/src/javascript/global.h" | |
8 | |
9 #include <vector> | |
10 | |
11 #include "core/include/fxcrt/fx_ext.h" | |
12 #include "fpdfsdk/include/javascript/IJavaScript.h" | |
13 #include "fpdfsdk/src/javascript/JS_Context.h" | |
14 #include "fpdfsdk/src/javascript/JS_Define.h" | |
15 #include "fpdfsdk/src/javascript/JS_EventHandler.h" | |
16 #include "fpdfsdk/src/javascript/JS_GlobalData.h" | |
17 #include "fpdfsdk/src/javascript/JS_Object.h" | |
18 #include "fpdfsdk/src/javascript/JS_Value.h" | |
19 #include "fpdfsdk/src/javascript/resource.h" | |
20 | |
21 /* ---------------------------- global ---------------------------- */ | |
22 | |
23 // Helper class for compile-time calculation of hash values in order to | |
24 // avoid having global object initializers. | |
25 template <unsigned ACC, wchar_t... Ns> | |
26 struct CHash; | |
27 | |
28 // Only needed to hash single-character strings. | |
29 template <wchar_t N> | |
30 struct CHash<N> { | |
31 static const unsigned value = N; | |
32 }; | |
33 | |
34 template <unsigned ACC, wchar_t N> | |
35 struct CHash<ACC, N> { | |
36 static const unsigned value = (ACC * 1313LLU + N) & 0xFFFFFFFF; | |
37 }; | |
38 | |
39 template <unsigned ACC, wchar_t N, wchar_t... Ns> | |
40 struct CHash<ACC, N, Ns...> { | |
41 static const unsigned value = CHash<CHash<ACC, N>::value, Ns...>::value; | |
42 }; | |
43 | |
44 const unsigned int JSCONST_nStringHash = | |
45 CHash<'s', 't', 'r', 'i', 'n', 'g'>::value; | |
46 const unsigned int JSCONST_nNumberHash = | |
47 CHash<'n', 'u', 'm', 'b', 'e', 'r'>::value; | |
48 const unsigned int JSCONST_nBoolHash = | |
49 CHash<'b', 'o', 'o', 'l', 'e', 'a', 'n'>::value; | |
50 const unsigned int JSCONST_nDateHash = CHash<'d', 'a', 't', 'e'>::value; | |
51 const unsigned int JSCONST_nObjectHash = | |
52 CHash<'o', 'b', 'j', 'e', 'c', 't'>::value; | |
53 const unsigned int JSCONST_nFXobjHash = CHash<'f', 'x', 'o', 'b', 'j'>::value; | |
54 const unsigned int JSCONST_nNullHash = CHash<'n', 'u', 'l', 'l'>::value; | |
55 const unsigned int JSCONST_nUndefHash = | |
56 CHash<'u', 'n', 'd', 'e', 'f', 'i', 'n', 'e', 'd'>::value; | |
57 | |
58 static unsigned JS_CalcHash(const wchar_t* main) { | |
59 return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main)); | |
60 } | |
61 | |
62 #ifndef NDEBUG | |
63 class HashVerify { | |
64 public: | |
65 HashVerify(); | |
66 } g_hashVerify; | |
67 | |
68 HashVerify::HashVerify() { | |
69 ASSERT(JSCONST_nStringHash == JS_CalcHash(kFXJSValueNameString)); | |
70 ASSERT(JSCONST_nNumberHash == JS_CalcHash(kFXJSValueNameNumber)); | |
71 ASSERT(JSCONST_nBoolHash == JS_CalcHash(kFXJSValueNameBoolean)); | |
72 ASSERT(JSCONST_nDateHash == JS_CalcHash(kFXJSValueNameDate)); | |
73 ASSERT(JSCONST_nObjectHash == JS_CalcHash(kFXJSValueNameObject)); | |
74 ASSERT(JSCONST_nFXobjHash == JS_CalcHash(kFXJSValueNameFxobj)); | |
75 ASSERT(JSCONST_nNullHash == JS_CalcHash(kFXJSValueNameNull)); | |
76 ASSERT(JSCONST_nUndefHash == JS_CalcHash(kFXJSValueNameUndefined)); | |
77 } | |
78 #endif | |
79 | |
80 BEGIN_JS_STATIC_CONST(CJS_Global) | |
81 END_JS_STATIC_CONST() | |
82 | |
83 BEGIN_JS_STATIC_PROP(CJS_Global) | |
84 END_JS_STATIC_PROP() | |
85 | |
86 BEGIN_JS_STATIC_METHOD(CJS_Global) | |
87 JS_STATIC_METHOD_ENTRY(setPersistent) | |
88 END_JS_STATIC_METHOD() | |
89 | |
90 IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, JSGlobalAlternate, global); | |
91 | |
92 void CJS_Global::InitInstance(IJS_Runtime* pIRuntime) { | |
93 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); | |
94 JSGlobalAlternate* pGlobal = | |
95 static_cast<JSGlobalAlternate*>(GetEmbedObject()); | |
96 pGlobal->Initial(pRuntime->GetReaderApp()); | |
97 } | |
98 | |
99 JSGlobalAlternate::JSGlobalAlternate(CJS_Object* pJSObject) | |
100 : CJS_EmbedObj(pJSObject), m_pApp(NULL) { | |
101 } | |
102 | |
103 JSGlobalAlternate::~JSGlobalAlternate() { | |
104 DestroyGlobalPersisitentVariables(); | |
105 m_pGlobalData->Release(); | |
106 } | |
107 | |
108 void JSGlobalAlternate::Initial(CPDFDoc_Environment* pApp) { | |
109 m_pApp = pApp; | |
110 m_pGlobalData = CJS_GlobalData::GetRetainedInstance(pApp); | |
111 UpdateGlobalPersistentVariables(); | |
112 } | |
113 | |
114 FX_BOOL JSGlobalAlternate::QueryProperty(const FX_WCHAR* propname) { | |
115 return CFX_WideString(propname) != L"setPersistent"; | |
116 } | |
117 | |
118 FX_BOOL JSGlobalAlternate::DelProperty(IJS_Context* cc, | |
119 const FX_WCHAR* propname, | |
120 CFX_WideString& sError) { | |
121 auto it = m_mapGlobal.find(CFX_ByteString::FromUnicode(propname)); | |
122 if (it == m_mapGlobal.end()) | |
123 return FALSE; | |
124 | |
125 it->second->bDeleted = TRUE; | |
126 return TRUE; | |
127 } | |
128 | |
129 FX_BOOL JSGlobalAlternate::DoProperty(IJS_Context* cc, | |
130 const FX_WCHAR* propname, | |
131 CJS_PropValue& vp, | |
132 CFX_WideString& sError) { | |
133 if (vp.IsSetting()) { | |
134 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); | |
135 switch (vp.GetType()) { | |
136 case CJS_Value::VT_number: { | |
137 double dData; | |
138 vp >> dData; | |
139 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NUMBER, dData, | |
140 false, "", v8::Local<v8::Object>(), FALSE); | |
141 } | |
142 case CJS_Value::VT_boolean: { | |
143 bool bData; | |
144 vp >> bData; | |
145 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0, | |
146 bData, "", v8::Local<v8::Object>(), FALSE); | |
147 } | |
148 case CJS_Value::VT_string: { | |
149 CFX_ByteString sData; | |
150 vp >> sData; | |
151 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0, | |
152 false, sData, v8::Local<v8::Object>(), FALSE); | |
153 } | |
154 case CJS_Value::VT_object: { | |
155 v8::Local<v8::Object> pData; | |
156 vp >> pData; | |
157 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, | |
158 false, "", pData, FALSE); | |
159 } | |
160 case CJS_Value::VT_null: { | |
161 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false, | |
162 "", v8::Local<v8::Object>(), FALSE); | |
163 } | |
164 case CJS_Value::VT_undefined: { | |
165 DelProperty(cc, propname, sError); | |
166 return TRUE; | |
167 } | |
168 default: | |
169 break; | |
170 } | |
171 } else { | |
172 auto it = m_mapGlobal.find(CFX_ByteString::FromUnicode(propname)); | |
173 if (it == m_mapGlobal.end()) { | |
174 vp.SetNull(); | |
175 return TRUE; | |
176 } | |
177 JSGlobalData* pData = it->second; | |
178 if (pData->bDeleted) { | |
179 vp.SetNull(); | |
180 return TRUE; | |
181 } | |
182 switch (pData->nType) { | |
183 case JS_GLOBALDATA_TYPE_NUMBER: | |
184 vp << pData->dData; | |
185 return TRUE; | |
186 case JS_GLOBALDATA_TYPE_BOOLEAN: | |
187 vp << pData->bData; | |
188 return TRUE; | |
189 case JS_GLOBALDATA_TYPE_STRING: | |
190 vp << pData->sData; | |
191 return TRUE; | |
192 case JS_GLOBALDATA_TYPE_OBJECT: { | |
193 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New( | |
194 vp.GetJSRuntime()->GetIsolate(), pData->pData); | |
195 vp << obj; | |
196 return TRUE; | |
197 } | |
198 case JS_GLOBALDATA_TYPE_NULL: | |
199 vp.SetNull(); | |
200 return TRUE; | |
201 default: | |
202 break; | |
203 } | |
204 } | |
205 return FALSE; | |
206 } | |
207 | |
208 FX_BOOL JSGlobalAlternate::setPersistent(IJS_Context* cc, | |
209 const std::vector<CJS_Value>& params, | |
210 CJS_Value& vRet, | |
211 CFX_WideString& sError) { | |
212 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
213 if (params.size() != 2) { | |
214 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
215 return FALSE; | |
216 } | |
217 | |
218 auto it = m_mapGlobal.find(params[0].ToCFXByteString()); | |
219 if (it != m_mapGlobal.end()) { | |
220 JSGlobalData* pData = it->second; | |
221 if (!pData->bDeleted) { | |
222 pData->bPersistent = params[1].ToBool(); | |
223 return TRUE; | |
224 } | |
225 } | |
226 | |
227 sError = JSGetStringFromID(pContext, IDS_STRING_JSNOGLOBAL); | |
228 return FALSE; | |
229 } | |
230 | |
231 void JSGlobalAlternate::UpdateGlobalPersistentVariables() { | |
232 for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { | |
233 CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); | |
234 switch (pData->data.nType) { | |
235 case JS_GLOBALDATA_TYPE_NUMBER: | |
236 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, | |
237 pData->data.dData, false, "", | |
238 v8::Local<v8::Object>(), pData->bPersistent == 1); | |
239 FXJS_PutObjectNumber(NULL, m_pJSObject->ToV8Object(), | |
240 pData->data.sKey.UTF8Decode().c_str(), | |
241 pData->data.dData); | |
242 break; | |
243 case JS_GLOBALDATA_TYPE_BOOLEAN: | |
244 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, | |
245 (bool)(pData->data.bData == 1), "", | |
246 v8::Local<v8::Object>(), pData->bPersistent == 1); | |
247 FXJS_PutObjectBoolean(NULL, m_pJSObject->ToV8Object(), | |
248 pData->data.sKey.UTF8Decode().c_str(), | |
249 (bool)(pData->data.bData == 1)); | |
250 break; | |
251 case JS_GLOBALDATA_TYPE_STRING: | |
252 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, | |
253 false, pData->data.sData, v8::Local<v8::Object>(), | |
254 pData->bPersistent == 1); | |
255 FXJS_PutObjectString(NULL, m_pJSObject->ToV8Object(), | |
256 pData->data.sKey.UTF8Decode().c_str(), | |
257 pData->data.sData.UTF8Decode().c_str()); | |
258 break; | |
259 case JS_GLOBALDATA_TYPE_OBJECT: { | |
260 v8::Isolate* pRuntime = m_pJSObject->ToV8Object()->GetIsolate(); | |
261 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(pRuntime, NULL, -1); | |
262 | |
263 PutObjectProperty(pObj, &pData->data); | |
264 | |
265 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, | |
266 false, "", pObj, pData->bPersistent == 1); | |
267 FXJS_PutObjectObject(NULL, m_pJSObject->ToV8Object(), | |
268 pData->data.sKey.UTF8Decode().c_str(), pObj); | |
269 } break; | |
270 case JS_GLOBALDATA_TYPE_NULL: | |
271 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, | |
272 "", v8::Local<v8::Object>(), | |
273 pData->bPersistent == 1); | |
274 FXJS_PutObjectNull(NULL, m_pJSObject->ToV8Object(), | |
275 pData->data.sKey.UTF8Decode().c_str()); | |
276 break; | |
277 } | |
278 } | |
279 } | |
280 | |
281 void JSGlobalAlternate::CommitGlobalPersisitentVariables(IJS_Context* cc) { | |
282 for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) { | |
283 CFX_ByteString name = it->first; | |
284 JSGlobalData* pData = it->second; | |
285 if (pData->bDeleted) { | |
286 m_pGlobalData->DeleteGlobalVariable(name); | |
287 } else { | |
288 switch (pData->nType) { | |
289 case JS_GLOBALDATA_TYPE_NUMBER: | |
290 m_pGlobalData->SetGlobalVariableNumber(name, pData->dData); | |
291 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); | |
292 break; | |
293 case JS_GLOBALDATA_TYPE_BOOLEAN: | |
294 m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData); | |
295 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); | |
296 break; | |
297 case JS_GLOBALDATA_TYPE_STRING: | |
298 m_pGlobalData->SetGlobalVariableString(name, pData->sData); | |
299 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); | |
300 break; | |
301 case JS_GLOBALDATA_TYPE_OBJECT: | |
302 { | |
303 CJS_GlobalVariableArray array; | |
304 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New( | |
305 GetJSObject()->GetIsolate(), pData->pData); | |
306 ObjectToArray(cc, obj, array); | |
307 m_pGlobalData->SetGlobalVariableObject(name, array); | |
308 m_pGlobalData->SetGlobalVariablePersistent(name, | |
309 pData->bPersistent); | |
310 } | |
311 break; | |
312 case JS_GLOBALDATA_TYPE_NULL: | |
313 m_pGlobalData->SetGlobalVariableNull(name); | |
314 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); | |
315 break; | |
316 } | |
317 } | |
318 } | |
319 } | |
320 | |
321 void JSGlobalAlternate::ObjectToArray(IJS_Context* cc, | |
322 v8::Local<v8::Object> pObj, | |
323 CJS_GlobalVariableArray& array) { | |
324 v8::Isolate* isolate = pObj->GetIsolate(); | |
325 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
326 | |
327 v8::Local<v8::Array> pKeyList = FXJS_GetObjectElementNames(isolate, pObj); | |
328 int nObjElements = pKeyList->Length(); | |
329 for (int i = 0; i < nObjElements; i++) { | |
330 CFX_WideString ws = | |
331 FXJS_ToString(isolate, FXJS_GetArrayElement(isolate, pKeyList, i)); | |
332 CFX_ByteString sKey = ws.UTF8Encode(); | |
333 | |
334 v8::Local<v8::Value> v = FXJS_GetObjectElement(isolate, pObj, ws.c_str()); | |
335 switch (GET_VALUE_TYPE(v)) { | |
336 case CJS_Value::VT_number: { | |
337 CJS_KeyValue* pObjElement = new CJS_KeyValue; | |
338 pObjElement->nType = JS_GLOBALDATA_TYPE_NUMBER; | |
339 pObjElement->sKey = sKey; | |
340 pObjElement->dData = FXJS_ToNumber(isolate, v); | |
341 array.Add(pObjElement); | |
342 } break; | |
343 case CJS_Value::VT_boolean: { | |
344 CJS_KeyValue* pObjElement = new CJS_KeyValue; | |
345 pObjElement->nType = JS_GLOBALDATA_TYPE_BOOLEAN; | |
346 pObjElement->sKey = sKey; | |
347 pObjElement->dData = FXJS_ToBoolean(isolate, v); | |
348 array.Add(pObjElement); | |
349 } break; | |
350 case CJS_Value::VT_string: { | |
351 CFX_ByteString sValue = | |
352 CJS_Value(pRuntime, v, CJS_Value::VT_string).ToCFXByteString(); | |
353 CJS_KeyValue* pObjElement = new CJS_KeyValue; | |
354 pObjElement->nType = JS_GLOBALDATA_TYPE_STRING; | |
355 pObjElement->sKey = sKey; | |
356 pObjElement->sData = sValue; | |
357 array.Add(pObjElement); | |
358 } break; | |
359 case CJS_Value::VT_object: { | |
360 CJS_KeyValue* pObjElement = new CJS_KeyValue; | |
361 pObjElement->nType = JS_GLOBALDATA_TYPE_OBJECT; | |
362 pObjElement->sKey = sKey; | |
363 ObjectToArray(cc, FXJS_ToObject(isolate, v), pObjElement->objData); | |
364 array.Add(pObjElement); | |
365 } break; | |
366 case CJS_Value::VT_null: { | |
367 CJS_KeyValue* pObjElement = new CJS_KeyValue; | |
368 pObjElement->nType = JS_GLOBALDATA_TYPE_NULL; | |
369 pObjElement->sKey = sKey; | |
370 array.Add(pObjElement); | |
371 } break; | |
372 default: | |
373 break; | |
374 } | |
375 } | |
376 } | |
377 | |
378 void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj, | |
379 CJS_KeyValue* pData) { | |
380 for (int i = 0, sz = pData->objData.Count(); i < sz; i++) { | |
381 CJS_KeyValue* pObjData = pData->objData.GetAt(i); | |
382 switch (pObjData->nType) { | |
383 case JS_GLOBALDATA_TYPE_NUMBER: | |
384 FXJS_PutObjectNumber(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(), | |
385 pObjData->dData); | |
386 break; | |
387 case JS_GLOBALDATA_TYPE_BOOLEAN: | |
388 FXJS_PutObjectBoolean(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(), | |
389 pObjData->bData == 1); | |
390 break; | |
391 case JS_GLOBALDATA_TYPE_STRING: | |
392 FXJS_PutObjectString(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(), | |
393 pObjData->sData.UTF8Decode().c_str()); | |
394 break; | |
395 case JS_GLOBALDATA_TYPE_OBJECT: { | |
396 v8::Isolate* pRuntime = m_pJSObject->ToV8Object()->GetIsolate(); | |
397 v8::Local<v8::Object> pNewObj = | |
398 FXJS_NewFxDynamicObj(pRuntime, NULL, -1); | |
399 PutObjectProperty(pNewObj, pObjData); | |
400 FXJS_PutObjectObject(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(), | |
401 pNewObj); | |
402 } break; | |
403 case JS_GLOBALDATA_TYPE_NULL: | |
404 FXJS_PutObjectNull(NULL, pObj, pObjData->sKey.UTF8Decode().c_str()); | |
405 break; | |
406 } | |
407 } | |
408 } | |
409 | |
410 void JSGlobalAlternate::DestroyGlobalPersisitentVariables() { | |
411 for (const auto& pair : m_mapGlobal) { | |
412 delete pair.second; | |
413 } | |
414 m_mapGlobal.clear(); | |
415 } | |
416 | |
417 FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname, | |
418 int nType, | |
419 double dData, | |
420 bool bData, | |
421 const CFX_ByteString& sData, | |
422 v8::Local<v8::Object> pData, | |
423 bool bDefaultPersistent) { | |
424 if (!propname) | |
425 return FALSE; | |
426 | |
427 auto it = m_mapGlobal.find(propname); | |
428 if (it != m_mapGlobal.end()) { | |
429 JSGlobalData* pTemp = it->second; | |
430 if (pTemp->bDeleted || pTemp->nType != nType) { | |
431 pTemp->dData = 0; | |
432 pTemp->bData = 0; | |
433 pTemp->sData = ""; | |
434 pTemp->nType = nType; | |
435 } | |
436 | |
437 pTemp->bDeleted = FALSE; | |
438 switch (nType) { | |
439 case JS_GLOBALDATA_TYPE_NUMBER: { | |
440 pTemp->dData = dData; | |
441 } break; | |
442 case JS_GLOBALDATA_TYPE_BOOLEAN: { | |
443 pTemp->bData = bData; | |
444 } break; | |
445 case JS_GLOBALDATA_TYPE_STRING: { | |
446 pTemp->sData = sData; | |
447 } break; | |
448 case JS_GLOBALDATA_TYPE_OBJECT: { | |
449 pTemp->pData.Reset(pData->GetIsolate(), pData); | |
450 } break; | |
451 case JS_GLOBALDATA_TYPE_NULL: | |
452 break; | |
453 default: | |
454 return FALSE; | |
455 } | |
456 return TRUE; | |
457 } | |
458 | |
459 JSGlobalData* pNewData = NULL; | |
460 | |
461 switch (nType) { | |
462 case JS_GLOBALDATA_TYPE_NUMBER: { | |
463 pNewData = new JSGlobalData; | |
464 pNewData->nType = JS_GLOBALDATA_TYPE_NUMBER; | |
465 pNewData->dData = dData; | |
466 pNewData->bPersistent = bDefaultPersistent; | |
467 } break; | |
468 case JS_GLOBALDATA_TYPE_BOOLEAN: { | |
469 pNewData = new JSGlobalData; | |
470 pNewData->nType = JS_GLOBALDATA_TYPE_BOOLEAN; | |
471 pNewData->bData = bData; | |
472 pNewData->bPersistent = bDefaultPersistent; | |
473 } break; | |
474 case JS_GLOBALDATA_TYPE_STRING: { | |
475 pNewData = new JSGlobalData; | |
476 pNewData->nType = JS_GLOBALDATA_TYPE_STRING; | |
477 pNewData->sData = sData; | |
478 pNewData->bPersistent = bDefaultPersistent; | |
479 } break; | |
480 case JS_GLOBALDATA_TYPE_OBJECT: { | |
481 pNewData = new JSGlobalData; | |
482 pNewData->nType = JS_GLOBALDATA_TYPE_OBJECT; | |
483 pNewData->pData.Reset(pData->GetIsolate(), pData); | |
484 pNewData->bPersistent = bDefaultPersistent; | |
485 } break; | |
486 case JS_GLOBALDATA_TYPE_NULL: { | |
487 pNewData = new JSGlobalData; | |
488 pNewData->nType = JS_GLOBALDATA_TYPE_NULL; | |
489 pNewData->bPersistent = bDefaultPersistent; | |
490 } break; | |
491 default: | |
492 return FALSE; | |
493 } | |
494 | |
495 m_mapGlobal[propname] = pNewData; | |
496 return TRUE; | |
497 } | |
498 | |
499 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p) { | |
500 const unsigned int nHash = JS_CalcHash(FXJS_GetTypeof(p)); | |
501 | |
502 if (nHash == JSCONST_nUndefHash) | |
503 return CJS_Value::VT_undefined; | |
504 if (nHash == JSCONST_nNullHash) | |
505 return CJS_Value::VT_null; | |
506 if (nHash == JSCONST_nStringHash) | |
507 return CJS_Value::VT_string; | |
508 if (nHash == JSCONST_nNumberHash) | |
509 return CJS_Value::VT_number; | |
510 if (nHash == JSCONST_nBoolHash) | |
511 return CJS_Value::VT_boolean; | |
512 if (nHash == JSCONST_nDateHash) | |
513 return CJS_Value::VT_date; | |
514 if (nHash == JSCONST_nObjectHash) | |
515 return CJS_Value::VT_object; | |
516 if (nHash == JSCONST_nFXobjHash) | |
517 return CJS_Value::VT_fxobject; | |
518 | |
519 return CJS_Value::VT_unknown; | |
520 } | |
OLD | NEW |