summaryrefslogtreecommitdiff
path: root/fxjs/cfxjse_context.cpp
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2017-12-04 15:42:36 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-04 15:42:36 +0000
commitf2d7656f335cf38dfafb97370ffac38b9d4e3fc0 (patch)
treea25d698c3ef75fedba78cc42c9c01195dc352720 /fxjs/cfxjse_context.cpp
parent53190d99102c9b3a5e0a8751e2f4f957d7736ccf (diff)
downloadpdfium-f2d7656f335cf38dfafb97370ffac38b9d4e3fc0.tar.xz
XFA JS method cleanup
Change-Id: I182388970e422bd31d011628a4f1b905d12b0da0 Reviewed-on: https://pdfium-review.googlesource.com/20193 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs/cfxjse_context.cpp')
-rw-r--r--fxjs/cfxjse_context.cpp94
1 files changed, 46 insertions, 48 deletions
diff --git a/fxjs/cfxjse_context.cpp b/fxjs/cfxjse_context.cpp
index ad37ca2c0a..bf9bee8652 100644
--- a/fxjs/cfxjse_context.cpp
+++ b/fxjs/cfxjse_context.cpp
@@ -43,6 +43,48 @@ const char szCompatibleModeScript[] =
wchar_t g_FXJSETagString[] = L"FXJSE_HostObject";
+v8::Local<v8::Object> CreateReturnValue(v8::Isolate* pIsolate,
+ v8::TryCatch& trycatch) {
+ v8::Local<v8::Object> hReturnValue = v8::Object::New(pIsolate);
+ if (trycatch.HasCaught()) {
+ v8::Local<v8::Value> hException = trycatch.Exception();
+ v8::Local<v8::Message> hMessage = trycatch.Message();
+ if (hException->IsObject()) {
+ v8::Local<v8::Value> hValue;
+ hValue = hException.As<v8::Object>()->Get(
+ v8::String::NewFromUtf8(pIsolate, "name"));
+ if (hValue->IsString() || hValue->IsStringObject())
+ hReturnValue->Set(0, hValue);
+ else
+ hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
+
+ hValue = hException.As<v8::Object>()->Get(
+ v8::String::NewFromUtf8(pIsolate, "message"));
+ if (hValue->IsString() || hValue->IsStringObject())
+ hReturnValue->Set(1, hValue);
+ else
+ hReturnValue->Set(1, hMessage->Get());
+ } else {
+ hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
+ hReturnValue->Set(1, hMessage->Get());
+ }
+ hReturnValue->Set(2, hException);
+ hReturnValue->Set(3, v8::Integer::New(pIsolate, hMessage->GetLineNumber()));
+ hReturnValue->Set(4, hMessage->GetSourceLine());
+ v8::Maybe<int32_t> maybe_int =
+ hMessage->GetStartColumn(pIsolate->GetCurrentContext());
+ hReturnValue->Set(5, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0)));
+ maybe_int = hMessage->GetEndColumn(pIsolate->GetCurrentContext());
+ hReturnValue->Set(6, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0)));
+ }
+ return hReturnValue;
+}
+
+v8::Local<v8::Object> GetGlobalObjectFromContext(
+ v8::Local<v8::Context> hContext) {
+ return hContext->Global()->GetPrototype().As<v8::Object>();
+}
+
} // namespace
// Note, not in the anonymous namespace due to the friend call
@@ -73,11 +115,6 @@ class CFXJSE_ScopeUtil_IsolateHandleContext {
v8::Context::Scope m_cscope;
};
-v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext(
- v8::Local<v8::Context> hContext) {
- return hContext->Global()->GetPrototype().As<v8::Object>();
-}
-
void FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject,
CFXJSE_HostObject* lpNewBinding) {
ASSERT(!hObject.IsEmpty());
@@ -115,43 +152,6 @@ CFXJSE_HostObject* FXJSE_RetrieveObjectBinding(v8::Local<v8::Object> hJSObject,
hObject->GetAlignedPointerFromInternalField(1));
}
-v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate,
- v8::TryCatch& trycatch) {
- v8::Local<v8::Object> hReturnValue = v8::Object::New(pIsolate);
- if (trycatch.HasCaught()) {
- v8::Local<v8::Value> hException = trycatch.Exception();
- v8::Local<v8::Message> hMessage = trycatch.Message();
- if (hException->IsObject()) {
- v8::Local<v8::Value> hValue;
- hValue = hException.As<v8::Object>()->Get(
- v8::String::NewFromUtf8(pIsolate, "name"));
- if (hValue->IsString() || hValue->IsStringObject())
- hReturnValue->Set(0, hValue);
- else
- hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
-
- hValue = hException.As<v8::Object>()->Get(
- v8::String::NewFromUtf8(pIsolate, "message"));
- if (hValue->IsString() || hValue->IsStringObject())
- hReturnValue->Set(1, hValue);
- else
- hReturnValue->Set(1, hMessage->Get());
- } else {
- hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error"));
- hReturnValue->Set(1, hMessage->Get());
- }
- hReturnValue->Set(2, hException);
- hReturnValue->Set(3, v8::Integer::New(pIsolate, hMessage->GetLineNumber()));
- hReturnValue->Set(4, hMessage->GetSourceLine());
- v8::Maybe<int32_t> maybe_int =
- hMessage->GetStartColumn(pIsolate->GetCurrentContext());
- hReturnValue->Set(5, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0)));
- maybe_int = hMessage->GetEndColumn(pIsolate->GetCurrentContext());
- hReturnValue->Set(6, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0)));
- }
- return hReturnValue;
-}
-
// static
std::unique_ptr<CFXJSE_Context> CFXJSE_Context::Create(
v8::Isolate* pIsolate,
@@ -182,8 +182,7 @@ std::unique_ptr<CFXJSE_Context> CFXJSE_Context::Create(
v8::Local<v8::Context> hRootContext = v8::Local<v8::Context>::New(
pIsolate, CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext);
hNewContext->SetSecurityToken(hRootContext->GetSecurityToken());
- v8::Local<v8::Object> hGlobalObject =
- FXJSE_GetGlobalObjectFromContext(hNewContext);
+ v8::Local<v8::Object> hGlobalObject = GetGlobalObjectFromContext(hNewContext);
FXJSE_UpdateObjectBinding(hGlobalObject, pGlobalObject);
pContext->m_hContext.Reset(pIsolate, hNewContext);
return pContext;
@@ -198,8 +197,7 @@ std::unique_ptr<CFXJSE_Value> CFXJSE_Context::GetGlobalObject() {
CFXJSE_ScopeUtil_IsolateHandleContext scope(this);
v8::Local<v8::Context> hContext =
v8::Local<v8::Context>::New(m_pIsolate, m_hContext);
- v8::Local<v8::Object> hGlobalObject =
- FXJSE_GetGlobalObjectFromContext(hContext);
+ v8::Local<v8::Object> hGlobalObject = GetGlobalObjectFromContext(hContext);
pValue->ForceSetValue(hGlobalObject);
return pValue;
}
@@ -245,7 +243,7 @@ bool CFXJSE_Context::ExecuteScript(const char* szScript,
}
if (lpRetValue) {
lpRetValue->m_hValue.Reset(m_pIsolate,
- FXJSE_CreateReturnValue(m_pIsolate, trycatch));
+ CreateReturnValue(m_pIsolate, trycatch));
}
return false;
}
@@ -270,7 +268,7 @@ bool CFXJSE_Context::ExecuteScript(const char* szScript,
}
if (lpRetValue) {
lpRetValue->m_hValue.Reset(m_pIsolate,
- FXJSE_CreateReturnValue(m_pIsolate, trycatch));
+ CreateReturnValue(m_pIsolate, trycatch));
}
return false;
}