13 #define FIXED_ONE_BYTE_STRING(isolate, string) \
14 (node::OneByteString((isolate), (string), sizeof(string) - 1))
16 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
17 void operator=(const TypeName&) = delete; \
18 void operator=(TypeName&&) = delete; \
19 TypeName(const TypeName&) = delete; \
20 TypeName(TypeName&&) = delete
22 // Windows 8+ does not like abort() in Release mode
24 #define ABORT() raise(SIGABRT)
26 #define ABORT() abort()
30 # define ASSERT(expression)
31 # define CHECK(expression) \
33 if (!(expression)) ABORT(); \
36 # define ASSERT(expression) assert(expression)
37 # define CHECK(expression) assert(expression)
40 #define ASSERT_EQ(a, b) ASSERT((a) == (b))
41 #define ASSERT_GE(a, b) ASSERT((a) >= (b))
42 #define ASSERT_GT(a, b) ASSERT((a) > (b))
43 #define ASSERT_LE(a, b) ASSERT((a) <= (b))
44 #define ASSERT_LT(a, b) ASSERT((a) < (b))
45 #define ASSERT_NE(a, b) ASSERT((a) != (b))
47 #define CHECK_EQ(a, b) CHECK((a) == (b))
48 #define CHECK_GE(a, b) CHECK((a) >= (b))
49 #define CHECK_GT(a, b) CHECK((a) > (b))
50 #define CHECK_LE(a, b) CHECK((a) <= (b))
51 #define CHECK_LT(a, b) CHECK((a) < (b))
52 #define CHECK_NE(a, b) CHECK((a) != (b))
54 #define UNREACHABLE() ABORT()
56 // TAILQ-style intrusive list node.
61 using ListNodeMember = ListNode<T> T::*;
63 // VS 2013 doesn't understand dependent templates.
65 #define ListNodeMember(T) ListNodeMember
67 #define ListNodeMember(T) ListNodeMember<T>
70 // TAILQ-style intrusive list head.
71 template <typename T, ListNodeMember(T) M>
80 inline bool IsEmpty() const;
83 template <typename U, ListNodeMember(U) M> friend class ListHead;
86 DISALLOW_COPY_AND_ASSIGN(ListNode);
89 template <typename T, ListNodeMember(T) M>
94 inline T* operator*() const;
95 inline const Iterator& operator++();
96 inline bool operator!=(const Iterator& that) const;
99 friend class ListHead;
100 inline explicit Iterator(ListNode<T>* node);
104 inline ListHead() = default;
106 inline void MoveBack(ListHead* that);
107 inline void PushBack(T* element);
108 inline void PushFront(T* element);
109 inline bool IsEmpty() const;
110 inline T* PopFront();
111 inline Iterator begin() const;
112 inline Iterator end() const;
116 DISALLOW_COPY_AND_ASSIGN(ListHead);
119 // The helper is for doing safe downcasts from base types to derived types.
120 template <typename Inner, typename Outer>
121 class ContainerOfHelper {
123 inline ContainerOfHelper(Inner Outer::*field, Inner* pointer);
124 template <typename TypeName>
125 inline operator TypeName*() const;
127 Outer* const pointer_;
130 // Calculate the address of the outer (i.e. embedding) struct from
131 // the interior pointer to a data member.
132 template <typename Inner, typename Outer>
133 inline ContainerOfHelper<Inner, Outer> ContainerOf(Inner Outer::*field,
136 // If persistent.IsWeak() == false, then do not call persistent.Reset()
137 // while the returned Local<T> is still in scope, it will destroy the
138 // reference to the object.
139 template <class TypeName>
140 inline v8::Local<TypeName> PersistentToLocal(
141 v8::Isolate* isolate,
142 const v8::Persistent<TypeName>& persistent);
144 // Unchecked conversion from a non-weak Persistent<T> to Local<TLocal<T>,
147 // Do not call persistent.Reset() while the returned Local<T> is still in
148 // scope, it will destroy the reference to the object.
149 template <class TypeName>
150 inline v8::Local<TypeName> StrongPersistentToLocal(
151 const v8::Persistent<TypeName>& persistent);
153 template <class TypeName>
154 inline v8::Local<TypeName> WeakPersistentToLocal(
155 v8::Isolate* isolate,
156 const v8::Persistent<TypeName>& persistent);
158 // Convenience wrapper around v8::String::NewFromOneByte().
159 inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
163 // For the people that compile with -funsigned-char.
164 inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
165 const signed char* data,
168 inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
169 const unsigned char* data,
172 inline void Wrap(v8::Local<v8::Object> object, void* pointer);
174 inline void ClearWrap(v8::Local<v8::Object> object);
176 template <typename TypeName>
177 inline TypeName* Unwrap(v8::Local<v8::Object> object);
181 explicit Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> value);
192 const char* operator*() const {
196 size_t length() const {
208 #endif // SRC_UTIL_H_