From cb22f9ad9265f40b1104ed2b09488ccc6ec9e5aa Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 11 Dec 2017 22:01:08 +0000 Subject: [xfa] Refactor CJX method signatures. This CL changes the CJX methods from void (*)(CFXJSE_Arguments*) to CJS_Return (*)(CJS_V8* runtime, const std::vector>& params) which is closer to how CJS works in practice. Change-Id: I3a3129268acfe4262dfeb04179919ed19f6c24e1 Reviewed-on: https://pdfium-review.googlesource.com/20491 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fxjs/cjs_v8.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'fxjs/cjs_v8.cpp') diff --git a/fxjs/cjs_v8.cpp b/fxjs/cjs_v8.cpp index 67f0cb52b1..18bbed606c 100644 --- a/fxjs/cjs_v8.cpp +++ b/fxjs/cjs_v8.cpp @@ -6,6 +6,11 @@ #include "fxjs/cjs_v8.h" +#ifdef PDF_ENABLE_XFA +#include "fxjs/cfxjse_context.h" +#include "xfa/fxfa/parser/cxfa_object.h" +#endif // PDF_ENABLE_XFA + CJS_V8::CJS_V8(v8::Isolate* isolate) : m_isolate(isolate) {} CJS_V8::~CJS_V8() { @@ -176,6 +181,17 @@ WideString CJS_V8::ToWideString(v8::Local pValue) { return WideString::FromUTF8(ByteStringView(*s, s.length())); } +ByteString CJS_V8::ToByteString(v8::Local pValue) { + if (pValue.IsEmpty()) + return ByteString(); + v8::Local context = m_isolate->GetCurrentContext(); + v8::MaybeLocal maybe_string = pValue->ToString(context); + if (maybe_string.IsEmpty()) + return ByteString(); + v8::String::Utf8Value s(maybe_string.ToLocalChecked()); + return ByteString(*s); +} + v8::Local CJS_V8::ToObject(v8::Local pValue) { if (pValue.IsEmpty() || !pValue->IsObject()) return v8::Local(); @@ -197,3 +213,29 @@ void CJS_V8::SetConstArray(const WideString& name, v8::Local array) { v8::Local CJS_V8::GetConstArray(const WideString& name) { return v8::Local::New(GetIsolate(), m_ConstArrays[name]); } + +#ifdef PDF_ENABLE_XFA +CXFA_Object* CJS_V8::ToXFAObject(v8::Local obj) { + ASSERT(!obj.IsEmpty()); + + if (!obj->IsObject()) + return nullptr; + + CFXJSE_HostObject* hostObj = + FXJSE_RetrieveObjectBinding(obj.As(), nullptr); + if (!hostObj || hostObj->type() != CFXJSE_HostObject::kXFA) + return nullptr; + return static_cast(hostObj); +} + +v8::Local CJS_V8::NewXFAObject( + CXFA_Object* obj, + v8::Global& tmpl) { + v8::EscapableHandleScope scope(m_isolate); + v8::Local klass = + v8::Local::New(m_isolate, tmpl); + v8::Local object = klass->InstanceTemplate()->NewInstance(); + FXJSE_UpdateObjectBinding(object, obj); + return scope.Escape(object); +} +#endif // PDF_ENABLE_XFA -- cgit v1.2.3