summaryrefslogtreecommitdiff
path: root/xfa/fxjse
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxjse')
-rw-r--r--xfa/fxjse/class.cpp13
-rw-r--r--xfa/fxjse/context.cpp7
-rw-r--r--xfa/fxjse/context.h19
-rw-r--r--xfa/fxjse/runtime.cpp25
-rw-r--r--xfa/fxjse/runtime.h4
5 files changed, 34 insertions, 34 deletions
diff --git a/xfa/fxjse/class.cpp b/xfa/fxjse/class.cpp
index d6744a6112..d5c9b2debc 100644
--- a/xfa/fxjse/class.cpp
+++ b/xfa/fxjse/class.cpp
@@ -305,16 +305,15 @@ CFXJSE_Class* CFXJSE_Class::Create(CFXJSE_Context* lpContext,
const_cast<FXJSE_CLASS*>(lpClassDefinition))));
}
pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate);
- lpContext->m_rgClasses.Add(pClass);
+ lpContext->m_rgClasses.push_back(std::unique_ptr<CFXJSE_Class>(pClass));
return pClass;
}
+
CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext,
const CFX_ByteStringC& szName) {
- for (int count = pContext->m_rgClasses.GetSize(), i = 0; i < count; i++) {
- CFXJSE_Class* pClass = pContext->m_rgClasses[i];
- if (pClass->m_szClassName == szName) {
- return pClass;
- }
+ for (const auto& pClass : pContext->m_rgClasses) {
+ if (pClass->m_szClassName == szName)
+ return pClass.get();
}
- return NULL;
+ return nullptr;
}
diff --git a/xfa/fxjse/context.cpp b/xfa/fxjse/context.cpp
index 9a6b9120a2..9d478295d6 100644
--- a/xfa/fxjse/context.cpp
+++ b/xfa/fxjse/context.cpp
@@ -155,11 +155,8 @@ CFXJSE_Context* CFXJSE_Context::Create(v8::Isolate* pIsolate,
return pContext;
}
-CFXJSE_Context::~CFXJSE_Context() {
- for (int32_t i = 0, count = m_rgClasses.GetSize(); i < count; i++)
- delete m_rgClasses[i];
- m_rgClasses.RemoveAll();
-}
+CFXJSE_Context::CFXJSE_Context(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {}
+CFXJSE_Context::~CFXJSE_Context() {}
void CFXJSE_Context::GetGlobalObject(CFXJSE_Value* pValue) {
ASSERT(pValue);
diff --git a/xfa/fxjse/context.h b/xfa/fxjse/context.h
index 75973f2a66..0092aac7f3 100644
--- a/xfa/fxjse/context.h
+++ b/xfa/fxjse/context.h
@@ -7,6 +7,9 @@
#ifndef XFA_FXJSE_CONTEXT_H_
#define XFA_FXJSE_CONTEXT_H_
+#include <memory>
+#include <vector>
+
#include "core/fxcrt/include/fx_basic.h"
#include "v8/include/v8.h"
#include "xfa/fxjse/include/fxjse.h"
@@ -15,33 +18,33 @@ class CFXJSE_Class;
class CFXJSE_Value;
class CFXJSE_Context {
- protected:
- CFXJSE_Context(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {}
-
public:
static CFXJSE_Context* Create(v8::Isolate* pIsolate,
- const FXJSE_CLASS* lpGlobalClass = NULL,
- void* lpGlobalObject = NULL);
+ const FXJSE_CLASS* lpGlobalClass = nullptr,
+ void* lpGlobalObject = nullptr);
~CFXJSE_Context();
+
V8_INLINE v8::Isolate* GetRuntime(void) { return m_pIsolate; }
void GetGlobalObject(CFXJSE_Value* pValue);
FX_BOOL ExecuteScript(const FX_CHAR* szScript,
CFXJSE_Value* lpRetValue,
- CFXJSE_Value* lpNewThisObject = NULL);
+ CFXJSE_Value* lpNewThisObject = nullptr);
protected:
CFXJSE_Context();
CFXJSE_Context(const CFXJSE_Context&);
+ explicit CFXJSE_Context(v8::Isolate* pIsolate);
CFXJSE_Context& operator=(const CFXJSE_Context&);
- protected:
v8::Global<v8::Context> m_hContext;
v8::Isolate* m_pIsolate;
- CFX_ArrayTemplate<CFXJSE_Class*> m_rgClasses;
+ std::vector<std::unique_ptr<CFXJSE_Class>> m_rgClasses;
+
friend class CFXJSE_Class;
friend class CFXJSE_ScopeUtil_IsolateHandleContext;
friend class CFXJSE_ScopeUtil_IsolateHandleRootOrNormalContext;
};
+
v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate,
v8::TryCatch& trycatch);
diff --git a/xfa/fxjse/runtime.cpp b/xfa/fxjse/runtime.cpp
index 7b62174899..1ee6c18599 100644
--- a/xfa/fxjse/runtime.cpp
+++ b/xfa/fxjse/runtime.cpp
@@ -6,6 +6,8 @@
#include "xfa/fxjse/runtime.h"
+#include <algorithm>
+
#include "fpdfsdk/jsapi/include/fxjs_v8.h"
#include "xfa/fxjse/scope_inline.h"
@@ -99,30 +101,27 @@ CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) {
return pData->m_pFXJSERuntimeData;
}
-CFXJSE_RuntimeList* CFXJSE_RuntimeData::g_RuntimeList = NULL;
+CFXJSE_RuntimeList* CFXJSE_RuntimeData::g_RuntimeList = nullptr;
+
void CFXJSE_RuntimeList::AppendRuntime(v8::Isolate* pIsolate) {
- m_RuntimeList.Add(pIsolate);
+ m_RuntimeList.push_back(pIsolate);
}
void CFXJSE_RuntimeList::RemoveRuntime(
v8::Isolate* pIsolate,
CFXJSE_RuntimeList::RuntimeDisposeCallback lpfnDisposeCallback) {
- int32_t iIdx = m_RuntimeList.Find(pIsolate, 0);
- if (iIdx >= 0) {
- m_RuntimeList.RemoveAt(iIdx, 1);
- }
- if (lpfnDisposeCallback) {
+ auto it = std::find(m_RuntimeList.begin(), m_RuntimeList.end(), pIsolate);
+ if (it != m_RuntimeList.end())
+ m_RuntimeList.erase(it);
+ if (lpfnDisposeCallback)
lpfnDisposeCallback(pIsolate);
- }
}
void CFXJSE_RuntimeList::RemoveAllRuntimes(
CFXJSE_RuntimeList::RuntimeDisposeCallback lpfnDisposeCallback) {
- int32_t iSize = m_RuntimeList.GetSize();
if (lpfnDisposeCallback) {
- for (int32_t iIdx = 0; iIdx < iSize; iIdx++) {
- lpfnDisposeCallback(m_RuntimeList[iIdx]);
- }
+ for (v8::Isolate* pIsolate : m_RuntimeList)
+ lpfnDisposeCallback(pIsolate);
}
- m_RuntimeList.RemoveAll();
+ m_RuntimeList.clear();
}
diff --git a/xfa/fxjse/runtime.h b/xfa/fxjse/runtime.h
index 43629e3771..1240089be4 100644
--- a/xfa/fxjse/runtime.h
+++ b/xfa/fxjse/runtime.h
@@ -7,6 +7,8 @@
#ifndef XFA_FXJSE_RUNTIME_H_
#define XFA_FXJSE_RUNTIME_H_
+#include <vector>
+
#include "core/fxcrt/include/fx_basic.h"
#include "v8/include/v8.h"
@@ -45,7 +47,7 @@ class CFXJSE_RuntimeList {
void RemoveAllRuntimes(RuntimeDisposeCallback lpfnDisposeCallback);
protected:
- CFX_ArrayTemplate<v8::Isolate*> m_RuntimeList;
+ std::vector<v8::Isolate*> m_RuntimeList;
};
#endif // XFA_FXJSE_RUNTIME_H_