Revision: 14898
Author:   [email protected]
Date:     Fri May 31 04:06:50 2013
Log:      ReturnValue::Set needs to check for empty handles

[email protected]
BUG=

Review URL: https://codereview.chromium.org/16073010
http://code.google.com/p/v8/source/detail?r=14898

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Wed May 29 05:40:21 2013
+++ /branches/bleeding_edge/include/v8.h        Fri May 31 04:06:50 2013
@@ -5665,14 +5665,22 @@
 template<typename S>
 void ReturnValue<T>::Set(const Persistent<S>& handle) {
   TYPE_CHECK(T, S);
-  *value_ = *reinterpret_cast<internal::Object**>(*handle);
+  if (V8_UNLIKELY(handle.IsEmpty())) {
+    SetUndefined();
+  } else {
+    *value_ = *reinterpret_cast<internal::Object**>(*handle);
+  }
 }

 template<typename T>
 template<typename S>
 void ReturnValue<T>::Set(const Handle<S> handle) {
   TYPE_CHECK(T, S);
-  *value_ = *reinterpret_cast<internal::Object**>(*handle);
+  if (V8_UNLIKELY(handle.IsEmpty())) {
+    SetUndefined();
+  } else {
+    *value_ = *reinterpret_cast<internal::Object**>(*handle);
+  }
 }

 template<typename T>
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Wed May 29 05:40:21 2013
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Fri May 31 04:06:50 2013
@@ -1029,6 +1029,7 @@
 // variable return values
 static bool fast_return_value_bool = false;
 static bool fast_return_value_void_is_null = false;
+static bool fast_return_value_object_is_empty = false;

 template<>
 void FastReturnValueCallback<int32_t>(
@@ -1072,7 +1073,9 @@
 template<>
 void FastReturnValueCallback<Object>(
     const v8::FunctionCallbackInfo<v8::Value>& info) {
-  info.GetReturnValue().Set(Object::New());
+  v8::Handle<v8::Object> object;
+  if (!fast_return_value_object_is_empty) object = Object::New();
+  info.GetReturnValue().Set(object);
 }

 template<typename T>
@@ -1119,8 +1122,13 @@
       CHECK(value->IsUndefined());
     }
   }
+  // check handles
+  fast_return_value_object_is_empty = false;
   value = TestFastReturnValues<Object>();
   CHECK(value->IsObject());
+  fast_return_value_object_is_empty = true;
+  value = TestFastReturnValues<Object>();
+  CHECK(value->IsUndefined());
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to