Chromium Code Reviews| Index: src/d8.cc |
| diff --git a/src/d8.cc b/src/d8.cc |
| index b95432e269b5d767c809b22004e82270c39d7852..f683af25640d6a3afce2e2eea97929f8bab38999 100644 |
| --- a/src/d8.cc |
| +++ b/src/d8.cc |
| @@ -1048,6 +1048,16 @@ static char* ReadChars(Isolate* isolate, const char* name, int* size_out) { |
| return chars; |
| } |
| +static void ReadBufferWeakCallback(v8::Isolate* isolate, |
| + Persistent<Value>* object, |
| + uint8_t* data) { |
| + size_t byte_length = ArrayBuffer::Cast(**object)->ByteLength(); |
| + isolate->AdjustAmountOfExternalAllocatedMemory( |
| + -static_cast<intptr_t>(byte_length)); |
| + |
| + delete[] data; |
| + object->Dispose(isolate); |
| +} |
| Handle<Value> Shell::ReadBuffer(const Arguments& args) { |
| ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT |
| @@ -1057,14 +1067,19 @@ Handle<Value> Shell::ReadBuffer(const Arguments& args) { |
| return Throw("Error loading file"); |
| } |
| + Isolate* isolate = args.GetIsolate(); |
| uint8_t* data = reinterpret_cast<uint8_t*>( |
| ReadChars(args.GetIsolate(), *filename, &length)); |
| if (data == NULL) { |
| return Throw("Error reading file"); |
| } |
| - Handle<v8::ArrayBuffer> buffer = ArrayBuffer::New(length); |
| - memcpy(buffer->Data(), data, length); |
| - delete[] data; |
| + Handle<v8::ArrayBuffer> buffer = ArrayBuffer::New(data, length); |
| + v8::Persistent<v8::Value> weak_handle = |
| + v8::Persistent<v8::Value>::New(isolate, buffer); |
| + weak_handle.MakeWeak(isolate, data, ReadBufferWeakCallback); |
| + weak_handle.MarkIndependent(isolate); |
|
Sven Panne
2013/05/23 07:57:01
IIRC, dcarney wants to move to a non-Isolate versi
Dmitry Lomov (no reviews)
2013/05/23 08:42:15
Done.
|
| + isolate->AdjustAmountOfExternalAllocatedMemory(length); |
| + |
| return buffer; |
| } |