summaryrefslogtreecommitdiff
path: root/fxjs/cfxjse_engine.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-02-08 21:01:01 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-08 21:01:01 +0000
commit3645652fb6cad1f94c9647f033a8e300bc37d521 (patch)
tree136dd8524455efdc4bbc32eed7914d3a3b5376e0 /fxjs/cfxjse_engine.cpp
parent3c62d20a385d31315a392206de53c9fe72a08db1 (diff)
downloadpdfium-3645652fb6cad1f94c9647f033a8e300bc37d521.tar.xz
Move XFA-specific methods out of CJS_V8.
These belong more properly in CFXJS_Engine, and a small amount of casting is required to get to the sub-class. Change-Id: Id954d182b7a7d51fe0a522c04a50a1b362746c72 Reviewed-on: https://pdfium-review.googlesource.com/26050 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/cfxjse_engine.cpp')
-rw-r--r--fxjs/cfxjse_engine.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp
index 84981666df..1c07a949b0 100644
--- a/fxjs/cfxjse_engine.cpp
+++ b/fxjs/cfxjse_engine.cpp
@@ -756,3 +756,27 @@ void CFXJSE_Engine::AddNodesOfRunScript(CXFA_Node* pNode) {
if (m_pScriptNodeArray && !pdfium::ContainsValue(*m_pScriptNodeArray, pNode))
m_pScriptNodeArray->push_back(pNode);
}
+
+CXFA_Object* CFXJSE_Engine::ToXFAObject(v8::Local<v8::Value> obj) {
+ ASSERT(!obj.IsEmpty());
+
+ if (!obj->IsObject())
+ return nullptr;
+
+ CFXJSE_HostObject* hostObj =
+ FXJSE_RetrieveObjectBinding(obj.As<v8::Object>(), nullptr);
+ if (!hostObj || hostObj->type() != CFXJSE_HostObject::kXFA)
+ return nullptr;
+ return static_cast<CXFA_Object*>(hostObj);
+}
+
+v8::Local<v8::Value> CFXJSE_Engine::NewXFAObject(
+ CXFA_Object* obj,
+ v8::Global<v8::FunctionTemplate>& tmpl) {
+ v8::EscapableHandleScope scope(GetIsolate());
+ v8::Local<v8::FunctionTemplate> klass =
+ v8::Local<v8::FunctionTemplate>::New(GetIsolate(), tmpl);
+ v8::Local<v8::Object> object = klass->InstanceTemplate()->NewInstance();
+ FXJSE_UpdateObjectBinding(object, obj);
+ return scope.Escape(object);
+}