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

Unified Diff: src/runtime.cc

Issue 15001041: Externalization API for ArrayBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback 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
« include/v8.h ('K') | « src/runtime.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 64573df4747eb8de8472e0c1869c9a3372002d62..36cd206913c6e70cfc5d02f3ff57653201a4b420 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -658,28 +658,37 @@ 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)
+ if (!array_buffer->is_external()) {
+ size_t allocated_length = NumberToSize(
+ isolate, array_buffer->byte_length());
+ isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
+ -static_cast<intptr_t>(allocated_length));
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 +705,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(
« include/v8.h ('K') | « src/runtime.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698