summaryrefslogtreecommitdiff
path: root/fxjs/cfxjse_engine.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-06-05 18:24:12 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-05 18:24:12 +0000
commite9f7db9dbb2c5b9d1953c6643e1c38f82130f98b (patch)
tree8918f344abae83984dcd976dbe2a19bf0b0bcc1c /fxjs/cfxjse_engine.cpp
parent22de733a693f27c90f58ee13cfd398c55d9a064f (diff)
downloadpdfium-e9f7db9dbb2c5b9d1953c6643e1c38f82130f98b.tar.xz
[xfa] Make the event context available when calling back in XFA
When calling into the XFA JS engine with a request for a non-XFA JS call which accesses the EventContext we would get a crash in XFA as we never set the context. This CL changes the XFA code to accept the CJS_Runtime instead of the CFXJS_Engine and then calls NewEventContext before executing JS scripts. This will correctly setup the event context as needed for any JS callbacks. Bug: pdfium:1003 Change-Id: Icf202252b2e6e56afdf0d1766a32a893935a2fd3 Reviewed-on: https://pdfium-review.googlesource.com/33930 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs/cfxjse_engine.cpp')
-rw-r--r--fxjs/cfxjse_engine.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp
index e894d51de4..90fcc312db 100644
--- a/fxjs/cfxjse_engine.cpp
+++ b/fxjs/cfxjse_engine.cpp
@@ -11,10 +11,10 @@
#include "core/fxcrt/autorestorer.h"
#include "core/fxcrt/cfx_widetextbuf.h"
#include "core/fxcrt/fx_extension.h"
-#include "fxjs/cfxjs_engine.h"
#include "fxjs/cfxjse_class.h"
#include "fxjs/cfxjse_resolveprocessor.h"
#include "fxjs/cfxjse_value.h"
+#include "fxjs/cjs_runtime.h"
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
#include "xfa/fxfa/cxfa_eventparam.h"
@@ -94,12 +94,12 @@ CXFA_Object* CFXJSE_Engine::ToObject(CFXJSE_Value* pValue,
}
CFXJSE_Engine::CFXJSE_Engine(CXFA_Document* pDocument,
- CFXJS_Engine* fxjs_engine)
- : CFX_V8(fxjs_engine->GetIsolate()),
- m_pSubordinateEngine(fxjs_engine),
+ CJS_Runtime* fxjs_runtime)
+ : CFX_V8(fxjs_runtime->GetIsolate()),
+ m_pSubordinateRuntime(fxjs_runtime),
m_pDocument(pDocument),
- m_JsContext(CFXJSE_Context::Create(fxjs_engine->GetIsolate(),
- fxjs_engine,
+ m_JsContext(CFXJSE_Context::Create(fxjs_runtime->GetIsolate(),
+ fxjs_runtime,
&GlobalClassDescriptor,
pDocument->GetRoot())),
m_pJsClass(nullptr),
@@ -146,7 +146,12 @@ bool CFXJSE_Engine::RunScript(CXFA_Script::Type eScriptType,
AutoRestorer<CXFA_Object*> nodeRestorer(&m_pThisObject);
m_pThisObject = pThisObject;
CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : nullptr;
- return m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue);
+
+ IJS_EventContext* ctx = m_pSubordinateRuntime->NewEventContext();
+ bool ret = m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue);
+ m_pSubordinateRuntime->ReleaseEventContext(ctx);
+
+ return ret;
}
bool CFXJSE_Engine::QueryNodeByFlag(CXFA_Node* refNode,
@@ -463,7 +468,7 @@ CFXJSE_Context* CFXJSE_Engine::CreateVariablesContext(CXFA_Node* pScriptNode,
return nullptr;
auto pNewContext = CFXJSE_Context::Create(
- GetIsolate(), m_pSubordinateEngine.Get(), &VariablesClassDescriptor,
+ GetIsolate(), m_pSubordinateRuntime.Get(), &VariablesClassDescriptor,
new CXFA_ThisProxy(pSubform, pScriptNode));
RemoveBuiltInObjs(pNewContext.get());
pNewContext->EnableCompatibleMode();