Reviewers: dcarney,
https://codereview.chromium.org/16102002/diff/1/include/v8.h
File include/v8.h (right):
https://codereview.chromium.org/16102002/diff/1/include/v8.h#newcode5688
include/v8.h:5688: void ReturnValue<T>::Set(const Persistent<S>& handle)
{
On 2013/05/27 12:34:36, dcarney wrote:
you need the correct type check here
and a test to make sure the type_cast is called correctly
Done.
Description:
Add template parameter to ReturnValue::Set.
E.g., v8-i18n wants to set the return value with a different type of a
Persistent.
BUG=NONE
Please review this at https://codereview.chromium.org/16102002/
SVN Base: git://github.com/v8/v8.git@master
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
7dfc9189aa307198416f02c8f804c10d1653adbe..769f89ac16cf8760cc5890396e2f9d486d654a97
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2779,8 +2779,8 @@ class ReturnValue {
public:
V8_INLINE(explicit ReturnValue(internal::Object** slot));
// Handle setters
- V8_INLINE(void Set(const Persistent<T>& handle));
- V8_INLINE(void Set(const Handle<T> handle));
+ template <typename S> V8_INLINE(void Set(const Persistent<S>& handle));
+ template <typename S> V8_INLINE(void Set(const Handle<S> handle));
// Fast primitive setters
V8_INLINE(void Set(Isolate* isolate, bool value));
V8_INLINE(void Set(Isolate* isolate, double i));
@@ -5684,12 +5684,16 @@ template<typename T>
ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
template<typename T>
-void ReturnValue<T>::Set(const Persistent<T>& handle) {
+template<typename S>
+void ReturnValue<T>::Set(const Persistent<S>& handle) {
+ TYPE_CHECK(T, S);
*value_ = *reinterpret_cast<internal::Object**>(*handle);
}
template<typename T>
-void ReturnValue<T>::Set(const Handle<T> handle) {
+template<typename S>
+void ReturnValue<T>::Set(const Handle<S> handle) {
+ TYPE_CHECK(T, S);
*value_ = *reinterpret_cast<internal::Object**>(*handle);
}
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
2e5cce6b2f1e25c497813f35e5b3706e85ef2246..bde1709cc1601770c13d8a947a6ca6df940f66c4
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1115,6 +1115,30 @@ THREADED_TEST(FastReturnValues) {
}
+void SubclassedReturnValueCallback(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().Set(Object::New());
+}
+
+Handle<Value> TestSubclassedReturnValuesHelper() {
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ v8::Handle<v8::ObjectTemplate> object_template =
v8::ObjectTemplate::New();
+ v8::FunctionCallback callback = &SubclassedReturnValueCallback;
+ object_template->Set("callback", v8::FunctionTemplate::New(callback));
+ v8::Local<v8::Object> object = object_template->NewInstance();
+ (*env)->Global()->Set(v8_str("callback_object"), object);
+ return scope.Close(CompileRun("callback_object.callback()"));
+}
+
+THREADED_TEST(SubclassedReturnValues) {
+ v8::HandleScope scope(v8::Isolate::GetCurrent());
+ v8::Handle<v8::Value> value;
+ value = TestSubclassedReturnValuesHelper();
+ CHECK(value->IsObject());
+}
+
+
THREADED_TEST(FunctionTemplateSetLength) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
--
--
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.