diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-12-11 22:01:08 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-11 22:01:08 +0000 |
commit | cb22f9ad9265f40b1104ed2b09488ccc6ec9e5aa (patch) | |
tree | 4aaa14dfb0528268fb9a9a94a4cac82df1af4602 /fxjs/cjs_v8.cpp | |
parent | 731526e3b9f32ceac1cdac600fe3ecd55a0bc9b5 (diff) | |
download | pdfium-cb22f9ad9265f40b1104ed2b09488ccc6ec9e5aa.tar.xz |
[xfa] Refactor CJX method signatures.
This CL changes the CJX methods from void (*)(CFXJSE_Arguments*) to
CJS_Return (*)(CJS_V8* runtime, const std::vector<v8::Local<v8::Value>>&
params) which is closer to how CJS works in practice.
Change-Id: I3a3129268acfe4262dfeb04179919ed19f6c24e1
Reviewed-on: https://pdfium-review.googlesource.com/20491
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/cjs_v8.cpp')
-rw-r--r-- | fxjs/cjs_v8.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
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<v8::Value> pValue) { return WideString::FromUTF8(ByteStringView(*s, s.length())); } +ByteString CJS_V8::ToByteString(v8::Local<v8::Value> pValue) { + if (pValue.IsEmpty()) + return ByteString(); + v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); + v8::MaybeLocal<v8::String> maybe_string = pValue->ToString(context); + if (maybe_string.IsEmpty()) + return ByteString(); + v8::String::Utf8Value s(maybe_string.ToLocalChecked()); + return ByteString(*s); +} + v8::Local<v8::Object> CJS_V8::ToObject(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty() || !pValue->IsObject()) return v8::Local<v8::Object>(); @@ -197,3 +213,29 @@ void CJS_V8::SetConstArray(const WideString& name, v8::Local<v8::Array> array) { v8::Local<v8::Array> CJS_V8::GetConstArray(const WideString& name) { return v8::Local<v8::Array>::New(GetIsolate(), m_ConstArrays[name]); } + +#ifdef PDF_ENABLE_XFA +CXFA_Object* CJS_V8::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> CJS_V8::NewXFAObject( + CXFA_Object* obj, + v8::Global<v8::FunctionTemplate>& tmpl) { + v8::EscapableHandleScope scope(m_isolate); + v8::Local<v8::FunctionTemplate> klass = + v8::Local<v8::FunctionTemplate>::New(m_isolate, tmpl); + v8::Local<v8::Object> object = klass->InstanceTemplate()->NewInstance(); + FXJSE_UpdateObjectBinding(object, obj); + return scope.Escape(object); +} +#endif // PDF_ENABLE_XFA |