Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Unified Diff: src/runtime.cc

Issue 15001041: Externalization API for ArrayBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 61b3549ddebf8d07db91bf6aafc405381e3e444b..30042757d5788d0fe3b42b3e536fb876207c3975 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -658,28 +658,38 @@ static void ArrayBufferWeakCallback(v8::Isolate* external_isolate,
Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate);
HandleScope scope(isolate);
Handle<Object> internal_object = Utils::OpenHandle(**object);
+ Handle<JSArrayBuffer> array_buffer(JSArrayBuffer::cast(*internal_object));
- size_t allocated_length = NumberToSize(
- isolate, JSArrayBuffer::cast(*internal_object)->byte_length());
- isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
- -static_cast<intptr_t>(allocated_length));
- if (data != NULL)
- free(data);
+ if (!array_buffer->is_external()) {
+ size_t allocated_length = NumberToSize(
+ isolate, array_buffer->byte_length());
+ isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
+ -static_cast<intptr_t>(allocated_length));
+ if (data != NULL)
Sven Panne 2013/05/23 07:57:01 No need for this guard here, either.
Dmitry Lomov (no reviews) 2013/05/23 08:42:15 Done.
+ free(data);
+ }
object->Dispose(external_isolate);
}
-bool Runtime::SetupArrayBuffer(Isolate* isolate,
+void Runtime::SetupArrayBuffer(Isolate* isolate,
Handle<JSArrayBuffer> array_buffer,
+ bool is_external,
void* data,
size_t allocated_length) {
+ ASSERT(array_buffer->GetInternalFieldCount() ==
+ v8::ArrayBuffer::kInternalFieldCount);
+ for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) {
+ array_buffer->SetInternalField(i, Smi::FromInt(0));
+ }
array_buffer->set_backing_store(data);
+ array_buffer->set_flag(Smi::FromInt(0));
+ array_buffer->set_is_external(is_external);
Handle<Object> byte_length =
isolate->factory()->NewNumberFromSize(allocated_length);
CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber());
array_buffer->set_byte_length(*byte_length);
- return true;
}
@@ -696,8 +706,7 @@ bool Runtime::SetupArrayBufferAllocatingData(
data = NULL;
}
- if (!SetupArrayBuffer(isolate, array_buffer, data, allocated_length))
- return false;
+ SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length);
v8::Isolate* external_isolate = reinterpret_cast<v8::Isolate*>(isolate);
v8::Persistent<v8::Value> weak_handle = v8::Persistent<v8::Value>::New(

Powered by Google App Engine
This is Rietveld 408576698