Reviewers: dcarney,

Description:
Prevent calls to ReturnValue::Set with pointer-valued types.
  [2nd try, after the previous version broke the build]

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.

(Said error was fixed/removed in crrev.com/267393002.)


Why was crrev.com/240013004 reverted?
The orginal version compiled fine on gcc (+ MSVC), but not on clang.
There's no clang try-bots, but the ASAN-based buildbots used clang
and hence the build broke. I'm slightly unsure on why, but clang -
unlike those other compilers - eagerly compiled the non-compilable
setter, which predictably broke. Now, the non-compilable setter uses
the same template logic that all other, comparable cases use. I've
tried 'make qc' with both gcc and clang versions.

BUG=

Please review this at https://codereview.chromium.org/279883002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+11, -0 lines):
  M include/v8.h


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 72dc75d42a057086cf17b24c6503a6fbe424e29a..f4ae71d43cfc2d679b9c76b210b5861d14858a69 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2429,6 +2429,10 @@ class ReturnValue {
   // Convenience getter for Isolate
   V8_INLINE Isolate* GetIsolate();

+  // Pointer setter: Uncompilable to prevent inadvertent misuse.
+  template <typename S>
+  V8_INLINE void Set(S* whatever);
+
  private:
   template<class F> friend class ReturnValue;
   template<class F> friend class FunctionCallbackInfo;
@@ -5974,6 +5978,13 @@ Isolate* ReturnValue<T>::GetIsolate() {
 }

 template<typename T>
+template<typename S>
+void ReturnValue<T>::Set(S* whatever) {
+  // Uncompilable to prevent inadvertent misuse.
+  TYPE_CHECK(S*, Primitive);
+}
+
+template<typename T>
 internal::Object* ReturnValue<T>::GetDefaultValue() {
   // Default value is always the pointer below value_ on the stack.
   return value_[-1];


--
--
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.

Reply via email to