diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-04-30 15:19:03 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-04-30 15:19:03 -0700 |
commit | d2cc1b90fe1ffd3162bb685a3f120f867220b5e9 (patch) | |
tree | d3004cd4b3e7c1296fbbdacc7cd68c6c4473655a /fpdfsdk | |
parent | 134eb282dfaf1e3903979d397db6433966837687 (diff) | |
download | pdfium-d2cc1b90fe1ffd3162bb685a3f120f867220b5e9.tar.xz |
Merge to XFA: Fix V8 array buffer allocator.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1118143003
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/include/javascript/JS_Runtime.h | 20 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Runtime.cpp | 27 |
2 files changed, 37 insertions, 10 deletions
diff --git a/fpdfsdk/include/javascript/JS_Runtime.h b/fpdfsdk/include/javascript/JS_Runtime.h index 86d49713a8..07e4e43c84 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: @@ -57,15 +64,16 @@ public: virtual FX_BOOL GetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue); virtual FX_BOOL SetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue); protected: - CFX_ArrayTemplate<CJS_Context *> m_ContextArray; - CPDFDoc_Environment * m_pApp; - CPDFSDK_Document * m_pDocument; + CFX_ArrayTemplate<CJS_Context*> 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<v8::Context> m_context; - FX_BOOL m_bRegistered; + v8::Isolate* m_isolate; + nonstd::unique_ptr<CJS_ArrayBufferAllocator> m_pArrayBufferAllocator; + v8::Persistent<v8::Context> m_context; }; #endif //_JS_RUNTIME_H_ 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<v8::ObjectTemplate>& _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); |