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 --- xfa/src/fxjse/src/runtime.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'xfa/src') diff --git a/xfa/src/fxjse/src/runtime.cpp b/xfa/src/fxjse/src/runtime.cpp index c4dc61c249..d880606551 100644 --- a/xfa/src/fxjse/src/runtime.cpp +++ b/xfa/src/fxjse/src/runtime.cpp @@ -8,6 +8,21 @@ #include "fxv8.h" #include "runtime.h" #include "scope_inline.h" + +// Duplicates fpdfsdk's JS_Runtime.h, but keeps XFA from depending on it. +// TODO(tsepez): make a single version of this. +class FXJSE_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { + void* Allocate(size_t length) override { + return calloc(1, length); + } + void* AllocateUninitialized(size_t length) override { + return malloc(length); + } + void Free(void* data, size_t length) override { + free(data); + } +}; + static void FXJSE_KillV8() { v8::V8::Dispose(); @@ -51,7 +66,9 @@ void FXJSE_Finalize() } FXJSE_HRUNTIME FXJSE_Runtime_Create() { - v8::Isolate* pIsolate = v8::Isolate::New(); + v8::Isolate::CreateParams params; + params.array_buffer_allocator = new FXJSE_ArrayBufferAllocator(); + v8::Isolate* pIsolate = v8::Isolate::New(params); ASSERT(pIsolate && CFXJSE_RuntimeData::g_RuntimeList); CFXJSE_RuntimeData::g_RuntimeList->AppendRuntime(pIsolate); return reinterpret_cast(pIsolate); -- cgit v1.2.3