Reviewers: Jakob,
Description:
ReturnValue::Set needs to check for empty handles
[email protected]
BUG=
Please review this at https://codereview.chromium.org/16073010/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M include/v8.h
M test/cctest/test-api.cc
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
e19f5861366bf3ec06e15b666e07f77740f990de..3fef9cdd80f4d6597d0a684f56a576f514ee70ae
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -5665,14 +5665,22 @@ template<typename T>
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>
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
2eb47adf1102a4df3b77ef8246620fb13685c5c0..9eecf945b4d3f991d969b5f53857693a5c8c0b3f
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1029,6 +1029,7 @@ static const double kFastReturnValueDouble = 2.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 @@ void FastReturnValueCallback<void>(
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 @@ THREADED_TEST(FastReturnValues) {
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.