From ee4b9b552dee37ed5844da6c261e4d28a33d3c13 Mon Sep 17 00:00:00 2001 From: Timothy J Fontaine Date: Mon, 17 Mar 2014 10:19:47 -0700 Subject: [PATCH] test: update our branched weakref to v8 3.24 --- test/gc/node_modules/weak/src/weakref.cc | 58 +++++++++++------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/test/gc/node_modules/weak/src/weakref.cc b/test/gc/node_modules/weak/src/weakref.cc index dd527937fd..548a224a83 100644 --- a/test/gc/node_modules/weak/src/weakref.cc +++ b/test/gc/node_modules/weak/src/weakref.cc @@ -39,7 +39,6 @@ using v8::Persistent; using v8::PropertyCallbackInfo; using v8::Value; using v8::String; -using v8::ThrowException; using v8::TryCatch; typedef struct proxy_container { @@ -84,6 +83,13 @@ Handle GetCallbacks(Handle proxy) { if (!dead) obj = Unwrap(info.This()); \ +void ThrowTypeError(Isolate* isolate, const char* message) { + HandleScope scope(isolate); + Local emessage = String::NewFromUtf8(isolate, message); + isolate->ThrowException(v8::Exception::TypeError(emessage)); +} + + void WeakNamedPropertyGetter(Local property, const PropertyCallbackInfo& info) { UNWRAP @@ -146,19 +152,18 @@ void WeakPropertyEnumerator(const PropertyCallbackInfo& info) { } -void AddCallback(Handle proxy, Handle callback) { +void AddCallback(Isolate* isolate, Handle proxy, Handle callback) { Handle callbacks = GetCallbacks(proxy); - callbacks->Set(Integer::New(callbacks->Length()), callback); + callbacks->Set(Integer::New(isolate, callbacks->Length()), callback); } -void TargetCallback(Isolate* isolate, - Persistent* ptarget, - proxy_container* cont) { +static void TargetCallback(const v8::WeakCallbackData& data) { + Isolate* isolate = data.GetIsolate(); HandleScope scope(isolate); - Local target = Local::New(isolate, *ptarget); - assert((*ptarget).IsNearDeath()); + Local target = data.GetValue(); + proxy_container* cont = data.GetParameter(); // invoke any listening callbacks Local callbacks = Local::New(isolate, cont->callbacks); @@ -168,7 +173,7 @@ void TargetCallback(Isolate* isolate, for (uint32_t i=0; i cb = Handle::Cast( - callbacks->Get(Integer::New(i))); + callbacks->Get(Integer::New(isolate, i))); TryCatch try_catch; @@ -179,12 +184,9 @@ void TargetCallback(Isolate* isolate, } } - cont->proxy.Dispose(); - cont->proxy.Clear(); - cont->target.Dispose(); - cont->target.Clear(); - cont->callbacks.Dispose(); - cont->callbacks.Clear(); + cont->proxy.Reset(); + cont->target.Reset(); + cont->callbacks.Reset(); delete cont; } @@ -193,8 +195,7 @@ void Create(const FunctionCallbackInfo& args) { HandleScope scope(args.GetIsolate()); if (!args[0]->IsObject()) { - Local message = String::New("Object expected"); - ThrowException(Exception::TypeError(message)); + ThrowTypeError(args.GetIsolate(), "Object expected"); return; } @@ -207,11 +208,11 @@ void Create(const FunctionCallbackInfo& args) { cont->proxy.Reset(Isolate::GetCurrent(), proxy); cont->target.Reset(isolate, args[0].As()); - cont->callbacks.Reset(isolate, Array::New()); - cont->target.MakeWeak(cont, TargetCallback); + cont->callbacks.Reset(isolate, Array::New(args.GetIsolate())); + cont->target.SetWeak(cont, TargetCallback); if (args.Length() >= 2) { - AddCallback(proxy, Handle::Cast(args[1])); + AddCallback(args.GetIsolate(), proxy, Handle::Cast(args[1])); } args.GetReturnValue().Set(proxy); @@ -233,8 +234,7 @@ void Get(const FunctionCallbackInfo& args) { HandleScope scope(args.GetIsolate()); if (!isWeakRef(args[0])) { - Local message = String::New("Weakref instance expected"); - ThrowException(Exception::TypeError(message)); + ThrowTypeError(args.GetIsolate(), "Weakref instance expected"); return; } @@ -249,8 +249,7 @@ void IsNearDeath(const FunctionCallbackInfo& args) { HandleScope scope(args.GetIsolate()); if (!isWeakRef(args[0])) { - Local message = String::New("Weakref instance expected"); - ThrowException(Exception::TypeError(message)); + ThrowTypeError(args.GetIsolate(), "Weakref instance expected"); return; } @@ -266,8 +265,7 @@ void IsDead(const FunctionCallbackInfo& args) { HandleScope scope(args.GetIsolate()); if (!isWeakRef(args[0])) { - Local message = String::New("Weakref instance expected"); - ThrowException(Exception::TypeError(message)); + ThrowTypeError(args.GetIsolate(), "Weakref instance expected"); return; } @@ -280,21 +278,19 @@ void AddCallback(const FunctionCallbackInfo& args) { HandleScope scope(args.GetIsolate()); if (!isWeakRef(args[0])) { - Local message = String::New("Weakref instance expected"); - ThrowException(Exception::TypeError(message)); + ThrowTypeError(args.GetIsolate(), "Weakref instance expected"); return; } Local proxy = args[0]->ToObject(); - AddCallback(proxy, Handle::Cast(args[1])); + AddCallback(args.GetIsolate(), proxy, Handle::Cast(args[1])); } void Callbacks(const FunctionCallbackInfo& args) { HandleScope scope(args.GetIsolate()); if (!isWeakRef(args[0])) { - Local message = String::New("Weakref instance expected"); - ThrowException(Exception::TypeError(message)); + ThrowTypeError(args.GetIsolate(), "Weakref instance expected"); return; }