1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #define OFFSET_OF(TypeName, Field) \
33 (reinterpret_cast<uintptr_t>(&(reinterpret_cast<TypeName*>(8)->Field)) - 8)
35 #define CONTAINER_OF(Pointer, TypeName, Field) \
36 reinterpret_cast<TypeName*>( \
37 reinterpret_cast<uintptr_t>(Pointer) - OFFSET_OF(TypeName, Field))
39 #define FIXED_ONE_BYTE_STRING(isolate, string) \
40 (node::OneByteString((isolate), (string), sizeof(string) - 1))
42 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
43 void operator=(const TypeName&); \
44 TypeName(const TypeName&)
47 # define ASSERT(expression)
48 # define CHECK(expression) \
50 if (!(expression)) abort(); \
53 # define ASSERT(expression) assert(expression)
54 # define CHECK(expression) assert(expression)
57 #define CHECK_EQ(a, b) CHECK((a) == (b))
58 #define CHECK_NE(a, b) CHECK((a) != (b))
60 #define UNREACHABLE() abort()
62 // If persistent.IsWeak() == false, then do not call persistent.Reset()
63 // while the returned Local<T> is still in scope, it will destroy the
64 // reference to the object.
65 template <class TypeName>
66 inline v8::Local<TypeName> PersistentToLocal(
68 const v8::Persistent<TypeName>& persistent);
70 // Unchecked conversion from a non-weak Persistent<T> to Local<TLocal<T>,
73 // Do not call persistent.Reset() while the returned Local<T> is still in
74 // scope, it will destroy the reference to the object.
75 template <class TypeName>
76 inline v8::Local<TypeName> StrongPersistentToLocal(
77 const v8::Persistent<TypeName>& persistent);
79 template <class TypeName>
80 inline v8::Local<TypeName> WeakPersistentToLocal(
82 const v8::Persistent<TypeName>& persistent);
84 // Convenience wrapper around v8::String::NewFromOneByte().
85 inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
89 // For the people that compile with -funsigned-char.
90 inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
91 const signed char* data,
94 inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
95 const unsigned char* data,
98 inline void Wrap(v8::Local<v8::Object> object, void* pointer);
100 template <typename TypeName>
101 inline TypeName* Unwrap(v8::Local<v8::Object> object);
105 #endif // SRC_UTIL_H_