OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | 7 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ |
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ |
9 | 9 |
10 #include "../jsapi/fxjs_v8.h" | 10 #include "../jsapi/fxjs_v8.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ | 169 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ |
170 static void method_name##_static( \ | 170 static void method_name##_static( \ |
171 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 171 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
172 JSMethod<class_alternate, &class_alternate::method_name>( \ | 172 JSMethod<class_alternate, &class_alternate::method_name>( \ |
173 #method_name, #class_name, info); \ | 173 #method_name, #class_name, info); \ |
174 } | 174 } |
175 | 175 |
176 /* ===================================== JS CLASS | 176 /* ===================================== JS CLASS |
177 * =============================================== */ | 177 * =============================================== */ |
178 | 178 |
179 #define DECLARE_JS_CLASS(js_class_name) \ | 179 #define DECLARE_JS_CLASS(js_class_name) \ |
180 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ | 180 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ |
181 v8::Local<v8::Object> global); \ | 181 v8::Local<v8::Object> global); \ |
182 static void JSDestructor(v8::Local<v8::Object> obj); \ | 182 static void JSDestructor(v8::Local<v8::Object> obj); \ |
183 static int Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | 183 static int DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ |
184 static JSConstSpec JS_Class_Consts[]; \ | 184 static JSConstSpec JS_Class_Consts[]; \ |
185 static JSPropertySpec JS_Class_Properties[]; \ | 185 static JSPropertySpec JS_Class_Properties[]; \ |
186 static JSMethodSpec JS_Class_Methods[]; \ | 186 static JSMethodSpec JS_Class_Methods[]; \ |
187 static const wchar_t* m_pClassName | 187 static const wchar_t* m_pClassName |
188 | 188 |
189 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ | 189 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ |
190 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | 190 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ |
191 void js_class_name::JSConstructor(IFXJS_Context* cc, \ | 191 void js_class_name::JSConstructor(IFXJS_Context* cc, \ |
192 v8::Local<v8::Object> obj, \ | 192 v8::Local<v8::Object> obj, \ |
193 v8::Local<v8::Object> global) { \ | 193 v8::Local<v8::Object> global) { \ |
194 CJS_Object* pObj = new js_class_name(obj); \ | 194 CJS_Object* pObj = new js_class_name(obj); \ |
195 pObj->SetEmbedObject(new class_alternate(pObj)); \ | 195 pObj->SetEmbedObject(new class_alternate(pObj)); \ |
196 JS_SetPrivate(NULL, obj, (void*)pObj); \ | 196 JS_SetPrivate(NULL, obj, (void*)pObj); \ |
197 pObj->InitInstance(cc); \ | 197 pObj->InitInstance(cc); \ |
198 } \ | 198 } \ |
199 \ | 199 \ |
200 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ | 200 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ |
201 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ | 201 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ |
202 ASSERT(pObj != NULL); \ | 202 pObj->ExitInstance(); \ |
203 pObj->ExitInstance(); \ | 203 delete pObj; \ |
204 delete pObj; \ | 204 } \ |
205 } \ | 205 \ |
206 \ | 206 int js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
207 int js_class_name::Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType) { \ | 207 FXJSOBJTYPE eObjType) { \ |
208 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | 208 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ |
209 eObjType, JSConstructor, JSDestructor); \ | 209 eObjType, JSConstructor, JSDestructor); \ |
210 if (nObjDefnID >= 0) { \ | 210 if (nObjDefnID < 0) \ |
211 for (int j = 0, \ | 211 return -1; \ |
212 szj = sizeof(JS_Class_Properties) / sizeof(JSPropertySpec) - 1; \ | 212 for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ |
213 j < szj; j++) { \ | 213 if (JS_DefineObjProperty(pIsolate, nObjDefnID, \ |
214 if (JS_DefineObjProperty(pIsolate, nObjDefnID, \ | 214 JS_Class_Properties[i].pName, \ |
215 JS_Class_Properties[j].pName, \ | 215 JS_Class_Properties[i].pPropGet, \ |
216 JS_Class_Properties[j].pPropGet, \ | 216 JS_Class_Properties[i].pPropPut) < 0) \ |
217 JS_Class_Properties[j].pPropPut) < 0) \ | 217 return -1; \ |
218 return -1; \ | 218 } \ |
219 } \ | 219 for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ |
220 for (int k = 0, \ | 220 if (JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \ |
221 szk = sizeof(JS_Class_Methods) / sizeof(JSMethodSpec) - 1; \ | 221 JS_Class_Methods[i].pMethodCall) < 0) \ |
222 k < szk; k++) { \ | 222 return -1; \ |
223 if (JS_DefineObjMethod(pIsolate, nObjDefnID, \ | 223 } \ |
224 JS_Class_Methods[k].pName, \ | 224 return nObjDefnID; \ |
225 JS_Class_Methods[k].pMethodCall) < 0) \ | |
226 return -1; \ | |
227 } \ | |
228 return nObjDefnID; \ | |
229 } \ | |
230 return -1; \ | |
231 } | 225 } |
232 | 226 |
233 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ | 227 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ |
234 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) | 228 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) |
235 | 229 |
236 /* ======================================== CONST CLASS | 230 /* ======================================== CONST CLASS |
237 * ============================================ */ | 231 * ============================================ */ |
238 | 232 |
239 #define DECLARE_JS_CLASS_CONST() \ | 233 #define DECLARE_JS_CLASS_CONST() \ |
240 static int Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | 234 static int DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ |
241 static JSConstSpec JS_Class_Consts[]; \ | 235 static JSConstSpec JS_Class_Consts[]; \ |
242 static const wchar_t* m_pClassName | 236 static const wchar_t* m_pClassName |
243 | 237 |
244 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ | 238 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ |
245 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | 239 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ |
246 int js_class_name::Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType) { \ | 240 int js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 241 FXJSOBJTYPE eObjType) { \ |
247 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | 242 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ |
248 eObjType, NULL, NULL); \ | 243 eObjType, NULL, NULL); \ |
249 if (nObjDefnID >= 0) { \ | 244 if (nObjDefnID >= 0) { \ |
250 for (int i = 0, sz = sizeof(JS_Class_Consts) / sizeof(JSConstSpec) - 1; \ | 245 for (int i = 0, sz = sizeof(JS_Class_Consts) / sizeof(JSConstSpec) - 1; \ |
251 i < sz; i++) { \ | 246 i < sz; i++) { \ |
252 if (JS_Class_Consts[i].t == 0) { \ | 247 if (JS_Class_Consts[i].t == 0) { \ |
253 if (JS_DefineObjConst( \ | 248 if (JS_DefineObjConst( \ |
254 pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \ | 249 pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \ |
255 JS_NewNumber(pIsolate, JS_Class_Consts[i].number)) < 0) \ | 250 JS_NewNumber(pIsolate, JS_Class_Consts[i].number)) < 0) \ |
256 return -1; \ | 251 return -1; \ |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 CFX_WideString propname = | 341 CFX_WideString propname = |
347 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 342 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
348 CFX_WideString sError; | 343 CFX_WideString sError; |
349 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { | 344 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { |
350 CFX_ByteString cbName; | 345 CFX_ByteString cbName; |
351 cbName.Format("%s.%s", class_name, "DelProperty"); | 346 cbName.Format("%s.%s", class_name, "DelProperty"); |
352 // Probably a missing call to JS_Error(). | 347 // Probably a missing call to JS_Error(). |
353 } | 348 } |
354 } | 349 } |
355 | 350 |
356 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ | 351 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ |
357 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ | 352 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ |
358 v8::Local<v8::Object> global); \ | 353 v8::Local<v8::Object> global); \ |
359 static void JSDestructor(v8::Local<v8::Object> obj); \ | 354 static void JSDestructor(v8::Local<v8::Object> obj); \ |
360 static JSConstSpec JS_Class_Consts[]; \ | 355 static JSConstSpec JS_Class_Consts[]; \ |
361 static JSPropertySpec JS_Class_Properties[]; \ | 356 static JSPropertySpec JS_Class_Properties[]; \ |
362 static JSMethodSpec JS_Class_Methods[]; \ | 357 static JSMethodSpec JS_Class_Methods[]; \ |
363 static int Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | 358 static int DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ |
364 static const wchar_t* m_pClassName; \ | 359 static const wchar_t* m_pClassName; \ |
365 static void queryprop_##js_class_name##_static( \ | 360 static void queryprop_##js_class_name##_static( \ |
366 v8::Local<v8::String> property, \ | 361 v8::Local<v8::String> property, \ |
367 const v8::PropertyCallbackInfo<v8::Integer>& info); \ | 362 const v8::PropertyCallbackInfo<v8::Integer>& info); \ |
368 static void getprop_##js_class_name##_static( \ | 363 static void getprop_##js_class_name##_static( \ |
369 v8::Local<v8::String> property, \ | 364 v8::Local<v8::String> property, \ |
370 const v8::PropertyCallbackInfo<v8::Value>& info); \ | 365 const v8::PropertyCallbackInfo<v8::Value>& info); \ |
371 static void putprop_##js_class_name##_static( \ | 366 static void putprop_##js_class_name##_static( \ |
372 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | 367 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ |
373 const v8::PropertyCallbackInfo<v8::Value>& info); \ | 368 const v8::PropertyCallbackInfo<v8::Value>& info); \ |
374 static void delprop_##js_class_name##_static( \ | 369 static void delprop_##js_class_name##_static( \ |
375 v8::Local<v8::String> property, \ | 370 v8::Local<v8::String> property, \ |
376 const v8::PropertyCallbackInfo<v8::Boolean>& info) | 371 const v8::PropertyCallbackInfo<v8::Boolean>& info) |
377 | 372 |
378 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ | 373 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ |
379 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | 374 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ |
380 void js_class_name::queryprop_##js_class_name##_static( \ | 375 void js_class_name::queryprop_##js_class_name##_static( \ |
381 v8::Local<v8::String> property, \ | 376 v8::Local<v8::String> property, \ |
382 const v8::PropertyCallbackInfo<v8::Integer>& info) { \ | 377 const v8::PropertyCallbackInfo<v8::Integer>& info) { \ |
383 JSSpecialPropQuery<class_alternate>(#class_name, property, info); \ | 378 JSSpecialPropQuery<class_alternate>(#class_name, property, info); \ |
384 } \ | 379 } \ |
385 void js_class_name::getprop_##js_class_name##_static( \ | 380 void js_class_name::getprop_##js_class_name##_static( \ |
(...skipping 20 matching lines...) Expand all Loading... |
406 pObj->InitInstance(cc); \ | 401 pObj->InitInstance(cc); \ |
407 } \ | 402 } \ |
408 \ | 403 \ |
409 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ | 404 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ |
410 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ | 405 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ |
411 ASSERT(pObj != NULL); \ | 406 ASSERT(pObj != NULL); \ |
412 pObj->ExitInstance(); \ | 407 pObj->ExitInstance(); \ |
413 delete pObj; \ | 408 delete pObj; \ |
414 } \ | 409 } \ |
415 \ | 410 \ |
416 int js_class_name::Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType) { \ | 411 int js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 412 FXJSOBJTYPE eObjType) { \ |
417 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | 413 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ |
418 eObjType, JSConstructor, JSDestructor); \ | 414 eObjType, JSConstructor, JSDestructor); \ |
419 \ | 415 \ |
420 if (nObjDefnID >= 0) { \ | 416 if (nObjDefnID < 0) \ |
421 for (int j = 0, \ | 417 return -1; \ |
422 szj = sizeof(JS_Class_Properties) / sizeof(JSPropertySpec) - 1; \ | 418 for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ |
423 j < szj; j++) { \ | 419 if (JS_DefineObjProperty(pIsolate, nObjDefnID, \ |
424 if (JS_DefineObjProperty(pIsolate, nObjDefnID, \ | 420 JS_Class_Properties[i].pName, \ |
425 JS_Class_Properties[j].pName, \ | 421 JS_Class_Properties[i].pPropGet, \ |
426 JS_Class_Properties[j].pPropGet, \ | 422 JS_Class_Properties[i].pPropPut) < 0) \ |
427 JS_Class_Properties[j].pPropPut) < 0) \ | |
428 return -1; \ | |
429 } \ | |
430 \ | |
431 for (int k = 0, \ | |
432 szk = sizeof(JS_Class_Methods) / sizeof(JSMethodSpec) - 1; \ | |
433 k < szk; k++) { \ | |
434 if (JS_DefineObjMethod(pIsolate, nObjDefnID, \ | |
435 JS_Class_Methods[k].pName, \ | |
436 JS_Class_Methods[k].pMethodCall) < 0) \ | |
437 return -1; \ | |
438 } \ | |
439 if (JS_DefineObjAllProperties( \ | |
440 pIsolate, nObjDefnID, \ | |
441 js_class_name::queryprop_##js_class_name##_static, \ | |
442 js_class_name::getprop_##js_class_name##_static, \ | |
443 js_class_name::putprop_##js_class_name##_static, \ | |
444 js_class_name::delprop_##js_class_name##_static) < 0) \ | |
445 return -1; \ | 423 return -1; \ |
446 \ | |
447 return nObjDefnID; \ | |
448 } \ | 424 } \ |
449 \ | 425 \ |
450 return -1; \ | 426 for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ |
| 427 if (JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \ |
| 428 JS_Class_Methods[i].pMethodCall) < 0) \ |
| 429 return -1; \ |
| 430 } \ |
| 431 if (JS_DefineObjAllProperties( \ |
| 432 pIsolate, nObjDefnID, \ |
| 433 js_class_name::queryprop_##js_class_name##_static, \ |
| 434 js_class_name::getprop_##js_class_name##_static, \ |
| 435 js_class_name::putprop_##js_class_name##_static, \ |
| 436 js_class_name::delprop_##js_class_name##_static) < 0) \ |
| 437 return -1; \ |
| 438 return nObjDefnID; \ |
451 } | 439 } |
452 | 440 |
453 /* ======================================== GLOBAL METHODS | 441 /* ======================================== GLOBAL METHODS |
454 * ============================================ */ | 442 * ============================================ */ |
455 | 443 |
456 template <FX_BOOL ( | 444 template <FX_BOOL ( |
457 *F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)> | 445 *F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)> |
458 void JSGlobalFunc(const char* func_name_string, | 446 void JSGlobalFunc(const char* func_name_string, |
459 const v8::FunctionCallbackInfo<v8::Value>& info) { | 447 const v8::FunctionCallbackInfo<v8::Value>& info) { |
460 v8::Isolate* isolate = info.GetIsolate(); | 448 v8::Isolate* isolate = info.GetIsolate(); |
(...skipping 13 matching lines...) Expand all Loading... |
474 } | 462 } |
475 | 463 |
476 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 464 #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
477 static void fun_name##_static( \ | 465 static void fun_name##_static( \ |
478 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 466 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
479 JSGlobalFunc<fun_name>(#fun_name, info); \ | 467 JSGlobalFunc<fun_name>(#fun_name, info); \ |
480 } | 468 } |
481 | 469 |
482 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ | 470 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ |
483 static JSMethodSpec global_methods[]; \ | 471 static JSMethodSpec global_methods[]; \ |
484 static int Init(v8::Isolate* pIsolate) | 472 static int DefineJSObjects(v8::Isolate* pIsolate) |
485 | 473 |
486 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 474 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
487 JSMethodSpec js_class_name::global_methods[] = { | 475 JSMethodSpec js_class_name::global_methods[] = { |
488 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ | 476 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ |
489 JS_STATIC_METHOD_ENTRY(method_name) | 477 JS_STATIC_METHOD_ENTRY(method_name) |
490 | 478 |
491 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() | 479 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() |
492 | 480 |
493 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 481 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
494 int js_class_name::Init(v8::Isolate* pIsolate) { \ | 482 int js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \ |
495 for (int i = 0, sz = sizeof(js_class_name::global_methods) / \ | 483 for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ |
496 sizeof(JSMethodSpec) - \ | |
497 1; \ | |
498 i < sz; i++) { \ | |
499 if (JS_DefineGlobalMethod( \ | 484 if (JS_DefineGlobalMethod( \ |
500 pIsolate, js_class_name::global_methods[i].pName, \ | 485 pIsolate, js_class_name::global_methods[i].pName, \ |
501 js_class_name::global_methods[i].pMethodCall) < 0) \ | 486 js_class_name::global_methods[i].pMethodCall) < 0) \ |
502 return -1; \ | 487 return -1; \ |
503 } \ | 488 } \ |
504 return 0; \ | 489 return 0; \ |
505 } | 490 } |
506 | 491 |
507 /* ======================================== GLOBAL CONSTS | |
508 * ============================================ */ | |
509 #define DEFINE_GLOBAL_CONST(pIsolate, const_name, const_value) \ | |
510 if (JS_DefineGlobalConst( \ | |
511 pIsolate, JS_WIDESTRING(const_name), \ | |
512 JS_NewString(pIsolate, JS_WIDESTRING(const_value)))) \ | |
513 return -1 | |
514 | |
515 /* ======================================== GLOBAL ARRAYS | |
516 * ============================================ */ | |
517 | |
518 #define DEFINE_GLOBAL_ARRAY(pIsolate) \ | |
519 int size = FX_ArraySize(ArrayContent); \ | |
520 \ | |
521 CJS_Array array(pIsolate); \ | |
522 for (int i = 0; i < size; i++) \ | |
523 array.SetElement(i, CJS_Value(pIsolate, ArrayContent[i])); \ | |
524 \ | |
525 CJS_PropValue prop(pIsolate); \ | |
526 prop << array; \ | |
527 if (JS_DefineGlobalConst(pIsolate, (const wchar_t*)ArrayName, \ | |
528 prop.ToV8Value()) < 0) \ | |
529 return -1 | |
530 | |
531 /* ============================================================ */ | 492 /* ============================================================ */ |
532 | 493 |
533 #define VALUE_NAME_STRING L"string" | 494 #define VALUE_NAME_STRING L"string" |
534 #define VALUE_NAME_NUMBER L"number" | 495 #define VALUE_NAME_NUMBER L"number" |
535 #define VALUE_NAME_BOOLEAN L"boolean" | 496 #define VALUE_NAME_BOOLEAN L"boolean" |
536 #define VALUE_NAME_DATE L"date" | 497 #define VALUE_NAME_DATE L"date" |
537 #define VALUE_NAME_OBJECT L"object" | 498 #define VALUE_NAME_OBJECT L"object" |
538 #define VALUE_NAME_FXOBJ L"fxobj" | 499 #define VALUE_NAME_FXOBJ L"fxobj" |
539 #define VALUE_NAME_NULL L"null" | 500 #define VALUE_NAME_NULL L"null" |
540 #define VALUE_NAME_UNDEFINED L"undefined" | 501 #define VALUE_NAME_UNDEFINED L"undefined" |
541 | 502 |
542 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); | 503 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); |
543 | 504 |
544 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | 505 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ |
OLD | NEW |