Merge to XFA: Fix V8 array buffer allocator.
[pdfium.git] / xfa / src / fxjse / src / runtime.cpp
index c4dc61c..d880606 100644 (file)
@@ -8,6 +8,21 @@
 #include "fxv8.h"\r
 #include "runtime.h"\r
 #include "scope_inline.h"\r
+\r
+// Duplicates fpdfsdk's JS_Runtime.h, but keeps XFA from depending on it.\r
+// TODO(tsepez): make a single version of this.\r
+class FXJSE_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {\r
+    void* Allocate(size_t length) override {\r
+        return calloc(1, length);\r
+    }\r
+    void* AllocateUninitialized(size_t length) override {\r
+        return malloc(length);\r
+    }\r
+    void Free(void* data, size_t length) override {\r
+        free(data);\r
+    }\r
+};\r
+\r
 static void FXJSE_KillV8()\r
 {\r
     v8::V8::Dispose();\r
@@ -51,7 +66,9 @@ void FXJSE_Finalize()
 }\r
 FXJSE_HRUNTIME FXJSE_Runtime_Create()\r
 {\r
-    v8::Isolate* pIsolate = v8::Isolate::New();\r
+    v8::Isolate::CreateParams params;\r
+    params.array_buffer_allocator = new FXJSE_ArrayBufferAllocator();\r
+    v8::Isolate* pIsolate = v8::Isolate::New(params);\r
     ASSERT(pIsolate && CFXJSE_RuntimeData::g_RuntimeList);\r
     CFXJSE_RuntimeData::g_RuntimeList->AppendRuntime(pIsolate);\r
     return reinterpret_cast<FXJSE_HRUNTIME>(pIsolate);\r