From d2cc1b90fe1ffd3162bb685a3f120f867220b5e9 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 30 Apr 2015 15:19:03 -0700 Subject: Merge to XFA: Fix V8 array buffer allocator. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1118143003 --- fpdfsdk/src/javascript/JS_Runtime.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'fpdfsdk/src') diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp index 4b4328c701..2ad5667b2e 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -93,17 +93,36 @@ void CJS_RuntimeFactory::ReleaseGlobalData() } } +void* CJS_ArrayBufferAllocator::Allocate(size_t length) { + return calloc(1, length); +} + +void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { + return malloc(length); +} + +void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { + free(data); +} + /* ------------------------------ CJS_Runtime ------------------------------ */ extern v8::Persistent& _getGlobalObjectTemplate(IJS_Runtime* pJSRuntime); CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pDocument(NULL), m_bBlocking(FALSE), - m_pFieldEventPath(NULL), - m_bRegistered(FALSE) + m_bRegistered(FALSE), + m_pFieldEventPath(NULL) { - m_isolate = FPDFXFA_GetApp()->GetJSERuntime()?(v8::Isolate*)FPDFXFA_GetApp()->GetJSERuntime():v8::Isolate::New(); - //m_isolate->Enter(); + if (FPDFXFA_GetApp()->GetJSERuntime()) { + m_isolate = (v8::Isolate*)FPDFXFA_GetApp()->GetJSERuntime(); + } else { + m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); + v8::Isolate::CreateParams params; + params.array_buffer_allocator = m_pArrayBufferAllocator.get(); + m_isolate = v8::Isolate::New(params); + } + v8::Isolate* isolate = m_isolate; v8::Isolate::Scope isolate_scope(isolate); v8::Locker locker(isolate); -- cgit v1.2.3