Revision: 21217
Author: [email protected]
Date: Fri May 9 12:07:38 2014 UTC
Log: Prevent calls to ReturnValue::Set with pointer-valued types.
Currently, this code will compile:
SomePointer* p = ...;
ReturnValue r = ...;
r.Set(p);
What happens is that ReturnValue::Set has no pointer-ish overloads, but
a bool one, and hence C++ will convert the pointer to a bool and use
the Set(bool) overload. In other words, the example above is equivalent
to: r.Set(p ? true : false); Which probably isn't what the author had
in mind. This change adds a Set(void*) overload whose body forces a
compile error, to prevent this from happening inadvertently. The only
use of this indeed turned out to be an error.
(Wait for issue 364025 before submitting.)
BUG=
[email protected]
Review URL: https://codereview.chromium.org/240013004
http://code.google.com/p/v8/source/detail?r=21217
Modified:
/branches/bleeding_edge/include/v8.h
=======================================
--- /branches/bleeding_edge/include/v8.h Fri May 9 08:38:27 2014 UTC
+++ /branches/bleeding_edge/include/v8.h Fri May 9 12:07:38 2014 UTC
@@ -2429,6 +2429,9 @@
// Convenience getter for Isolate
V8_INLINE Isolate* GetIsolate();
+ // Pointer setter: Uncompilable to prevent inadvertent misuse.
+ void Set(void* whatever);
+
private:
template<class F> friend class ReturnValue;
template<class F> friend class FunctionCallbackInfo;
@@ -5972,6 +5975,12 @@
// Isolate is always the pointer below the default value on the stack.
return *reinterpret_cast<Isolate**>(&value_[-2]);
}
+
+template<typename T>
+void ReturnValue<T>::Set(void* whatever) {
+ // Uncompilable to prevent inadvertent misuse.
+ TYPE_CHECK(void*, Primitive);
+}
template<typename T>
internal::Object* ReturnValue<T>::GetDefaultValue() {
--
--
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/d/optout.