summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/JS_Value.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-08-08 09:49:42 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-08 09:49:42 -0700
commite5aff74a43a2c3355a8b7699a47d0fb7f23b243e (patch)
treecaa9e0f3dffc91bfdf7b753171353b4ae9c5370a /fpdfsdk/javascript/JS_Value.cpp
parent660de3c494b68a574cb4cdf20359f51ddc260d3c (diff)
downloadpdfium-e5aff74a43a2c3355a8b7699a47d0fb7f23b243e.tar.xz
Remove backpointer to runtime from CJS_Array.
This is always available elsewhere, so save the bytes and ease removal of CJS_Array since it now only contains a single v8 local. Review-Url: https://codereview.chromium.org/2217253002
Diffstat (limited to 'fpdfsdk/javascript/JS_Value.cpp')
-rw-r--r--fpdfsdk/javascript/JS_Value.cpp44
1 files changed, 19 insertions, 25 deletions
diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp
index 9d65c79a1b..ab81aa0b46 100644
--- a/fpdfsdk/javascript/JS_Value.cpp
+++ b/fpdfsdk/javascript/JS_Value.cpp
@@ -73,10 +73,9 @@ CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr)
operator=(pStr);
}
-CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Array& array)
- : m_pJSRuntime(pRuntime) {
- operator=(array);
-}
+CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array)
+ : m_pValue(array.ToV8Array(pRuntime->GetIsolate())),
+ m_pJSRuntime(pRuntime) {}
CJS_Value::~CJS_Value() {}
@@ -192,11 +191,6 @@ void CJS_Value::operator=(const FX_CHAR* pStr) {
operator=(CFX_WideString::FromLocal(pStr).c_str());
}
-void CJS_Value::operator=(const CJS_Array& array) {
- ASSERT(m_pJSRuntime == array.GetJSRuntime());
- m_pValue = array.ToV8Array();
-}
-
void CJS_Value::operator=(const CJS_Date& date) {
ASSERT(m_pJSRuntime == date.GetJSRuntime());
m_pValue = FXJS_NewDate(m_pJSRuntime->GetIsolate(), date.ToDouble());
@@ -360,7 +354,7 @@ void CJS_PropValue::operator>>(CJS_Array& array) const {
void CJS_PropValue::operator<<(CJS_Array& array) {
ASSERT(!m_bIsSetting);
- CJS_Value::operator=(array);
+ m_pValue = array.ToV8Array(m_pJSRuntime->GetIsolate());
}
void CJS_PropValue::operator>>(CJS_Date& date) const {
@@ -373,30 +367,30 @@ void CJS_PropValue::operator<<(CJS_Date& date) {
CJS_Value::operator=(date);
}
-CJS_Array::CJS_Array(CJS_Runtime* pRuntime) : m_pJSRuntime(pRuntime) {}
-
-CJS_Array::~CJS_Array() {}
+CJS_Array::CJS_Array() {}
CJS_Array::CJS_Array(const CJS_Array& other) = default;
+CJS_Array::~CJS_Array() {}
+
void CJS_Array::Attach(v8::Local<v8::Array> pArray) {
m_pArray = pArray;
}
-void CJS_Array::GetElement(unsigned index, CJS_Value& value) const {
- if (m_pArray.IsEmpty())
- return;
- v8::Local<v8::Value> p =
- FXJS_GetArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index);
- value.Attach(p);
+void CJS_Array::GetElement(v8::Isolate* pIsolate,
+ unsigned index,
+ CJS_Value& value) const {
+ if (!m_pArray.IsEmpty())
+ value.Attach(FXJS_GetArrayElement(pIsolate, m_pArray, index));
}
-void CJS_Array::SetElement(unsigned index, CJS_Value value) {
+void CJS_Array::SetElement(v8::Isolate* pIsolate,
+ unsigned index,
+ const CJS_Value& value) {
if (m_pArray.IsEmpty())
- m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate());
+ m_pArray = FXJS_NewArray(pIsolate);
- FXJS_PutArrayElement(m_pJSRuntime->GetIsolate(), m_pArray, index,
- value.ToV8Value());
+ FXJS_PutArrayElement(pIsolate, m_pArray, index, value.ToV8Value());
}
int CJS_Array::GetLength() const {
@@ -405,9 +399,9 @@ int CJS_Array::GetLength() const {
return FXJS_GetArrayLength(m_pArray);
}
-v8::Local<v8::Array> CJS_Array::ToV8Array() const {
+v8::Local<v8::Array> CJS_Array::ToV8Array(v8::Isolate* pIsolate) const {
if (m_pArray.IsEmpty())
- m_pArray = FXJS_NewArray(m_pJSRuntime->GetIsolate());
+ m_pArray = FXJS_NewArray(pIsolate);
return m_pArray;
}