Merge branch 'master' into chrome31

Conflicts:
	common/atom_version.h
This commit is contained in:
Cheng Zhao 2013-12-17 12:58:25 +08:00
commit a4715f936b
7 changed files with 42 additions and 12 deletions

View file

@ -5,8 +5,37 @@
#ifndef ATOM_COMMON_SWAP_OR_ASSIGN_H_
#define ATOM_COMMON_SWAP_OR_ASSIGN_H_
#include "base/compiler_specific.h"
namespace internal {
#if defined(OS_WIN)
template<typename T> inline
void SwapOrAssign(T& v1, const T& v2) {
__if_exists(T::swap) {
v1.swap(const_cast<T&>(v2));
}
__if_not_exists(T::swap) {
v1 = v2;
}
}
template<typename T> inline
void SwapOrAssign(T*& v1, T* v2) {
v1 = v2;
}
inline
void SwapOrAssign(int& v1, int v2) {
v1 = v2;
}
inline
void SwapOrAssign(bool& v1, bool v2) {
v1 = v2;
}
#else // defined(OS_WIN)
// Helper to detect whether value has specified method.
template <typename T>
class HasSwapMethod {
@ -24,17 +53,18 @@ struct enable_if {};
template<class T>
struct enable_if<true, T> { typedef T type; };
template<typename T>
template<typename T> inline
typename enable_if<HasSwapMethod<T>::value>::type SwapOrAssign(
T& v1, const T& v2) {
v1.swap(const_cast<T&>(v2));
}
template<typename T>
template<typename T> inline
typename enable_if<!HasSwapMethod<T>::value>::type SwapOrAssign(
T& v1, const T& v2) {
v1 = v2;
}
#endif // !defined(OS_WIN)
} // namespace internal

View file

@ -239,7 +239,7 @@ bool FromV8Arguments(const v8::FunctionCallbackInfo<v8::Value>& args,
if (!V8ValueCanBeConvertedTo<T1>(args[index]))
return false;
internal::SwapOrAssign(*value,
static_cast<const T1&>(FromV8Value(args[index])));
FromV8Value(args[index]).operator T1());
return true;
}