Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1012)

Side by Side Diff: fpdfsdk/src/javascript/JS_Context.cpp

Issue 1394993006: Merge to XFA: Pass IJS_Runtime, not IJS_Context, to native object constructors. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/JS_Context.h ('k') | fpdfsdk/src/javascript/JS_Define.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "JS_Context.h" 7 #include "JS_Context.h"
8 8
9 #include "../../include/javascript/IJavaScript.h" 9 #include "../../include/javascript/IJavaScript.h"
10 #include "JS_EventHandler.h" 10 #include "JS_EventHandler.h"
(...skipping 15 matching lines...) Expand all
26 return m_pRuntime->GetReaderDocument(); 26 return m_pRuntime->GetReaderDocument();
27 } 27 }
28 28
29 CPDFDoc_Environment* CJS_Context::GetReaderApp() { 29 CPDFDoc_Environment* CJS_Context::GetReaderApp() {
30 ASSERT(m_pRuntime != NULL); 30 ASSERT(m_pRuntime != NULL);
31 31
32 return m_pRuntime->GetReaderApp(); 32 return m_pRuntime->GetReaderApp();
33 } 33 }
34 34
35 FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, 35 FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
36 CFX_WideString& info) { 36 CFX_WideString* info) {
37 v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate()); 37 v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
38 v8::Locker locker(m_pRuntime->GetIsolate()); 38 v8::Locker locker(m_pRuntime->GetIsolate());
39 v8::HandleScope handle_scope(m_pRuntime->GetIsolate()); 39 v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
40 v8::Local<v8::Context> context = m_pRuntime->NewJSContext(); 40 v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
41 v8::Context::Scope context_scope(context); 41 v8::Context::Scope context_scope(context);
42 42
43 if (m_bBusy) { 43 if (m_bBusy) {
44 info = JSGetStringFromID(this, IDS_STRING_JSBUSY); 44 *info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
45 return FALSE; 45 return FALSE;
46 } 46 }
47 m_bBusy = TRUE; 47 m_bBusy = TRUE;
48 48
49 ASSERT(m_pEventHandler->IsValid()); 49 ASSERT(m_pEventHandler->IsValid());
50 CJS_Runtime::FieldEvent event(m_pEventHandler->TargetName(), 50 CJS_Runtime::FieldEvent event(m_pEventHandler->TargetName(),
51 m_pEventHandler->EventType()); 51 m_pEventHandler->EventType());
52 if (!m_pRuntime->AddEventToSet(event)) { 52 if (!m_pRuntime->AddEventToSet(event)) {
53 info = JSGetStringFromID(this, IDS_STRING_JSEVENT); 53 *info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
54 return FALSE; 54 return FALSE;
55 } 55 }
56 56
57 FXJSErr error = {NULL, NULL, 0}; 57 CFX_WideString sErrorMessage;
58 int nRet = 0; 58 int nRet = 0;
59 if (script.GetLength() > 0) { 59 if (script.GetLength() > 0) {
60 nRet = FXJS_Execute(m_pRuntime->GetIsolate(), this, script.c_str(), 60 nRet = m_pRuntime->Execute(this, script.c_str(), &sErrorMessage);
61 script.GetLength(), &error);
62 } 61 }
63 62
64 if (nRet < 0) { 63 if (nRet < 0) {
65 CFX_WideString sLine; 64 *info += sErrorMessage;
66 sLine.Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline,
67 error.message);
68 info += sLine;
69 } else { 65 } else {
70 info = JSGetStringFromID(this, IDS_STRING_RUN); 66 *info = JSGetStringFromID(this, IDS_STRING_RUN);
71 } 67 }
72 68
73 m_pRuntime->RemoveEventFromSet(event); 69 m_pRuntime->RemoveEventFromSet(event);
74 m_pEventHandler->Destroy(); 70 m_pEventHandler->Destroy();
75 m_bBusy = FALSE; 71 m_bBusy = FALSE;
76 72
77 return nRet >= 0; 73 return nRet >= 0;
78 } 74 }
79 75
80 void CJS_Context::OnApp_Init() { 76 void CJS_Context::OnApp_Init() {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 275 }
280 276
281 void CJS_Context::OnBatchExec(CPDFSDK_Document* pTarget) { 277 void CJS_Context::OnBatchExec(CPDFSDK_Document* pTarget) {
282 m_pEventHandler->OnBatchExec(pTarget); 278 m_pEventHandler->OnBatchExec(pTarget);
283 } 279 }
284 280
285 void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget, 281 void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget,
286 const CFX_WideString& strTargetName) { 282 const CFX_WideString& strTargetName) {
287 m_pEventHandler->OnMenu_Exec(pTarget, strTargetName); 283 m_pEventHandler->OnMenu_Exec(pTarget, strTargetName);
288 } 284 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Context.h ('k') | fpdfsdk/src/javascript/JS_Define.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698