@@ -91,6 +91,7 @@ extern char **environ;
91
91
namespace node {
92
92
93
93
using v8::Array;
94
+ using v8::ArrayBuffer;
94
95
using v8::Boolean ;
95
96
using v8::Context;
96
97
using v8::Exception;
@@ -204,6 +205,35 @@ static uv_async_t emit_debug_enabled_async;
204
205
Isolate* node_isolate = NULL ;
205
206
206
207
208
+ class ArrayBufferAllocator : public ArrayBuffer ::Allocator {
209
+ public:
210
+ // Impose an upper limit to avoid out of memory errors that bring down
211
+ // the process.
212
+ static const size_t kMaxLength = 0x3fffffff ;
213
+ static ArrayBufferAllocator the_singleton;
214
+ virtual ~ArrayBufferAllocator () {}
215
+ virtual void * Allocate (size_t length);
216
+ virtual void Free (void * data);
217
+ private:
218
+ ArrayBufferAllocator () {}
219
+ ArrayBufferAllocator (const ArrayBufferAllocator&);
220
+ void operator =(const ArrayBufferAllocator&);
221
+ };
222
+
223
+ ArrayBufferAllocator ArrayBufferAllocator::the_singleton;
224
+
225
+
226
+ void * ArrayBufferAllocator::Allocate (size_t length) {
227
+ if (length > kMaxLength ) return NULL ;
228
+ return new char [length];
229
+ }
230
+
231
+
232
+ void ArrayBufferAllocator::Free (void * data) {
233
+ delete[] static_cast <char *>(data);
234
+ }
235
+
236
+
207
237
static void CheckImmediate (uv_check_t * handle, int status) {
208
238
assert (handle == &check_immediate_watcher);
209
239
assert (status == 0 );
@@ -2924,6 +2954,10 @@ char** Init(int argc, char *argv[]) {
2924
2954
}
2925
2955
V8::SetFlagsFromCommandLine (&v8argc, v8argv, false );
2926
2956
2957
+ const char typed_arrays_flag[] = " --harmony_typed_arrays" ;
2958
+ V8::SetFlagsFromString (typed_arrays_flag, sizeof (typed_arrays_flag) - 1 );
2959
+ V8::SetArrayBufferAllocator (&ArrayBufferAllocator::the_singleton);
2960
+
2927
2961
// Fetch a reference to the main isolate, so we have a reference to it
2928
2962
// even when we need it to access it from another (debugger) thread.
2929
2963
node_isolate = Isolate::GetCurrent ();
0 commit comments