Properly AdjustAmountOfExternalAllocatedMemory() in d8
This is related to v8 issue 2022 but doesn't fix it as this patch only affects d8, while there is a related bug in the WebKit V8 bindings too. Review URL: https://chromiumcodereview.appspot.com/9835055 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11144 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
59b06fd638
commit
3f7244e37b
15
src/d8.cc
15
src/d8.cc
@ -426,14 +426,20 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args,
|
||||
}
|
||||
|
||||
Persistent<Object> persistent_array = Persistent<Object>::New(array);
|
||||
persistent_array.MakeWeak(data, ExternalArrayWeakCallback);
|
||||
persistent_array.MarkIndependent();
|
||||
if (data == NULL && length != 0) {
|
||||
data = calloc(length, element_size);
|
||||
// Prepend the size of the allocated chunk to the data itself.
|
||||
int total_size = length * element_size + sizeof(size_t);
|
||||
data = malloc(total_size);
|
||||
if (data == NULL) {
|
||||
return ThrowException(String::New("Memory allocation failed."));
|
||||
}
|
||||
*reinterpret_cast<size_t*>(data) = total_size;
|
||||
data = reinterpret_cast<size_t*>(data) + 1;
|
||||
memset(data, 0, length * element_size);
|
||||
V8::AdjustAmountOfExternalAllocatedMemory(total_size);
|
||||
}
|
||||
persistent_array.MakeWeak(data, ExternalArrayWeakCallback);
|
||||
persistent_array.MarkIndependent();
|
||||
|
||||
array->SetIndexedPropertiesToExternalArrayData(
|
||||
reinterpret_cast<uint8_t*>(data) + offset, type,
|
||||
@ -452,6 +458,9 @@ void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) {
|
||||
Handle<Object> converted_object = object->ToObject();
|
||||
Local<Value> prop_value = converted_object->Get(prop_name);
|
||||
if (data != NULL && !prop_value->IsObject()) {
|
||||
data = reinterpret_cast<size_t*>(data) - 1;
|
||||
V8::AdjustAmountOfExternalAllocatedMemory(
|
||||
-(*reinterpret_cast<size_t*>(data)));
|
||||
free(data);
|
||||
}
|
||||
object.Dispose();
|
||||
|
Loading…
Reference in New Issue
Block a user