From f3fecc0c686418272e49c8d51da2cb12e80bd1a2 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 30 Apr 2015 14:30:29 -0700 Subject: Provide an array buffer allocator to V8. This allows PDFium to work with current V8, so unpin v8 in the pdfium DEPS file. (I also re-ordered one field in CJS_Runtime, just to put two bools together (may pack tighter), and to put all the v8 stuff together). BUG=pdfium:146 R=thestig@chromium.org Review URL: https://codereview.chromium.org/1118043002 --- DEPS | 2 +- fpdfsdk/include/javascript/JS_Runtime.h | 20 ++++++++++++++------ fpdfsdk/src/javascript/JS_Runtime.cpp | 23 +++++++++++++++++++---- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/DEPS b/DEPS index 66f4d20b4e..7bd073d1bd 100644 --- a/DEPS +++ b/DEPS @@ -14,7 +14,7 @@ deps = { "https://chromium.googlesource.com/external/googletest.git@8245545b6dc9c4703e6496d1efd19e975ad2b038", "v8": - "https://chromium.googlesource.com/v8/v8.git@6988aec61f071a1caec96abae1cf39353a234455", + "https://chromium.googlesource.com/v8/v8.git", "v8/third_party/icu": "https://chromium.googlesource.com/chromium/deps/icu46", diff --git a/fpdfsdk/include/javascript/JS_Runtime.h b/fpdfsdk/include/javascript/JS_Runtime.h index a1f62b8d0f..5326db693d 100644 --- a/fpdfsdk/include/javascript/JS_Runtime.h +++ b/fpdfsdk/include/javascript/JS_Runtime.h @@ -7,6 +7,7 @@ #ifndef _JS_RUNTIME_H_ #define _JS_RUNTIME_H_ +#include "../../../third_party/base/nonstd_unique_ptr.h" #include "../../../core/include/fxcrt/fx_basic.h" #include "../jsapi/fxjs_v8.h" #include "IJavaScript.h" @@ -14,6 +15,12 @@ class CJS_Context; +class CJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { + void* Allocate(size_t length) override; + void* AllocateUninitialized(size_t length) override; + void Free(void* data, size_t length) override; +}; + class CJS_FieldEvent { public: @@ -53,15 +60,16 @@ public: v8::Handle NewJSContext(); protected: - CFX_ArrayTemplate m_ContextArray; - CPDFDoc_Environment * m_pApp; - CPDFSDK_Document * m_pDocument; + CFX_ArrayTemplate m_ContextArray; + CPDFDoc_Environment* m_pApp; + CPDFSDK_Document* m_pDocument; FX_BOOL m_bBlocking; + FX_BOOL m_bRegistered; CJS_FieldEvent* m_pFieldEventPath; - v8::Isolate* m_isolate; - v8::Persistent m_context; - FX_BOOL m_bRegistered; + v8::Isolate* m_isolate; + nonstd::unique_ptr m_pArrayBufferAllocator; + v8::Persistent m_context; }; #endif //_JS_RUNTIME_H_ diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp index 4ff3c0bc98..e2f50067e6 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -91,17 +91,32 @@ 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 ------------------------------ */ 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 = v8::Isolate::New(); - //m_isolate->Enter(); + m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); + + v8::Isolate::CreateParams params; + params.array_buffer_allocator = m_pArrayBufferAllocator.get(); + m_isolate = v8::Isolate::New(params); InitJSObjects(); -- cgit v1.2.3