add_realloc.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Shelley Vohr <[email protected]>
  3. Date: Mon, 22 Oct 2018 10:47:11 -0700
  4. Subject: add_realloc.patch
  5. Blink overrides ArrayBuffer's allocator with its own one, while Node simply
  6. uses malloc and free, so we need to use v8's allocator in Node. As part of the
  7. 10.6.0 upgrade, we needed to make SerializerDelegate accept an allocator
  8. argument in its constructor, and override ReallocateBufferMemory and
  9. FreeBufferMemory to use the allocator. We cannot simply allocate and then memcpy
  10. when we override ReallocateBufferMemory, so we therefore need to implement
  11. Realloc on the v8 side.
  12. diff --git a/include/v8.h b/include/v8.h
  13. index 32687d90b5f96f68975a0d773dfd95ac1ed28943..e5e5e4733b1562b1dbb6c0ddc5397ee3a8f1ace1 100644
  14. --- a/include/v8.h
  15. +++ b/include/v8.h
  16. @@ -5131,6 +5131,13 @@ class V8_EXPORT ArrayBuffer : public Object {
  17. */
  18. virtual void* AllocateUninitialized(size_t length) = 0;
  19. + /**
  20. + * Free the memory block of size |length|, pointed to by |data|.
  21. + * That memory must be previously allocated by |Allocate| and not yet freed
  22. + * with a call to |Free| or |Realloc|
  23. + */
  24. + virtual void* Realloc(void* data, size_t length);
  25. +
  26. /**
  27. * Free the memory block of size |length|, pointed to by |data|.
  28. * That memory is guaranteed to be previously allocated by |Allocate|.
  29. diff --git a/src/api/api.cc b/src/api/api.cc
  30. index b49ad728a8e4d57f69d8228207f4280251fbd448..561e9888d4c71b6ef9ee45c581f5071a55a422c0 100644
  31. --- a/src/api/api.cc
  32. +++ b/src/api/api.cc
  33. @@ -536,6 +536,10 @@ void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) {
  34. i::V8::SetSnapshotBlob(snapshot_blob);
  35. }
  36. +void* v8::ArrayBuffer::Allocator::Realloc(void* data, size_t length) {
  37. + UNIMPLEMENTED();
  38. +}
  39. +
  40. namespace {
  41. class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {