| 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 { | 317 { |
| 318 return v8::Local<v8::Context>::New(m_isolate, m_context); | 318 return v8::Local<v8::Context>::New(m_isolate, m_context); |
| 319 } | 319 } |
| 320 | 320 |
| 321 CFX_WideString ChangeObjName(const CFX_WideString& str) | 321 CFX_WideString ChangeObjName(const CFX_WideString& str) |
| 322 { | 322 { |
| 323 CFX_WideString sRet = str; | 323 CFX_WideString sRet = str; |
| 324 sRet.Replace(L"_", L"."); | 324 sRet.Replace(L"_", L"."); |
| 325 return sRet; | 325 return sRet; |
| 326 } | 326 } |
| 327 | |
| 328 void CJS_Runtime::GetObjectNames(CFX_WideStringArray& array) | |
| 329 { | |
| 330 array.RemoveAll(); | |
| 331 | |
| 332 array.Add(CJS_Border::m_pClassName); | |
| 333 array.Add(CJS_Display::m_pClassName); | |
| 334 array.Add(CJS_Font::m_pClassName); | |
| 335 array.Add(CJS_Highlight::m_pClassName); | |
| 336 array.Add(CJS_Position::m_pClassName); | |
| 337 array.Add(CJS_ScaleHow::m_pClassName); | |
| 338 array.Add(CJS_ScaleWhen::m_pClassName); | |
| 339 array.Add(CJS_Style::m_pClassName); | |
| 340 array.Add(CJS_Zoomtype::m_pClassName); | |
| 341 | |
| 342 array.Add(CJS_App::m_pClassName); | |
| 343 array.Add(L"this"); | |
| 344 array.Add(CJS_Event::m_pClassName); | |
| 345 | |
| 346 array.Add(CJS_Global::m_pClassName); | |
| 347 array.Add(CJS_Util::m_pClassName); | |
| 348 } | |
| 349 | |
| 350 void CJS_Runtime::GetObjectConsts(const CFX_WideString& sObjName, CFX_WideString
Array& array) | |
| 351 { | |
| 352 JSConstSpec* pConsts = NULL; | |
| 353 int nSize = 0; | |
| 354 | |
| 355 if (sObjName == CJS_Border::m_pClassName) | |
| 356 CJS_Border::GetConsts(pConsts, nSize); | |
| 357 else if (sObjName == CJS_Display::m_pClassName) | |
| 358 CJS_Display::GetConsts(pConsts, nSize); | |
| 359 else if (sObjName == CJS_Font::m_pClassName) | |
| 360 CJS_Font::GetConsts(pConsts, nSize); | |
| 361 else if (sObjName == CJS_Highlight::m_pClassName) | |
| 362 CJS_Highlight::GetConsts(pConsts, nSize); | |
| 363 else if (sObjName == CJS_Position::m_pClassName) | |
| 364 CJS_Position::GetConsts(pConsts, nSize); | |
| 365 else if (sObjName == CJS_ScaleHow::m_pClassName) | |
| 366 CJS_ScaleHow::GetConsts(pConsts, nSize); | |
| 367 else if (sObjName == CJS_ScaleWhen::m_pClassName) | |
| 368 CJS_ScaleWhen::GetConsts(pConsts, nSize); | |
| 369 else if (sObjName == CJS_Style::m_pClassName) | |
| 370 CJS_Style::GetConsts(pConsts, nSize); | |
| 371 else if (sObjName == CJS_Zoomtype::m_pClassName) | |
| 372 CJS_Zoomtype::GetConsts(pConsts, nSize); | |
| 373 | |
| 374 else if (sObjName == CJS_App::m_pClassName) | |
| 375 CJS_App::GetConsts(pConsts, nSize); | |
| 376 else if (sObjName == CJS_Color::m_pClassName) | |
| 377 CJS_Color::GetConsts(pConsts, nSize); | |
| 378 | |
| 379 else if (sObjName == L"this") | |
| 380 { | |
| 381 if (GetReaderDocument()) | |
| 382 CJS_Document::GetConsts(pConsts, nSize); | |
| 383 else | |
| 384 CJS_App::GetConsts(pConsts, nSize); | |
| 385 } | |
| 386 | |
| 387 if (sObjName == CJS_Event::m_pClassName) | |
| 388 CJS_Event::GetConsts(pConsts, nSize); | |
| 389 else if (sObjName == CJS_Field::m_pClassName) | |
| 390 CJS_Field::GetConsts(pConsts, nSize); | |
| 391 else if (sObjName == CJS_Global::m_pClassName) | |
| 392 CJS_Global::GetConsts(pConsts, nSize); | |
| 393 else if (sObjName == CJS_Util::m_pClassName) | |
| 394 CJS_Util::GetConsts(pConsts, nSize); | |
| 395 | |
| 396 for (int i=0; i<nSize; i++) | |
| 397 array.Add(pConsts[i].pName); | |
| 398 } | |
| 399 | |
| 400 void CJS_Runtime::GetObjectProps(const CFX_WideString& sObjName, CFX_WideStringA
rray& array) | |
| 401 { | |
| 402 JSPropertySpec* pProperties = NULL; | |
| 403 int nSize = 0; | |
| 404 | |
| 405 if (sObjName == CJS_App::m_pClassName) | |
| 406 CJS_App::GetProperties(pProperties, nSize); | |
| 407 else if (sObjName == CJS_Color::m_pClassName) | |
| 408 CJS_Color::GetProperties(pProperties, nSize); | |
| 409 else if (sObjName == L"this") | |
| 410 { | |
| 411 if (GetReaderDocument()) | |
| 412 CJS_Document::GetProperties(pProperties, nSize); | |
| 413 else | |
| 414 CJS_App::GetProperties(pProperties, nSize); | |
| 415 } | |
| 416 else if (sObjName == CJS_Event::m_pClassName) | |
| 417 CJS_Event::GetProperties(pProperties, nSize); | |
| 418 else if (sObjName == CJS_Field::m_pClassName) | |
| 419 CJS_Field::GetProperties(pProperties, nSize); | |
| 420 else if (sObjName == CJS_Global::m_pClassName) | |
| 421 CJS_Global::GetProperties(pProperties, nSize); | |
| 422 else if (sObjName == CJS_Util::m_pClassName) | |
| 423 CJS_Util::GetProperties(pProperties, nSize); | |
| 424 | |
| 425 for (int i=0; i<nSize; i++) | |
| 426 array.Add(pProperties[i].pName); | |
| 427 } | |
| 428 | |
| 429 void CJS_Runtime::GetObjectMethods(const CFX_WideString& sObjName, CFX_WideStrin
gArray& array) | |
| 430 { | |
| 431 JSMethodSpec* pMethods = NULL; | |
| 432 int nSize = 0; | |
| 433 | |
| 434 if (sObjName == CJS_App::m_pClassName) | |
| 435 CJS_App::GetMethods(pMethods, nSize); | |
| 436 else if (sObjName == CJS_Color::m_pClassName) | |
| 437 CJS_Color::GetMethods(pMethods, nSize); | |
| 438 else if (sObjName == L"this") | |
| 439 { | |
| 440 if (GetReaderDocument()) | |
| 441 CJS_Document::GetMethods(pMethods, nSize); | |
| 442 else | |
| 443 CJS_App::GetMethods(pMethods, nSize); | |
| 444 } | |
| 445 else if (sObjName == CJS_Event::m_pClassName) | |
| 446 CJS_Event::GetMethods(pMethods, nSize); | |
| 447 else if (sObjName == CJS_Field::m_pClassName) | |
| 448 CJS_Field::GetMethods(pMethods, nSize); | |
| 449 else if (sObjName == CJS_Global::m_pClassName) | |
| 450 CJS_Global::GetMethods(pMethods, nSize); | |
| 451 else if (sObjName == CJS_Util::m_pClassName) | |
| 452 CJS_Util::GetMethods(pMethods, nSize); | |
| 453 | |
| 454 for (int i=0; i<nSize; i++) | |
| 455 array.Add(pMethods[i].pName); | |
| 456 } | |
| 457 | |
| 458 FX_BOOL CJS_Runtime::IsEntered() | |
| 459 { | |
| 460 return v8::Isolate::GetCurrent() == m_isolate; | |
| 461 } | |
| 462 void CJS_Runtime::Exit() | |
| 463 { | |
| 464 if(m_isolate) m_isolate->Exit(); | |
| 465 } | |
| 466 void CJS_Runtime::Enter() | |
| 467 { | |
| 468 if(m_isolate) m_isolate->Enter(); | |
| 469 } | |
| OLD | NEW |