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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ | 182 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ |
183 static void method_name##_static( \ | 183 static void method_name##_static( \ |
184 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 184 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
185 JSMethod<class_alternate, &class_alternate::method_name>( \ | 185 JSMethod<class_alternate, &class_alternate::method_name>( \ |
186 #method_name, #class_name, info); \ | 186 #method_name, #class_name, info); \ |
187 } | 187 } |
188 | 188 |
189 /* ===================================== JS CLASS | 189 /* ===================================== JS CLASS |
190 * =============================================== */ | 190 * =============================================== */ |
191 | 191 |
192 #define DECLARE_JS_CLASS(js_class_name) \ | 192 #define DECLARE_JS_CLASS(js_class_name) \ |
193 static void JSConstructor(IFXJS_Context* cc, JSFXObject obj, \ | 193 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ |
194 JSFXObject global); \ | 194 v8::Local<v8::Object> global); \ |
195 static void JSDestructor(JSFXObject obj); \ | 195 static void JSDestructor(v8::Local<v8::Object> obj); \ |
196 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType); \ | 196 static int Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ |
197 static JSConstSpec JS_Class_Consts[]; \ | 197 static JSConstSpec JS_Class_Consts[]; \ |
198 static JSPropertySpec JS_Class_Properties[]; \ | 198 static JSPropertySpec JS_Class_Properties[]; \ |
199 static JSMethodSpec JS_Class_Methods[]; \ | 199 static JSMethodSpec JS_Class_Methods[]; \ |
200 static const wchar_t* m_pClassName | 200 static const wchar_t* m_pClassName |
201 | 201 |
202 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ | 202 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ |
203 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | 203 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ |
204 void js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj, \ | 204 void js_class_name::JSConstructor(IFXJS_Context* cc, \ |
205 JSFXObject global) { \ | 205 v8::Local<v8::Object> obj, \ |
| 206 v8::Local<v8::Object> global) { \ |
206 CJS_Object* pObj = new js_class_name(obj); \ | 207 CJS_Object* pObj = new js_class_name(obj); \ |
207 pObj->SetEmbedObject(new class_alternate(pObj)); \ | 208 pObj->SetEmbedObject(new class_alternate(pObj)); \ |
208 JS_SetPrivate(NULL, obj, (void*)pObj); \ | 209 JS_SetPrivate(NULL, obj, (void*)pObj); \ |
209 pObj->InitInstance(cc); \ | 210 pObj->InitInstance(cc); \ |
210 } \ | 211 } \ |
211 \ | 212 \ |
212 void js_class_name::JSDestructor(JSFXObject obj) { \ | 213 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ |
213 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ | 214 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ |
214 ASSERT(pObj != NULL); \ | 215 ASSERT(pObj != NULL); \ |
215 pObj->ExitInstance(); \ | 216 pObj->ExitInstance(); \ |
216 delete pObj; \ | 217 delete pObj; \ |
217 } \ | 218 } \ |
218 \ | 219 \ |
219 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType) { \ | 220 int js_class_name::Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType) { \ |
220 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, \ | 221 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ |
221 eObjType, JSConstructor, JSDestructor); \ | 222 eObjType, JSConstructor, JSDestructor); \ |
222 if (nObjDefnID >= 0) { \ | 223 if (nObjDefnID >= 0) { \ |
223 for (int j = 0, \ | 224 for (int j = 0, \ |
224 szj = sizeof(JS_Class_Properties) / sizeof(JSPropertySpec) - 1; \ | 225 szj = sizeof(JS_Class_Properties) / sizeof(JSPropertySpec) - 1; \ |
225 j < szj; j++) { \ | 226 j < szj; j++) { \ |
226 if (JS_DefineObjProperty(pRuntime, nObjDefnID, \ | 227 if (JS_DefineObjProperty(pIsolate, nObjDefnID, \ |
227 JS_Class_Properties[j].pName, \ | 228 JS_Class_Properties[j].pName, \ |
228 JS_Class_Properties[j].pPropGet, \ | 229 JS_Class_Properties[j].pPropGet, \ |
229 JS_Class_Properties[j].pPropPut) < 0) \ | 230 JS_Class_Properties[j].pPropPut) < 0) \ |
230 return -1; \ | 231 return -1; \ |
231 } \ | 232 } \ |
232 for (int k = 0, \ | 233 for (int k = 0, \ |
233 szk = sizeof(JS_Class_Methods) / sizeof(JSMethodSpec) - 1; \ | 234 szk = sizeof(JS_Class_Methods) / sizeof(JSMethodSpec) - 1; \ |
234 k < szk; k++) { \ | 235 k < szk; k++) { \ |
235 if (JS_DefineObjMethod(pRuntime, nObjDefnID, \ | 236 if (JS_DefineObjMethod(pIsolate, nObjDefnID, \ |
236 JS_Class_Methods[k].pName, \ | 237 JS_Class_Methods[k].pName, \ |
237 JS_Class_Methods[k].pMethodCall) < 0) \ | 238 JS_Class_Methods[k].pMethodCall) < 0) \ |
238 return -1; \ | 239 return -1; \ |
239 } \ | 240 } \ |
240 return nObjDefnID; \ | 241 return nObjDefnID; \ |
241 } \ | 242 } \ |
242 return -1; \ | 243 return -1; \ |
243 } | 244 } |
244 | 245 |
245 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ | 246 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ |
246 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) | 247 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) |
247 | 248 |
248 /* ======================================== CONST CLASS | 249 /* ======================================== CONST CLASS |
249 * ============================================ */ | 250 * ============================================ */ |
250 | 251 |
251 #define DECLARE_JS_CLASS_CONST() \ | 252 #define DECLARE_JS_CLASS_CONST() \ |
252 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType); \ | 253 static int Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ |
253 static JSConstSpec JS_Class_Consts[]; \ | 254 static JSConstSpec JS_Class_Consts[]; \ |
254 static const wchar_t* m_pClassName | 255 static const wchar_t* m_pClassName |
255 | 256 |
256 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ | 257 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ |
257 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | 258 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ |
258 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType) { \ | 259 int js_class_name::Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType) { \ |
259 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, \ | 260 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ |
260 eObjType, NULL, NULL); \ | 261 eObjType, NULL, NULL); \ |
261 if (nObjDefnID >= 0) { \ | 262 if (nObjDefnID >= 0) { \ |
262 for (int i = 0, sz = sizeof(JS_Class_Consts) / sizeof(JSConstSpec) - 1; \ | 263 for (int i = 0, sz = sizeof(JS_Class_Consts) / sizeof(JSConstSpec) - 1; \ |
263 i < sz; i++) { \ | 264 i < sz; i++) { \ |
264 if (JS_Class_Consts[i].t == 0) { \ | 265 if (JS_Class_Consts[i].t == 0) { \ |
265 if (JS_DefineObjConst( \ | 266 if (JS_DefineObjConst( \ |
266 pRuntime, nObjDefnID, JS_Class_Consts[i].pName, \ | 267 pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \ |
267 JS_NewNumber(pRuntime, JS_Class_Consts[i].number)) < 0) \ | 268 JS_NewNumber(pIsolate, JS_Class_Consts[i].number)) < 0) \ |
268 return -1; \ | 269 return -1; \ |
269 } else { \ | 270 } else { \ |
270 if (JS_DefineObjConst( \ | 271 if (JS_DefineObjConst( \ |
271 pRuntime, nObjDefnID, JS_Class_Consts[i].pName, \ | 272 pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \ |
272 JS_NewString(pRuntime, JS_Class_Consts[i].string)) < 0) \ | 273 JS_NewString(pIsolate, JS_Class_Consts[i].string)) < 0) \ |
273 return -1; \ | 274 return -1; \ |
274 } \ | 275 } \ |
275 } \ | 276 } \ |
276 return nObjDefnID; \ | 277 return nObjDefnID; \ |
277 } \ | 278 } \ |
278 return -1; \ | 279 return -1; \ |
279 } | 280 } |
280 | 281 |
281 /* ===================================== SPECIAL JS CLASS | 282 /* ===================================== SPECIAL JS CLASS |
282 * =============================================== */ | 283 * =============================================== */ |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 CFX_WideString propname = | 365 CFX_WideString propname = |
365 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 366 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
366 CFX_WideString sError; | 367 CFX_WideString sError; |
367 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { | 368 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { |
368 CFX_ByteString cbName; | 369 CFX_ByteString cbName; |
369 cbName.Format("%s.%s", class_name, "DelProperty"); | 370 cbName.Format("%s.%s", class_name, "DelProperty"); |
370 // Probably a missing call to JS_Error(). | 371 // Probably a missing call to JS_Error(). |
371 } | 372 } |
372 } | 373 } |
373 | 374 |
374 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ | 375 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ |
375 static void JSConstructor(IFXJS_Context* cc, JSFXObject obj, \ | 376 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ |
376 JSFXObject global); \ | 377 v8::Local<v8::Object> global); \ |
377 static void JSDestructor(JSFXObject obj); \ | 378 static void JSDestructor(v8::Local<v8::Object> obj); \ |
378 static JSConstSpec JS_Class_Consts[]; \ | 379 static JSConstSpec JS_Class_Consts[]; \ |
379 static JSPropertySpec JS_Class_Properties[]; \ | 380 static JSPropertySpec JS_Class_Properties[]; \ |
380 static JSMethodSpec JS_Class_Methods[]; \ | 381 static JSMethodSpec JS_Class_Methods[]; \ |
381 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType); \ | 382 static int Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ |
382 static const wchar_t* m_pClassName; \ | 383 static const wchar_t* m_pClassName; \ |
383 static void queryprop_##js_class_name##_static( \ | 384 static void queryprop_##js_class_name##_static( \ |
384 v8::Local<v8::String> property, \ | 385 v8::Local<v8::String> property, \ |
385 const v8::PropertyCallbackInfo<v8::Integer>& info); \ | 386 const v8::PropertyCallbackInfo<v8::Integer>& info); \ |
386 static void getprop_##js_class_name##_static( \ | 387 static void getprop_##js_class_name##_static( \ |
387 v8::Local<v8::String> property, \ | 388 v8::Local<v8::String> property, \ |
388 const v8::PropertyCallbackInfo<v8::Value>& info); \ | 389 const v8::PropertyCallbackInfo<v8::Value>& info); \ |
389 static void putprop_##js_class_name##_static( \ | 390 static void putprop_##js_class_name##_static( \ |
390 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | 391 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ |
391 const v8::PropertyCallbackInfo<v8::Value>& info); \ | 392 const v8::PropertyCallbackInfo<v8::Value>& info); \ |
392 static void delprop_##js_class_name##_static( \ | 393 static void delprop_##js_class_name##_static( \ |
393 v8::Local<v8::String> property, \ | 394 v8::Local<v8::String> property, \ |
394 const v8::PropertyCallbackInfo<v8::Boolean>& info) | 395 const v8::PropertyCallbackInfo<v8::Boolean>& info) |
395 | 396 |
396 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ | 397 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ |
397 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | 398 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ |
398 void js_class_name::queryprop_##js_class_name##_static( \ | 399 void js_class_name::queryprop_##js_class_name##_static( \ |
399 v8::Local<v8::String> property, \ | 400 v8::Local<v8::String> property, \ |
400 const v8::PropertyCallbackInfo<v8::Integer>& info) { \ | 401 const v8::PropertyCallbackInfo<v8::Integer>& info) { \ |
401 JSSpecialPropQuery<class_alternate>(#class_name, property, info); \ | 402 JSSpecialPropQuery<class_alternate>(#class_name, property, info); \ |
402 } \ | 403 } \ |
403 void js_class_name::getprop_##js_class_name##_static( \ | 404 void js_class_name::getprop_##js_class_name##_static( \ |
404 v8::Local<v8::String> property, \ | 405 v8::Local<v8::String> property, \ |
405 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | 406 const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
406 JSSpecialPropGet<class_alternate>(#class_name, property, info); \ | 407 JSSpecialPropGet<class_alternate>(#class_name, property, info); \ |
407 } \ | 408 } \ |
408 void js_class_name::putprop_##js_class_name##_static( \ | 409 void js_class_name::putprop_##js_class_name##_static( \ |
409 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | 410 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ |
410 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | 411 const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
411 JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \ | 412 JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \ |
412 } \ | 413 } \ |
413 void js_class_name::delprop_##js_class_name##_static( \ | 414 void js_class_name::delprop_##js_class_name##_static( \ |
414 v8::Local<v8::String> property, \ | 415 v8::Local<v8::String> property, \ |
415 const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ | 416 const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ |
416 JSSpecialPropDel<class_alternate>(#class_name, property, info); \ | 417 JSSpecialPropDel<class_alternate>(#class_name, property, info); \ |
417 } \ | 418 } \ |
418 void js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj, \ | 419 void js_class_name::JSConstructor(IFXJS_Context* cc, \ |
419 JSFXObject global) { \ | 420 v8::Local<v8::Object> obj, \ |
| 421 v8::Local<v8::Object> global) { \ |
420 CJS_Object* pObj = new js_class_name(obj); \ | 422 CJS_Object* pObj = new js_class_name(obj); \ |
421 pObj->SetEmbedObject(new class_alternate(pObj)); \ | 423 pObj->SetEmbedObject(new class_alternate(pObj)); \ |
422 JS_SetPrivate(NULL, obj, (void*)pObj); \ | 424 JS_SetPrivate(NULL, obj, (void*)pObj); \ |
423 pObj->InitInstance(cc); \ | 425 pObj->InitInstance(cc); \ |
424 } \ | 426 } \ |
425 \ | 427 \ |
426 void js_class_name::JSDestructor(JSFXObject obj) { \ | 428 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ |
427 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ | 429 js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj); \ |
428 ASSERT(pObj != NULL); \ | 430 ASSERT(pObj != NULL); \ |
429 pObj->ExitInstance(); \ | 431 pObj->ExitInstance(); \ |
430 delete pObj; \ | 432 delete pObj; \ |
431 } \ | 433 } \ |
432 \ | 434 \ |
433 int js_class_name::Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType) { \ | 435 int js_class_name::Init(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType) { \ |
434 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, \ | 436 int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \ |
435 eObjType, JSConstructor, JSDestructor); \ | 437 eObjType, JSConstructor, JSDestructor); \ |
436 \ | 438 \ |
437 if (nObjDefnID >= 0) { \ | 439 if (nObjDefnID >= 0) { \ |
438 for (int j = 0, \ | 440 for (int j = 0, \ |
439 szj = sizeof(JS_Class_Properties) / sizeof(JSPropertySpec) - 1; \ | 441 szj = sizeof(JS_Class_Properties) / sizeof(JSPropertySpec) - 1; \ |
440 j < szj; j++) { \ | 442 j < szj; j++) { \ |
441 if (JS_DefineObjProperty(pRuntime, nObjDefnID, \ | 443 if (JS_DefineObjProperty(pIsolate, nObjDefnID, \ |
442 JS_Class_Properties[j].pName, \ | 444 JS_Class_Properties[j].pName, \ |
443 JS_Class_Properties[j].pPropGet, \ | 445 JS_Class_Properties[j].pPropGet, \ |
444 JS_Class_Properties[j].pPropPut) < 0) \ | 446 JS_Class_Properties[j].pPropPut) < 0) \ |
445 return -1; \ | 447 return -1; \ |
446 } \ | 448 } \ |
447 \ | 449 \ |
448 for (int k = 0, \ | 450 for (int k = 0, \ |
449 szk = sizeof(JS_Class_Methods) / sizeof(JSMethodSpec) - 1; \ | 451 szk = sizeof(JS_Class_Methods) / sizeof(JSMethodSpec) - 1; \ |
450 k < szk; k++) { \ | 452 k < szk; k++) { \ |
451 if (JS_DefineObjMethod(pRuntime, nObjDefnID, \ | 453 if (JS_DefineObjMethod(pIsolate, nObjDefnID, \ |
452 JS_Class_Methods[k].pName, \ | 454 JS_Class_Methods[k].pName, \ |
453 JS_Class_Methods[k].pMethodCall) < 0) \ | 455 JS_Class_Methods[k].pMethodCall) < 0) \ |
454 return -1; \ | 456 return -1; \ |
455 } \ | 457 } \ |
456 if (JS_DefineObjAllProperties( \ | 458 if (JS_DefineObjAllProperties( \ |
457 pRuntime, nObjDefnID, \ | 459 pIsolate, nObjDefnID, \ |
458 js_class_name::queryprop_##js_class_name##_static, \ | 460 js_class_name::queryprop_##js_class_name##_static, \ |
459 js_class_name::getprop_##js_class_name##_static, \ | 461 js_class_name::getprop_##js_class_name##_static, \ |
460 js_class_name::putprop_##js_class_name##_static, \ | 462 js_class_name::putprop_##js_class_name##_static, \ |
461 js_class_name::delprop_##js_class_name##_static) < 0) \ | 463 js_class_name::delprop_##js_class_name##_static) < 0) \ |
462 return -1; \ | 464 return -1; \ |
463 \ | 465 \ |
464 return nObjDefnID; \ | 466 return nObjDefnID; \ |
465 } \ | 467 } \ |
466 \ | 468 \ |
467 return -1; \ | 469 return -1; \ |
(...skipping 28 matching lines...) Expand all Loading... |
496 } | 498 } |
497 | 499 |
498 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 500 #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
499 static void fun_name##_static( \ | 501 static void fun_name##_static( \ |
500 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 502 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
501 JSGlobalFunc<fun_name>(#fun_name, info); \ | 503 JSGlobalFunc<fun_name>(#fun_name, info); \ |
502 } | 504 } |
503 | 505 |
504 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ | 506 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ |
505 static JSMethodSpec global_methods[]; \ | 507 static JSMethodSpec global_methods[]; \ |
506 static int Init(IJS_Runtime* pRuntime) | 508 static int Init(v8::Isolate* pIsolate) |
507 | 509 |
508 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 510 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
509 JSMethodSpec js_class_name::global_methods[] = { | 511 JSMethodSpec js_class_name::global_methods[] = { |
510 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ | 512 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ |
511 JS_STATIC_METHOD_ENTRY(method_name) | 513 JS_STATIC_METHOD_ENTRY(method_name) |
512 | 514 |
513 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() | 515 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() |
514 | 516 |
515 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 517 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
516 int js_class_name::Init(IJS_Runtime* pRuntime) { \ | 518 int js_class_name::Init(v8::Isolate* pIsolate) { \ |
517 for (int i = 0, sz = sizeof(js_class_name::global_methods) / \ | 519 for (int i = 0, sz = sizeof(js_class_name::global_methods) / \ |
518 sizeof(JSMethodSpec) - \ | 520 sizeof(JSMethodSpec) - \ |
519 1; \ | 521 1; \ |
520 i < sz; i++) { \ | 522 i < sz; i++) { \ |
521 if (JS_DefineGlobalMethod( \ | 523 if (JS_DefineGlobalMethod( \ |
522 pRuntime, js_class_name::global_methods[i].pName, \ | 524 pIsolate, js_class_name::global_methods[i].pName, \ |
523 js_class_name::global_methods[i].pMethodCall) < 0) \ | 525 js_class_name::global_methods[i].pMethodCall) < 0) \ |
524 return -1; \ | 526 return -1; \ |
525 } \ | 527 } \ |
526 return 0; \ | 528 return 0; \ |
527 } | 529 } |
528 | 530 |
529 /* ======================================== GLOBAL CONSTS | 531 /* ======================================== GLOBAL CONSTS |
530 * ============================================ */ | 532 * ============================================ */ |
531 #define DEFINE_GLOBAL_CONST(pRuntime, const_name, const_value) \ | 533 #define DEFINE_GLOBAL_CONST(pIsolate, const_name, const_value) \ |
532 if (JS_DefineGlobalConst( \ | 534 if (JS_DefineGlobalConst( \ |
533 pRuntime, JS_WIDESTRING(const_name), \ | 535 pIsolate, JS_WIDESTRING(const_name), \ |
534 JS_NewString(pRuntime, JS_WIDESTRING(const_value)))) \ | 536 JS_NewString(pIsolate, JS_WIDESTRING(const_value)))) \ |
535 return -1 | 537 return -1 |
536 | 538 |
537 /* ======================================== GLOBAL ARRAYS | 539 /* ======================================== GLOBAL ARRAYS |
538 * ============================================ */ | 540 * ============================================ */ |
539 | 541 |
540 #define DEFINE_GLOBAL_ARRAY(pRuntime) \ | 542 #define DEFINE_GLOBAL_ARRAY(pIsolate) \ |
541 int size = FX_ArraySize(ArrayContent); \ | 543 int size = FX_ArraySize(ArrayContent); \ |
542 \ | 544 \ |
543 CJS_Array array(pRuntime); \ | 545 CJS_Array array(pIsolate); \ |
544 for (int i = 0; i < size; i++) \ | 546 for (int i = 0; i < size; i++) \ |
545 array.SetElement(i, CJS_Value(pRuntime, ArrayContent[i])); \ | 547 array.SetElement(i, CJS_Value(pIsolate, ArrayContent[i])); \ |
546 \ | 548 \ |
547 CJS_PropValue prop(pRuntime); \ | 549 CJS_PropValue prop(pIsolate); \ |
548 prop << array; \ | 550 prop << array; \ |
549 if (JS_DefineGlobalConst(pRuntime, (const wchar_t*)ArrayName, \ | 551 if (JS_DefineGlobalConst(pIsolate, (const wchar_t*)ArrayName, \ |
550 prop.ToV8Value()) < 0) \ | 552 prop.ToV8Value()) < 0) \ |
551 return -1 | 553 return -1 |
552 | 554 |
553 /* ============================================================ */ | 555 /* ============================================================ */ |
554 | 556 |
555 #define VALUE_NAME_STRING L"string" | 557 #define VALUE_NAME_STRING L"string" |
556 #define VALUE_NAME_NUMBER L"number" | 558 #define VALUE_NAME_NUMBER L"number" |
557 #define VALUE_NAME_BOOLEAN L"boolean" | 559 #define VALUE_NAME_BOOLEAN L"boolean" |
558 #define VALUE_NAME_DATE L"date" | 560 #define VALUE_NAME_DATE L"date" |
559 #define VALUE_NAME_OBJECT L"object" | 561 #define VALUE_NAME_OBJECT L"object" |
560 #define VALUE_NAME_FXOBJ L"fxobj" | 562 #define VALUE_NAME_FXOBJ L"fxobj" |
561 #define VALUE_NAME_NULL L"null" | 563 #define VALUE_NAME_NULL L"null" |
562 #define VALUE_NAME_UNDEFINED L"undefined" | 564 #define VALUE_NAME_UNDEFINED L"undefined" |
563 | 565 |
564 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); | 566 FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p); |
565 | 567 |
566 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | 568 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ |
OLD | NEW |