From 76a44dea318041f8229d80e70ca3568a435611eb Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 11 Jan 2017 08:58:35 -0500 Subject: Cleaning up memory allocation in CXFA_FM2JSContext - IV This CL removes the use of FX_Alloc and any remaining new'd CFXJSE_Value objects from CXFA_FM2JSContext and replaces them with unique_ptrs and vectors. Change-Id: I30ba697d65ee326d2faa895c3217bdc407419298 Reviewed-on: https://pdfium-review.googlesource.com/2157 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fxjs/cfxjse_value.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'fxjs/cfxjse_value.cpp') diff --git a/fxjs/cfxjse_value.cpp b/fxjs/cfxjse_value.cpp index 471d85cf76..68c82e5deb 100644 --- a/fxjs/cfxjse_value.cpp +++ b/fxjs/cfxjse_value.cpp @@ -102,16 +102,14 @@ void CFXJSE_Value::SetHostObject(CFXJSE_HostObject* lpObject, m_hValue.Reset(m_pIsolate, hObject); } -void CFXJSE_Value::SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues) { +void CFXJSE_Value::SetArray( + const std::vector>& values) { CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); - v8::Local hArrayObject = v8::Array::New(m_pIsolate, uValueCount); - if (rgValues) { - for (uint32_t i = 0; i < uValueCount; i++) { - if (rgValues[i]) { - hArrayObject->Set(i, v8::Local::New( - m_pIsolate, rgValues[i]->DirectGetValue())); - } - } + v8::Local hArrayObject = v8::Array::New(m_pIsolate, values.size()); + uint32_t count = 0; + for (auto& v : values) { + hArrayObject->Set(count++, v8::Local::New( + m_pIsolate, v.get()->DirectGetValue())); } m_hValue.Reset(m_pIsolate, hArrayObject); } -- cgit v1.2.3