Commit ccc8e4e4 authored by dcarney's avatar dcarney Committed by Commit bot

prepare to deprecate non phantom weak callbacks

BUG=

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

Cr-Commit-Position: refs/heads/master@{#28046}
parent ae7ce701
......@@ -1130,13 +1130,14 @@ static char* ReadChars(Isolate* isolate, const char* name, int* size_out) {
struct DataAndPersistent {
uint8_t* data;
Persistent<ArrayBuffer> handle;
int byte_length;
Global<ArrayBuffer> handle;
};
static void ReadBufferWeakCallback(
const v8::WeakCallbackData<ArrayBuffer, DataAndPersistent>& data) {
size_t byte_length = data.GetValue()->ByteLength();
const v8::WeakCallbackInfo<DataAndPersistent>& data) {
int byte_length = data.GetParameter()->byte_length;
data.GetIsolate()->AdjustAmountOfExternalAllocatedMemory(
-static_cast<intptr_t>(byte_length));
......@@ -1164,10 +1165,12 @@ void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
Throw(args.GetIsolate(), "Error reading file");
return;
}
data->byte_length = length;
Handle<v8::ArrayBuffer> buffer =
ArrayBuffer::New(isolate, data->data, length);
data->handle.Reset(isolate, buffer);
data->handle.SetWeak(data, ReadBufferWeakCallback);
data->handle.SetWeak(data, ReadBufferWeakCallback,
v8::WeakCallbackType::kParameter);
data->handle.MarkIndependent();
isolate->AdjustAmountOfExternalAllocatedMemory(length);
......
This diff is collapsed.
......@@ -2031,9 +2031,8 @@ bool HasWeakGlobalHandle() {
static void PersistentHandleCallback(
const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
const v8::WeakCallbackInfo<v8::Persistent<v8::Object> >& data) {
data.GetParameter()->Reset();
delete data.GetParameter();
}
......@@ -2045,7 +2044,8 @@ TEST(WeakGlobalHandle) {
v8::Persistent<v8::Object> handle(env->GetIsolate(),
v8::Object::New(env->GetIsolate()));
handle.SetWeak(&handle, PersistentHandleCallback);
handle.SetWeak(&handle, PersistentHandleCallback,
v8::WeakCallbackType::kParameter);
CHECK(HasWeakGlobalHandle());
}
......
......@@ -4470,13 +4470,11 @@ TEST(NextCodeLinkIsWeak2) {
static bool weak_ic_cleared = false;
static void ClearWeakIC(const v8::WeakCallbackData<v8::Object, void>& data) {
static void ClearWeakIC(
const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
printf("clear weak is called\n");
weak_ic_cleared = true;
v8::Persistent<v8::Value>* p =
reinterpret_cast<v8::Persistent<v8::Value>*>(data.GetParameter());
CHECK(p->IsNearDeath());
p->Reset();
data.GetParameter()->Reset();
}
......@@ -4507,7 +4505,7 @@ TEST(WeakFunctionInConstructor) {
garbage.Reset(isolate, CompileRun(source)->ToObject(isolate));
}
weak_ic_cleared = false;
garbage.SetWeak(static_cast<void*>(&garbage), &ClearWeakIC);
garbage.SetWeak(&garbage, &ClearWeakIC, v8::WeakCallbackType::kParameter);
Heap* heap = CcTest::i_isolate()->heap();
heap->CollectAllGarbage();
CHECK(weak_ic_cleared);
......@@ -4546,7 +4544,7 @@ void CheckWeakness(const char* source) {
garbage.Reset(isolate, CompileRun(source)->ToObject(isolate));
}
weak_ic_cleared = false;
garbage.SetWeak(static_cast<void*>(&garbage), &ClearWeakIC);
garbage.SetWeak(&garbage, &ClearWeakIC, v8::WeakCallbackType::kParameter);
Heap* heap = CcTest::i_isolate()->heap();
heap->CollectAllGarbage();
CHECK(weak_ic_cleared);
......
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