1 /** 2 * Contents of this file are snippets from node.h and node.cc 3 * see http://www.nodejs.org/ 4 * 5 * Node's license follows: 6 * 7 * Copyright 2009, 2010 Ryan Lienhart Dahl. All rights reserved. 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to 10 * deal in the Software without restriction, including without limitation the 11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 12 * sell copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 */ 15 16 17 #ifndef MOCK_RIL_NODE_UTIL_H_ 18 #define MOCK_RIL_NODE_UTIL_H_ 19 20 #include <v8.h> 21 22 enum encoding {ASCII, UTF8, BINARY}; 23 24 enum encoding ParseEncoding(v8::Handle<v8::Value> encoding_v, 25 enum encoding _default = BINARY); 26 27 void FatalException(v8::TryCatch &try_catch); 28 29 v8::Local<v8::Value> Encode(const void *buf, size_t len, 30 enum encoding encoding = BINARY); 31 32 // returns bytes written. 33 ssize_t DecodeWrite(char *buf, 34 size_t buflen, 35 v8::Handle<v8::Value>, 36 enum encoding encoding = BINARY); 37 38 #define SET_PROTOTYPE_METHOD(templ, name, callback) \ 39 do { \ 40 v8::Local<v8::Signature> __callback##_SIG = v8::Signature::New(templ); \ 41 v8::Local<v8::FunctionTemplate> __callback##_TEM = \ 42 v8::FunctionTemplate::New(callback, v8::Handle<v8::Value>(), \ 43 __callback##_SIG); \ 44 templ->PrototypeTemplate()->Set(v8::String::NewSymbol(name), \ 45 __callback##_TEM); \ 46 } while (0) 47 48 #define SET_METHOD(obj, name, callback) \ 49 obj->Set(v8::String::NewSymbol(name), \ 50 v8::FunctionTemplate::New(callback)->GetFunction()) 51 52 53 #endif // MOCK_RIL_NODE_UTIL_H_ 54