Commit 851972d6 authored by eostroukhov's avatar eostroukhov Committed by Commit bot

[DevTools] Compatibility with older STL libraries

One of the clients need to support Mac OS X version 10.7, which means that Clang compiler that support C++11 is used but the application is linked against pre-C++11 libstdc++.

Following changes were made:
1. std::unique_ptr got a new copy ctor that take a const ref - this
   allows for the pointer to be put into STL containers that do not
   support rvalue references.
2. cbegin/cend functions are no longer used.
3. Paths were changed and conditional macros were adjusted.

BUG=628794
R=pfeldman@chromium.org

Review-Url: https://codereview.chromium.org/2150333003
Cr-Commit-Position: refs/heads/master@{#406103}
parent 433fb76e
......@@ -7,7 +7,7 @@
#include <cstddef>
#if V8_INSPECTOR_USE_OLD_STL
#if defined(__APPLE__) && !defined(_LIBCPP_VERSION)
#include <map>
#include <set>
......@@ -33,7 +33,7 @@ template <class Key> using HashSet = std::unordered_set<Key>;
} // namespace protocol
} // namespace blink
#endif // V8_INSPECTOR_USE_STL
#endif // defined(__APPLE__) && !defined(_LIBCPP_VERSION)
// Macro that returns a compile time constant with the length of an array, but gives an error if passed a non-array.
template<typename T, std::size_t Size> char (&ArrayLengthHelperFunction(T (&)[Size]))[Size];
......
......@@ -122,6 +122,7 @@ public:
unique_ptr() : m_ptr(nullptr) {}
unique_ptr(std::nullptr_t) : m_ptr(nullptr) {}
unique_ptr(const unique_ptr&);
unique_ptr(unique_ptr&&);
template <typename U, typename = typename enable_if<is_convertible<U*, T*>::value>::type> unique_ptr(unique_ptr<U>&&);
......@@ -134,7 +135,10 @@ public:
PtrType get() const { return m_ptr; }
void reset(PtrType = nullptr);
PtrType release();
PtrType release()
{
return this->internalRelease();
}
ValueType& operator*() const { DCHECK(m_ptr); return *m_ptr; }
PtrType operator->() const { DCHECK(m_ptr); return m_ptr; }
......@@ -146,7 +150,7 @@ public:
unique_ptr& operator=(std::nullptr_t) { reset(); return *this; }
unique_ptr& operator=(const unique_ptr&);
unique_ptr& operator=(unique_ptr&&);
template <typename U> unique_ptr& operator=(unique_ptr<U>&&);
......@@ -157,6 +161,12 @@ public:
explicit unique_ptr(PtrType ptr) : m_ptr(ptr) {}
private:
PtrType internalRelease() const
{
PtrType ptr = m_ptr;
m_ptr = nullptr;
return ptr;
}
// We should never have two unique_ptrs for the same underlying object
// (otherwise we'll get double-destruction), so these equality operators
......@@ -172,7 +182,7 @@ private:
return false;
}
PtrType m_ptr;
mutable PtrType m_ptr;
};
......@@ -180,16 +190,10 @@ template <typename T> inline void unique_ptr<T>::reset(PtrType ptr)
{
PtrType p = m_ptr;
m_ptr = ptr;
DCHECK(!p || m_ptr != p);
OwnedPtrDeleter<T>::deletePtr(p);
}
template <typename T> inline typename unique_ptr<T>::PtrType unique_ptr<T>::release()
{
PtrType ptr = m_ptr;
m_ptr = nullptr;
return ptr;
}
template <typename T> inline typename unique_ptr<T>::ValueType& unique_ptr<T>::operator[](std::ptrdiff_t i) const
{
static_assert(is_array<T>::value, "elements access is possible for arrays only");
......@@ -198,8 +202,13 @@ template <typename T> inline typename unique_ptr<T>::ValueType& unique_ptr<T>::o
return m_ptr[i];
}
template <typename T> inline unique_ptr<T>::unique_ptr(const unique_ptr<T>& o)
: m_ptr(o.internalRelease())
{
}
template <typename T> inline unique_ptr<T>::unique_ptr(unique_ptr<T>&& o)
: m_ptr(o.release())
: m_ptr(o.internalRelease())
{
}
......@@ -210,13 +219,15 @@ template <typename U, typename> inline unique_ptr<T>::unique_ptr(unique_ptr<U>&&
static_assert(!is_array<T>::value, "pointers to array must never be converted");
}
template <typename T> inline unique_ptr<T>& unique_ptr<T>::operator=(unique_ptr<T>&& o)
template <typename T> inline unique_ptr<T>& unique_ptr<T>::operator=(const unique_ptr<T>& o)
{
PtrType ptr = m_ptr;
m_ptr = o.release();
DCHECK(!ptr || m_ptr != ptr);
OwnedPtrDeleter<T>::deletePtr(ptr);
reset(o.internalRelease());
return *this;
}
template <typename T> inline unique_ptr<T>& unique_ptr<T>::operator=(unique_ptr<T>&& o)
{
reset(o.internalRelease());
return *this;
}
......
......@@ -243,6 +243,7 @@ public:
};
} // namespace WTF
#if !defined(__APPLE__) || defined(_LIBCPP_VERSION)
namespace std {
template<> struct hash<String16> {
......@@ -254,6 +255,8 @@ template<> struct hash<String16> {
} // namespace std
#endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION)
using String = WTF::String;
#endif // !defined(String16STL_h)
......@@ -445,7 +445,7 @@ bool V8DebuggerAgentImpl::isCallFrameWithUnknownScriptOrBlackboxed(JavaScriptCal
return false;
const std::vector<std::pair<int, int>>& ranges = itBlackboxedPositions->second;
auto itRange = std::lower_bound(ranges.cbegin(), ranges.cend(),
auto itRange = std::lower_bound(ranges.begin(), ranges.end(),
std::make_pair(frame->line(), frame->column()), positionComparator);
// Ranges array contains positions in script where blackbox state is changed.
// [(0,0) ... ranges[0]) isn't blackboxed, [ranges[0] ... ranges[1]) is blackboxed...
......
......@@ -879,7 +879,7 @@ void V8DebuggerImpl::disconnect(V8InspectorSessionImpl* session)
InspectedContext* V8DebuggerImpl::getContext(int groupId, int contextId) const
{
ContextsByGroupMap::const_iterator contextGroupIt = m_contexts.find(groupId);
if (contextGroupIt == m_contexts.cend())
if (contextGroupIt == m_contexts.end())
return nullptr;
ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId);
......
......@@ -57,8 +57,8 @@
['debug_devtools=="node"', {
# Node build
'jinja_module_files': [
'../../deps/jinja2/jinja2/__init__.py',
'../../deps/markupsafe/markupsafe/__init__.py', # jinja2 dep
'../../../jinja2/jinja2/__init__.py',
'../../../markupsafe/markupsafe/__init__.py', # jinja2 dep
],
}, {
'jinja_module_files': [
......@@ -145,8 +145,8 @@
],
'include_dirs': [
'../..',
'../../../v8/include',
'../../../v8',
'../../../../../v8/include',
'../../../../../v8',
'<(SHARED_INTERMEDIATE_DIR)/blink',
],
'sources': [
......@@ -238,8 +238,8 @@
'public/V8StackTrace.h',
'public/V8ToProtocolValue.h',
'<(blink_platform_output_dir/v8_inspector/DebuggerScript.h',
'<(blink_platform_output_dir/v8_inspector/InjectedScriptSource.h',
'<(blink_platform_output_dir)/v8_inspector/DebuggerScript.h',
'<(blink_platform_output_dir)/v8_inspector/InjectedScriptSource.h',
],
},
], # targets
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment