Commit 8565d3e9 authored by jochen@chromium.org's avatar jochen@chromium.org

Remove deprecated Persistent::MakeWeak usage from V8

BUG=none
LOG=n
R=dcarney@chromium.org, ulan@chromium.org

Review URL: https://codereview.chromium.org/101523002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18227 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ee5726cd
...@@ -1097,16 +1097,22 @@ static char* ReadChars(Isolate* isolate, const char* name, int* size_out) { ...@@ -1097,16 +1097,22 @@ static char* ReadChars(Isolate* isolate, const char* name, int* size_out) {
return chars; return chars;
} }
static void ReadBufferWeakCallback(v8::Isolate* isolate,
Persistent<ArrayBuffer>* array_buffer, struct DataAndPersistent {
uint8_t* data) { uint8_t* data;
size_t byte_length = Persistent<ArrayBuffer> handle;
Local<ArrayBuffer>::New(isolate, *array_buffer)->ByteLength(); };
isolate->AdjustAmountOfExternalAllocatedMemory(
static void ReadBufferWeakCallback(
const v8::WeakCallbackData<ArrayBuffer, DataAndPersistent>& data) {
size_t byte_length = data.GetValue()->ByteLength();
data.GetIsolate()->AdjustAmountOfExternalAllocatedMemory(
-static_cast<intptr_t>(byte_length)); -static_cast<intptr_t>(byte_length));
delete[] data; delete[] data.GetParameter()->data;
array_buffer->Reset(); data.GetParameter()->handle.Reset();
delete data.GetParameter();
} }
...@@ -1120,16 +1126,18 @@ void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1120,16 +1126,18 @@ void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
} }
Isolate* isolate = args.GetIsolate(); Isolate* isolate = args.GetIsolate();
uint8_t* data = reinterpret_cast<uint8_t*>( DataAndPersistent* data = new DataAndPersistent;
data->data = reinterpret_cast<uint8_t*>(
ReadChars(args.GetIsolate(), *filename, &length)); ReadChars(args.GetIsolate(), *filename, &length));
if (data == NULL) { if (data->data == NULL) {
delete data;
Throw(args.GetIsolate(), "Error reading file"); Throw(args.GetIsolate(), "Error reading file");
return; return;
} }
Handle<v8::ArrayBuffer> buffer = ArrayBuffer::New(isolate, data, length); Handle<v8::ArrayBuffer> buffer = ArrayBuffer::New(isolate, data, length);
v8::Persistent<v8::ArrayBuffer> weak_handle(isolate, buffer); data->handle.Reset(isolate, buffer);
weak_handle.MakeWeak(data, ReadBufferWeakCallback); data->handle.SetWeak(data, ReadBufferWeakCallback);
weak_handle.MarkIndependent(); data->handle.MarkIndependent();
isolate->AdjustAmountOfExternalAllocatedMemory(length); isolate->AdjustAmountOfExternalAllocatedMemory(length);
args.GetReturnValue().Set(buffer); args.GetReturnValue().Set(buffer);
......
This diff is collapsed.
...@@ -1763,10 +1763,10 @@ bool HasWeakGlobalHandle() { ...@@ -1763,10 +1763,10 @@ bool HasWeakGlobalHandle() {
} }
static void PersistentHandleCallback(v8::Isolate* isolate, static void PersistentHandleCallback(
v8::Persistent<v8::Value>* handle, const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
void*) { data.GetParameter()->Reset();
handle->Reset(); delete data.GetParameter();
} }
...@@ -1776,8 +1776,9 @@ TEST(WeakGlobalHandle) { ...@@ -1776,8 +1776,9 @@ TEST(WeakGlobalHandle) {
CHECK(!HasWeakGlobalHandle()); CHECK(!HasWeakGlobalHandle());
v8::Persistent<v8::Object> handle(env->GetIsolate(), v8::Object::New()); v8::Persistent<v8::Object>* handle =
handle.MakeWeak<v8::Value, void>(NULL, PersistentHandleCallback); new v8::Persistent<v8::Object>(env->GetIsolate(), v8::Object::New());
handle->SetWeak(handle, PersistentHandleCallback);
CHECK(HasWeakGlobalHandle()); CHECK(HasWeakGlobalHandle());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment