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 #include "../../include/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
9 #include "../../include/javascript/JS_EventHandler.h" | 9 #include "../../include/javascript/JS_EventHandler.h" |
10 #include "../../include/javascript/JS_Runtime.h" | 10 #include "../../include/javascript/JS_Runtime.h" |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 { | 333 { |
334 return v8::Local<v8::Context>::New(m_isolate, m_context); | 334 return v8::Local<v8::Context>::New(m_isolate, m_context); |
335 } | 335 } |
336 | 336 |
337 CFX_WideString ChangeObjName(const CFX_WideString& str) | 337 CFX_WideString ChangeObjName(const CFX_WideString& str) |
338 { | 338 { |
339 CFX_WideString sRet = str; | 339 CFX_WideString sRet = str; |
340 sRet.Replace(L"_", L"."); | 340 sRet.Replace(L"_", L"."); |
341 return sRet; | 341 return sRet; |
342 } | 342 } |
343 | |
344 void CJS_Runtime::GetObjectNames(CFX_WideStringArray& array) | |
345 { | |
346 array.RemoveAll(); | |
347 | |
348 array.Add(CJS_Border::m_pClassName); | |
349 array.Add(CJS_Display::m_pClassName); | |
350 array.Add(CJS_Font::m_pClassName); | |
351 array.Add(CJS_Highlight::m_pClassName); | |
352 array.Add(CJS_Position::m_pClassName); | |
353 array.Add(CJS_ScaleHow::m_pClassName); | |
354 array.Add(CJS_ScaleWhen::m_pClassName); | |
355 array.Add(CJS_Style::m_pClassName); | |
356 array.Add(CJS_Zoomtype::m_pClassName); | |
357 | |
358 array.Add(CJS_App::m_pClassName); | |
359 array.Add(L"this"); | |
360 array.Add(CJS_Event::m_pClassName); | |
361 | |
362 array.Add(CJS_Global::m_pClassName); | |
363 array.Add(CJS_Util::m_pClassName); | |
364 } | |
365 | |
366 void CJS_Runtime::GetObjectConsts(const CFX_WideString& sObjName, CFX_WideString
Array& array) | |
367 { | |
368 JSConstSpec* pConsts = NULL; | |
369 int nSize = 0; | |
370 | |
371 if (sObjName == CJS_Border::m_pClassName) | |
372 CJS_Border::GetConsts(pConsts, nSize); | |
373 else if (sObjName == CJS_Display::m_pClassName) | |
374 CJS_Display::GetConsts(pConsts, nSize); | |
375 else if (sObjName == CJS_Font::m_pClassName) | |
376 CJS_Font::GetConsts(pConsts, nSize); | |
377 else if (sObjName == CJS_Highlight::m_pClassName) | |
378 CJS_Highlight::GetConsts(pConsts, nSize); | |
379 else if (sObjName == CJS_Position::m_pClassName) | |
380 CJS_Position::GetConsts(pConsts, nSize); | |
381 else if (sObjName == CJS_ScaleHow::m_pClassName) | |
382 CJS_ScaleHow::GetConsts(pConsts, nSize); | |
383 else if (sObjName == CJS_ScaleWhen::m_pClassName) | |
384 CJS_ScaleWhen::GetConsts(pConsts, nSize); | |
385 else if (sObjName == CJS_Style::m_pClassName) | |
386 CJS_Style::GetConsts(pConsts, nSize); | |
387 else if (sObjName == CJS_Zoomtype::m_pClassName) | |
388 CJS_Zoomtype::GetConsts(pConsts, nSize); | |
389 | |
390 else if (sObjName == CJS_App::m_pClassName) | |
391 CJS_App::GetConsts(pConsts, nSize); | |
392 else if (sObjName == CJS_Color::m_pClassName) | |
393 CJS_Color::GetConsts(pConsts, nSize); | |
394 | |
395 else if (sObjName == L"this") | |
396 { | |
397 if (GetReaderDocument()) | |
398 CJS_Document::GetConsts(pConsts, nSize); | |
399 else | |
400 CJS_App::GetConsts(pConsts, nSize); | |
401 } | |
402 | |
403 if (sObjName == CJS_Event::m_pClassName) | |
404 CJS_Event::GetConsts(pConsts, nSize); | |
405 else if (sObjName == CJS_Field::m_pClassName) | |
406 CJS_Field::GetConsts(pConsts, nSize); | |
407 else if (sObjName == CJS_Global::m_pClassName) | |
408 CJS_Global::GetConsts(pConsts, nSize); | |
409 else if (sObjName == CJS_Util::m_pClassName) | |
410 CJS_Util::GetConsts(pConsts, nSize); | |
411 | |
412 for (int i=0; i<nSize; i++) | |
413 array.Add(pConsts[i].pName); | |
414 } | |
415 | |
416 void CJS_Runtime::GetObjectProps(const CFX_WideString& sObjName, CFX_WideStringA
rray& array) | |
417 { | |
418 JSPropertySpec* pProperties = NULL; | |
419 int nSize = 0; | |
420 | |
421 if (sObjName == CJS_App::m_pClassName) | |
422 CJS_App::GetProperties(pProperties, nSize); | |
423 else if (sObjName == CJS_Color::m_pClassName) | |
424 CJS_Color::GetProperties(pProperties, nSize); | |
425 else if (sObjName == L"this") | |
426 { | |
427 if (GetReaderDocument()) | |
428 CJS_Document::GetProperties(pProperties, nSize); | |
429 else | |
430 CJS_App::GetProperties(pProperties, nSize); | |
431 } | |
432 else if (sObjName == CJS_Event::m_pClassName) | |
433 CJS_Event::GetProperties(pProperties, nSize); | |
434 else if (sObjName == CJS_Field::m_pClassName) | |
435 CJS_Field::GetProperties(pProperties, nSize); | |
436 else if (sObjName == CJS_Global::m_pClassName) | |
437 CJS_Global::GetProperties(pProperties, nSize); | |
438 else if (sObjName == CJS_Util::m_pClassName) | |
439 CJS_Util::GetProperties(pProperties, nSize); | |
440 | |
441 for (int i=0; i<nSize; i++) | |
442 array.Add(pProperties[i].pName); | |
443 } | |
444 | |
445 void CJS_Runtime::GetObjectMethods(const CFX_WideString& sObjName, CFX_WideStrin
gArray& array) | |
446 { | |
447 JSMethodSpec* pMethods = NULL; | |
448 int nSize = 0; | |
449 | |
450 if (sObjName == CJS_App::m_pClassName) | |
451 CJS_App::GetMethods(pMethods, nSize); | |
452 else if (sObjName == CJS_Color::m_pClassName) | |
453 CJS_Color::GetMethods(pMethods, nSize); | |
454 else if (sObjName == L"this") | |
455 { | |
456 if (GetReaderDocument()) | |
457 CJS_Document::GetMethods(pMethods, nSize); | |
458 else | |
459 CJS_App::GetMethods(pMethods, nSize); | |
460 } | |
461 else if (sObjName == CJS_Event::m_pClassName) | |
462 CJS_Event::GetMethods(pMethods, nSize); | |
463 else if (sObjName == CJS_Field::m_pClassName) | |
464 CJS_Field::GetMethods(pMethods, nSize); | |
465 else if (sObjName == CJS_Global::m_pClassName) | |
466 CJS_Global::GetMethods(pMethods, nSize); | |
467 else if (sObjName == CJS_Util::m_pClassName) | |
468 CJS_Util::GetMethods(pMethods, nSize); | |
469 | |
470 for (int i=0; i<nSize; i++) | |
471 array.Add(pMethods[i].pName); | |
472 } | |
473 | |
474 FX_BOOL CJS_Runtime::IsEntered() | |
475 { | |
476 return v8::Isolate::GetCurrent() == m_isolate; | |
477 } | |
478 void CJS_Runtime::Exit() | |
479 { | |
480 if(m_isolate) m_isolate->Exit(); | |
481 } | |
482 void CJS_Runtime::Enter() | |
483 { | |
484 if(m_isolate) m_isolate->Enter(); | |
485 } | |
486 FX_BOOL CJS_Runtime::GetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue) | 343 FX_BOOL CJS_Runtime::GetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue) |
487 { | 344 { |
488 FX_LPCSTR name = utf8Name.GetCStr(); | 345 FX_LPCSTR name = utf8Name.GetCStr(); |
489 | 346 |
490 v8::Locker lock(GetIsolate()); | 347 v8::Locker lock(GetIsolate()); |
491 v8::Isolate::Scope isolate_scope(GetIsolate()); | 348 v8::Isolate::Scope isolate_scope(GetIsolate()); |
492 v8::HandleScope handle_scope(GetIsolate()); | 349 v8::HandleScope handle_scope(GetIsolate()); |
493 v8::Local<v8::Context> context = | 350 v8::Local<v8::Context> context = |
494 v8::Local<v8::Context>::New(GetIsolate(), m_context); | 351 v8::Local<v8::Context>::New(GetIsolate(), m_context); |
495 v8::Context::Scope context_scope(context); | 352 v8::Context::Scope context_scope(context); |
(...skipping 22 matching lines...) Expand all Loading... |
518 v8::Local<v8::Context> context = | 375 v8::Local<v8::Context> context = |
519 v8::Local<v8::Context>::New(pIsolate, m_context); | 376 v8::Local<v8::Context>::New(pIsolate, m_context); |
520 v8::Context::Scope context_scope(context); | 377 v8::Context::Scope context_scope(context); |
521 | 378 |
522 //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsol
ate(), m_context); | 379 //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsol
ate(), m_context); |
523 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(),
((CFXJSE_Value*)hValue)->DirectGetValue()); | 380 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(),
((CFXJSE_Value*)hValue)->DirectGetValue()); |
524 context->Global()->Set(v8::String::NewFromUtf8(pIsolate, name, v8::Strin
g::kNormalString, utf8Name.GetLength()), propvalue); | 381 context->Global()->Set(v8::String::NewFromUtf8(pIsolate, name, v8::Strin
g::kNormalString, utf8Name.GetLength()), propvalue); |
525 | 382 |
526 return TRUE; | 383 return TRUE; |
527 } | 384 } |
OLD | NEW |