// Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to permit // persons to whom the Software is furnished to do so, subject to the // following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. #ifndef SRC_UTIL_H_ #define SRC_UTIL_H_ #include "v8.h" #include #include #include namespace node { #define OFFSET_OF(TypeName, Field) \ (reinterpret_cast(&(reinterpret_cast(8)->Field)) - 8) #define CONTAINER_OF(Pointer, TypeName, Field) \ reinterpret_cast( \ reinterpret_cast(Pointer) - OFFSET_OF(TypeName, Field)) #define FIXED_ONE_BYTE_STRING(isolate, string) \ (node::OneByteString((isolate), (string), sizeof(string) - 1)) #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ void operator=(const TypeName&); \ TypeName(const TypeName&) #if defined(NDEBUG) # define ASSERT(expression) # define CHECK(expression) \ do { \ if (!(expression)) abort(); \ } while (0) # define CHECK_EQ(a, b) CHECK((a) == (b)) # define CHECK_NE(a, b) CHECK((a) != (b)) #else # define ASSERT(expression) assert(expression) # define CHECK(expression) assert(expression) # define CHECK_EQ(a, b) assert((a) == (b)) # define CHECK_NE(a, b) assert((a) != (b)) #endif #define UNREACHABLE() abort() // If persistent.IsWeak() == false, then do not call persistent.Dispose() // while the returned Local is still in scope, it will destroy the // reference to the object. template inline v8::Local PersistentToLocal( v8::Isolate* isolate, const v8::Persistent& persistent); // Unchecked conversion from a non-weak Persistent to Local, // use with care! // // Do not call persistent.Dispose() while the returned Local is still in // scope, it will destroy the reference to the object. template inline v8::Local StrongPersistentToLocal( const v8::Persistent& persistent); template inline v8::Local WeakPersistentToLocal( v8::Isolate* isolate, const v8::Persistent& persistent); // Convenience wrapper around v8::String::NewFromOneByte(). inline v8::Local OneByteString(v8::Isolate* isolate, const char* data, int length = -1); // For the people that compile with -funsigned-char. inline v8::Local OneByteString(v8::Isolate* isolate, const signed char* data, int length = -1); inline v8::Local OneByteString(v8::Isolate* isolate, const unsigned char* data, int length = -1); inline void Wrap(v8::Local object, void* pointer); template inline TypeName* Unwrap(v8::Local object); } // namespace node #endif // SRC_UTIL_H_