summaryrefslogtreecommitdiff
path: root/fxjs/cjs_v8.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fxjs/cjs_v8.cpp')
-rw-r--r--fxjs/cjs_v8.cpp42
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