|
5 | 5 | #include "node_http_parser.h" |
6 | 6 | #include "node_javascript.h" |
7 | 7 | #include "node_version.h" |
| 8 | +#include "node_internals.h" |
8 | 9 |
|
9 | 10 | #if defined HAVE_PERFCTR |
10 | 11 | #include "node_counters.h" |
@@ -147,6 +148,8 @@ static uv_async_t dispatch_debug_messages_async; |
147 | 148 | static Isolate* node_isolate = nullptr; |
148 | 149 | static v8::Platform* default_platform; |
149 | 150 |
|
| 151 | +bool using_old_buffer = false; |
| 152 | + |
150 | 153 | class ArrayBufferAllocator : public ArrayBuffer::Allocator { |
151 | 154 | public: |
152 | 155 | // Impose an upper limit to avoid out of memory errors that bring down |
@@ -166,23 +169,17 @@ ArrayBufferAllocator ArrayBufferAllocator::the_singleton; |
166 | 169 |
|
167 | 170 |
|
168 | 171 | void* ArrayBufferAllocator::Allocate(size_t length) { |
169 | | - if (length > kMaxLength) |
170 | | - return nullptr; |
171 | | - char* data = new char[length]; |
172 | | - memset(data, 0, length); |
173 | | - return data; |
| 172 | + return calloc(length, 1); |
174 | 173 | } |
175 | 174 |
|
176 | 175 |
|
177 | 176 | void* ArrayBufferAllocator::AllocateUninitialized(size_t length) { |
178 | | - if (length > kMaxLength) |
179 | | - return nullptr; |
180 | | - return new char[length]; |
| 177 | + return malloc(length); |
181 | 178 | } |
182 | 179 |
|
183 | 180 |
|
184 | 181 | void ArrayBufferAllocator::Free(void* data, size_t length) { |
185 | | - delete[] static_cast<char*>(data); |
| 182 | + free(data); |
186 | 183 | } |
187 | 184 |
|
188 | 185 |
|
@@ -2836,6 +2833,11 @@ void SetupProcessObject(Environment* env, |
2836 | 2833 | READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate())); |
2837 | 2834 | } |
2838 | 2835 |
|
| 2836 | + // --use-old_buffer |
| 2837 | + if (using_old_buffer) { |
| 2838 | + READONLY_PROPERTY(process, "useOldBuffer", True(env->isolate())); |
| 2839 | + } |
| 2840 | + |
2839 | 2841 | size_t exec_path_len = 2 * PATH_MAX; |
2840 | 2842 | char* exec_path = new char[exec_path_len]; |
2841 | 2843 | Local<String> exec_path_value; |
@@ -3067,6 +3069,7 @@ static void PrintHelp() { |
3067 | 3069 | " --track-heap-objects track heap object allocations for heap " |
3068 | 3070 | "snapshots\n" |
3069 | 3071 | " --v8-options print v8 command line options\n" |
| 3072 | + " --use-old-buffer Revert to old Buffer implementation\n" |
3070 | 3073 | #if defined(NODE_HAVE_I18N_SUPPORT) |
3071 | 3074 | " --icu-data-dir=dir set ICU data load path to dir\n" |
3072 | 3075 | " (overrides NODE_ICU_DATA)\n" |
@@ -3204,6 +3207,10 @@ static void ParseArgs(int* argc, |
3204 | 3207 | #endif |
3205 | 3208 | } else if (strcmp(arg, "--expose-internals") == 0 || |
3206 | 3209 | strcmp(arg, "--expose_internals") == 0) { |
| 3210 | + } else if (strcmp(arg, "--use-old-buffer") == 0 || |
| 3211 | + strcmp(arg, "--use_old_buffer") == 0) { |
| 3212 | + using_old_buffer = true; |
| 3213 | + |
3207 | 3214 | // consumed in js |
3208 | 3215 | } else { |
3209 | 3216 | // V8 option. Pass through as-is. |
|