summaryrefslogtreecommitdiff
path: root/fxjs/cfxjse_context.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-25 12:43:13 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-25 20:31:57 +0000
commit80547a165adf250f31ade57544771201bbc2690c (patch)
tree1c1669fdcbc6d2fc443172142b80c03cd1a4972a /fxjs/cfxjse_context.cpp
parent233360e3ea0d6d4acea76a7d9e7ce7700ea80b1a (diff)
downloadpdfium-80547a165adf250f31ade57544771201bbc2690c.tar.xz
Use unique_ptr in CXFA_ScriptContext::m_mapVariableToContext.
Remove unused CFXJSE_Arguments::GetRuntime(). Remove some default argument values. Make members of CFXJSE_Context private. Change-Id: Id21951f7d8d68929b2799a9d6a2cdd7a3677f52a Reviewed-on: https://pdfium-review.googlesource.com/4493 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs/cfxjse_context.cpp')
-rw-r--r--fxjs/cfxjse_context.cpp44
1 files changed, 31 insertions, 13 deletions
diff --git a/fxjs/cfxjse_context.cpp b/fxjs/cfxjse_context.cpp
index d3b55ff43e..183d6363eb 100644
--- a/fxjs/cfxjse_context.cpp
+++ b/fxjs/cfxjse_context.cpp
@@ -6,6 +6,8 @@
#include "fxjs/cfxjse_context.h"
+#include <utility>
+
#include "fxjs/cfxjse_class.h"
#include "fxjs/cfxjse_value.h"
#include "third_party/base/ptr_util.h"
@@ -102,7 +104,7 @@ CFXJSE_HostObject* FXJSE_RetrieveObjectBinding(
if (lpClass) {
v8::Local<v8::FunctionTemplate> hClass =
v8::Local<v8::FunctionTemplate>::New(
- lpClass->GetContext()->GetRuntime(), lpClass->GetTemplate());
+ lpClass->GetContext()->GetIsolate(), lpClass->GetTemplate());
if (!hClass->HasInstance(hObject))
return nullptr;
}
@@ -148,20 +150,20 @@ v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate,
}
// static
-CFXJSE_Context* CFXJSE_Context::Create(
+std::unique_ptr<CFXJSE_Context> CFXJSE_Context::Create(
v8::Isolate* pIsolate,
- const FXJSE_CLASS_DESCRIPTOR* lpGlobalClass,
- CFXJSE_HostObject* lpGlobalObject) {
+ const FXJSE_CLASS_DESCRIPTOR* pGlobalClass,
+ CFXJSE_HostObject* pGlobalObject) {
CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate);
- CFXJSE_Context* pContext = new CFXJSE_Context(pIsolate);
- CFXJSE_Class* lpGlobalClassObj = nullptr;
+ auto pContext = pdfium::MakeUnique<CFXJSE_Context>(pIsolate);
+ CFXJSE_Class* pGlobalClassObj = nullptr;
v8::Local<v8::ObjectTemplate> hObjectTemplate;
- if (lpGlobalClass) {
- lpGlobalClassObj = CFXJSE_Class::Create(pContext, lpGlobalClass, true);
- ASSERT(lpGlobalClassObj);
+ if (pGlobalClass) {
+ pGlobalClassObj = CFXJSE_Class::Create(pContext.get(), pGlobalClass, true);
+ ASSERT(pGlobalClassObj);
v8::Local<v8::FunctionTemplate> hFunctionTemplate =
v8::Local<v8::FunctionTemplate>::New(pIsolate,
- lpGlobalClassObj->m_hTemplate);
+ pGlobalClassObj->m_hTemplate);
hObjectTemplate = hFunctionTemplate->InstanceTemplate();
} else {
hObjectTemplate = v8::ObjectTemplate::New(pIsolate);
@@ -178,7 +180,7 @@ CFXJSE_Context* CFXJSE_Context::Create(
hNewContext->SetSecurityToken(hRootContext->GetSecurityToken());
v8::Local<v8::Object> hGlobalObject =
FXJSE_GetGlobalObjectFromContext(hNewContext);
- FXJSE_UpdateObjectBinding(hGlobalObject, lpGlobalObject);
+ FXJSE_UpdateObjectBinding(hGlobalObject, pGlobalObject);
pContext->m_hContext.Reset(pIsolate, hNewContext);
return pContext;
}
@@ -189,16 +191,32 @@ CFXJSE_Context::~CFXJSE_Context() {}
std::unique_ptr<CFXJSE_Value> CFXJSE_Context::GetGlobalObject() {
auto pValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
-
CFXJSE_ScopeUtil_IsolateHandleContext scope(this);
v8::Local<v8::Context> hContext =
v8::Local<v8::Context>::New(m_pIsolate, m_hContext);
v8::Local<v8::Object> hGlobalObject = hContext->Global();
pValue->ForceSetValue(hGlobalObject);
-
return pValue;
}
+v8::Local<v8::Context> CFXJSE_Context::GetContext() {
+ return v8::Local<v8::Context>::New(m_pIsolate, m_hContext);
+}
+
+void CFXJSE_Context::AddClass(std::unique_ptr<CFXJSE_Class> pClass) {
+ m_rgClasses.push_back(std::move(pClass));
+}
+
+CFXJSE_Class* CFXJSE_Context::GetClassByName(
+ const CFX_ByteStringC& szName) const {
+ auto pClass =
+ std::find_if(m_rgClasses.begin(), m_rgClasses.end(),
+ [szName](const std::unique_ptr<CFXJSE_Class>& item) {
+ return szName == item->m_szClassName;
+ });
+ return pClass != m_rgClasses.end() ? pClass->get() : nullptr;
+}
+
void CFXJSE_Context::EnableCompatibleMode() {
ExecuteScript(szCompatibleModeScript, nullptr, nullptr);
}