diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-09-01 09:51:10 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-09-01 09:51:10 -0700 |
commit | 9ed941a3709dc27ab8c7b27941197c6238f201a3 (patch) | |
tree | 929cf2ab538aca70a0544bfd633796c345c64ef1 | |
parent | aecd9d0c5cfc569269bfe6cc228efaab76a7bb1b (diff) | |
download | pdfium-9ed941a3709dc27ab8c7b27941197c6238f201a3.tar.xz |
Merge to XFA: CJS_Context::compile unused
Manual merge in fpdfsdk/src/javascript/JS_Context.cpp
(cherry picked from commit 6e945a1ebbacde3ed2a4fc83ccb7215ccbc46931)
Original Review URL: https://codereview.chromium.org/1318543012 .
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1318343004 .
-rw-r--r-- | fpdfsdk/include/javascript/IJavaScript.h | 2 | ||||
-rw-r--r-- | fpdfsdk/include/javascript/JS_Context.h | 10 | ||||
-rw-r--r-- | fpdfsdk/include/jsapi/fxjs_v8.h | 5 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Context.cpp | 90 | ||||
-rw-r--r-- | fpdfsdk/src/jsapi/fxjs_v8.cpp | 25 |
5 files changed, 14 insertions, 118 deletions
diff --git a/fpdfsdk/include/javascript/IJavaScript.h b/fpdfsdk/include/javascript/IJavaScript.h index 9c232b01fb..3da2c1a002 100644 --- a/fpdfsdk/include/javascript/IJavaScript.h +++ b/fpdfsdk/include/javascript/IJavaScript.h @@ -18,8 +18,6 @@ class CPDFSDK_Document; class IFXJS_Context { public: - virtual FX_BOOL Compile(const CFX_WideString& script, - CFX_WideString& info) = 0; virtual FX_BOOL RunScript(const CFX_WideString& script, CFX_WideString& info) = 0; diff --git a/fpdfsdk/include/javascript/JS_Context.h b/fpdfsdk/include/javascript/JS_Context.h index 995d32219e..d5b1064cfc 100644 --- a/fpdfsdk/include/javascript/JS_Context.h +++ b/fpdfsdk/include/javascript/JS_Context.h @@ -16,11 +16,10 @@ class CJS_Runtime; class CJS_Context : public IFXJS_Context { public: - CJS_Context(CJS_Runtime* pRuntime); + explicit CJS_Context(CJS_Runtime* pRuntime); ~CJS_Context() override; // IFXJS_Context - FX_BOOL Compile(const CFX_WideString& script, CFX_WideString& info) override; FX_BOOL RunScript(const CFX_WideString& script, CFX_WideString& info) override; void OnApp_Init() override; @@ -124,11 +123,8 @@ class CJS_Context : public IFXJS_Context { FX_BOOL IsMsgBoxEnabled() const { return m_bMsgBoxEnable; } CPDFDoc_Environment* GetReaderApp(); - CJS_Runtime* GetJSRuntime() { return m_pRuntime; } - - FX_BOOL DoJob(int nMode, const CFX_WideString& script, CFX_WideString& info); - - CJS_EventHandler* GetEventHandler() { return m_pEventHandler; } + CJS_Runtime* GetJSRuntime() const { return m_pRuntime; } + CJS_EventHandler* GetEventHandler() const { return m_pEventHandler; } CPDFSDK_Document* GetReaderDocument(); private: diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h index 72f2a5de01..f9d8f50248 100644 --- a/fpdfsdk/include/jsapi/fxjs_v8.h +++ b/fpdfsdk/include/jsapi/fxjs_v8.h @@ -91,11 +91,6 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8PersistentContext); void JS_Initial(unsigned int embedderDataSlot); void JS_Release(); -int JS_Parse(IJS_Runtime* pJSRuntime, - IFXJS_Context* pJSContext, - const wchar_t* script, - long length, - FXJSErr* perror); int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp index b51b5aa265..51c18f1249 100644 --- a/fpdfsdk/src/javascript/JS_Context.cpp +++ b/fpdfsdk/src/javascript/JS_Context.cpp @@ -4,12 +4,11 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "../../include/javascript/JavaScript.h" #include "../../include/javascript/IJavaScript.h" -//#include "../../include/javascript/JS_ResMgr.h" #include "../../include/javascript/JS_Context.h" #include "../../include/javascript/JS_EventHandler.h" #include "../../include/javascript/JS_Runtime.h" +#include "../../include/javascript/JavaScript.h" #include "../../include/javascript/resource.h" /* -------------------------- CJS_Context -------------------------- */ @@ -24,8 +23,6 @@ CJS_Context::~CJS_Context() { } CPDFSDK_Document* CJS_Context::GetReaderDocument() { - ASSERT(m_pRuntime != NULL); - return m_pRuntime->GetReaderDocument(); } @@ -35,20 +32,21 @@ CPDFDoc_Environment* CJS_Context::GetReaderApp() { return m_pRuntime->GetReaderApp(); } -FX_BOOL CJS_Context::DoJob(int nMode, - const CFX_WideString& script, - CFX_WideString& info) { +FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, + CFX_WideString& info) { + v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate()); + v8::Locker locker(m_pRuntime->GetIsolate()); + v8::HandleScope handle_scope(m_pRuntime->GetIsolate()); + v8::Local<v8::Context> context = m_pRuntime->NewJSContext(); + v8::Context::Scope context_scope(context); + if (m_bBusy) { info = JSGetStringFromID(this, IDS_STRING_JSBUSY); return FALSE; } - m_bBusy = TRUE; - ASSERT(m_pRuntime != NULL); - ASSERT(m_pEventHandler != NULL); ASSERT(m_pEventHandler->IsValid()); - if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType())) { info = JSGetStringFromID(this, IDS_STRING_JSEVENT); @@ -57,27 +55,15 @@ FX_BOOL CJS_Context::DoJob(int nMode, FXJSErr error = {NULL, NULL, 0}; int nRet = 0; - if (script.GetLength() > 0) { - if (nMode == 0) { - nRet = JS_Execute(*m_pRuntime, this, script.c_str(), script.GetLength(), - &error); - } else { - nRet = JS_Parse(*m_pRuntime, this, script.c_str(), script.GetLength(), + nRet = JS_Execute(*m_pRuntime, this, script.c_str(), script.GetLength(), &error); - } } if (nRet < 0) { CFX_WideString sLine; sLine.Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline, error.message); - - // TRACE(L"/* -------------- JS Error -------------- - //*/\n"); - // TRACE(sLine); - // TRACE(L"\n"); - // CFX_ByteString sTemp = CFX_ByteString::FromUnicode(error.message); info += sLine; } else { info = JSGetStringFromID(this, IDS_STRING_RUN); @@ -92,108 +78,72 @@ FX_BOOL CJS_Context::DoJob(int nMode, return nRet >= 0; } -FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, - CFX_WideString& info) { - v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate()); - v8::Locker locker(m_pRuntime->GetIsolate()); - v8::HandleScope handle_scope(m_pRuntime->GetIsolate()); - v8::Local<v8::Context> context = m_pRuntime->NewJSContext(); - v8::Context::Scope context_scope(context); - - return DoJob(0, script, info); -} - -FX_BOOL CJS_Context::Compile(const CFX_WideString& script, - CFX_WideString& info) { - v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate()); - v8::HandleScope handle_scope(m_pRuntime->GetIsolate()); - v8::Local<v8::Context> context = m_pRuntime->NewJSContext(); - v8::Context::Scope context_scope(context); - - return DoJob(1, script, info); -} - void CJS_Context::OnApp_Init() { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnApp_Init(); } void CJS_Context::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnDoc_Open(pDoc, strTargetName); } void CJS_Context::OnDoc_WillPrint(CPDFSDK_Document* pDoc) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnDoc_WillPrint(pDoc); } void CJS_Context::OnDoc_DidPrint(CPDFSDK_Document* pDoc) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnDoc_DidPrint(pDoc); } void CJS_Context::OnDoc_WillSave(CPDFSDK_Document* pDoc) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnDoc_WillSave(pDoc); } void CJS_Context::OnDoc_DidSave(CPDFSDK_Document* pDoc) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnDoc_DidSave(pDoc); } void CJS_Context::OnDoc_WillClose(CPDFSDK_Document* pDoc) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnDoc_WillClose(pDoc); } void CJS_Context::OnPage_Open(CPDFSDK_Document* pTarget) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnPage_Open(pTarget); } void CJS_Context::OnPage_Close(CPDFSDK_Document* pTarget) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnPage_Close(pTarget); } void CJS_Context::OnPage_InView(CPDFSDK_Document* pTarget) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnPage_InView(pTarget); } void CJS_Context::OnPage_OutView(CPDFSDK_Document* pTarget) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnPage_OutView(pTarget); } void CJS_Context::OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnField_MouseDown(bModifier, bShift, pTarget); } void CJS_Context::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnField_MouseEnter(bModifier, bShift, pTarget); } void CJS_Context::OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnField_MouseExit(bModifier, bShift, pTarget); } void CJS_Context::OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnField_MouseUp(bModifier, bShift, pTarget); } @@ -201,7 +151,6 @@ void CJS_Context::OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnField_Focus(bModifier, bShift, pTarget, Value); } @@ -209,7 +158,6 @@ void CJS_Context::OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnField_Blur(bModifier, bShift, pTarget, Value); } @@ -217,7 +165,6 @@ void CJS_Context::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnField_Calculate(pSource, pTarget, Value, bRc); } @@ -252,7 +199,6 @@ void CJS_Context::OnField_Validate(CFX_WideString& strChange, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnField_Validate(strChange, strChangeEx, bKeyDown, bModifier, bShift, pTarget, Value, bRc); } @@ -260,100 +206,84 @@ void CJS_Context::OnField_Validate(CFX_WideString& strChange, void CJS_Context::OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnScreen_Focus(bModifier, bShift, pScreen); } void CJS_Context::OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnScreen_Blur(bModifier, bShift, pScreen); } void CJS_Context::OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnScreen_Open(bModifier, bShift, pScreen); } void CJS_Context::OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnScreen_Close(bModifier, bShift, pScreen); } void CJS_Context::OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnScreen_MouseDown(bModifier, bShift, pScreen); } void CJS_Context::OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnScreen_MouseUp(bModifier, bShift, pScreen); } void CJS_Context::OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnScreen_MouseEnter(bModifier, bShift, pScreen); } void CJS_Context::OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnScreen_MouseExit(bModifier, bShift, pScreen); } void CJS_Context::OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnScreen_InView(bModifier, bShift, pScreen); } void CJS_Context::OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnScreen_OutView(bModifier, bShift, pScreen); } void CJS_Context::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnBookmark_MouseUp(pBookMark); } void CJS_Context::OnLink_MouseUp(CPDFSDK_Document* pTarget) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnLink_MouseUp(pTarget); } void CJS_Context::OnConsole_Exec() { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnConsole_Exec(); } void CJS_Context::OnExternal_Exec() { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnExternal_Exec(); } void CJS_Context::OnBatchExec(CPDFSDK_Document* pTarget) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnBatchExec(pTarget); } void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName) { - ASSERT(m_pEventHandler != NULL); m_pEventHandler->OnMenu_Exec(pTarget, strTargetName); } diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp index d0e8e6e593..de957ed456 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp @@ -373,31 +373,8 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, void JS_Initial(unsigned int embedderDataSlot) { g_embedderDataSlot = embedderDataSlot; } -void JS_Release() {} -int JS_Parse(IJS_Runtime* pJSRuntime, - IFXJS_Context* pJSContext, - const wchar_t* script, - long length, - FXJSErr* perror) { - v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; - v8::Isolate::Scope isolate_scope(isolate); - v8::TryCatch try_catch(isolate); - CFX_WideString wsScript(script); - CFX_ByteString bsScript = wsScript.UTF8Encode(); - - v8::Local<v8::Context> context = isolate->GetCurrentContext(); - v8::Local<v8::Script> compiled_script; - if (!v8::Script::Compile(context, - v8::String::NewFromUtf8(isolate, bsScript.c_str(), - v8::NewStringType::kNormal, - bsScript.GetLength()) - .ToLocalChecked()) - .ToLocal(&compiled_script)) { - v8::String::Utf8Value error(try_catch.Exception()); - return -1; - } - return 0; +void JS_Release() { } int JS_Execute(IJS_Runtime* pJSRuntime, |