The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.
Please select the desired protocol below to get the URL.
This URL has Read-Only access.
main_repo / src / node_internals.h @ 31c510ca
History | View | Annotate | Download (4.02 KB)
1 |
// Copyright Joyent, Inc. and other Node contributors.
|
---|---|
2 |
//
|
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:
|
10 |
//
|
11 |
// The above copyright notice and this permission notice shall be included
|
12 |
// in all copies or substantial portions of the Software.
|
13 |
//
|
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.
|
21 |
|
22 |
#ifndef SRC_NODE_INTERNALS_H_
|
23 |
#define SRC_NODE_INTERNALS_H_
|
24 |
|
25 |
#include <stdlib.h> |
26 |
|
27 |
#include "v8.h" |
28 |
|
29 |
namespace node { |
30 |
|
31 |
// Defined in node.cc
|
32 |
extern v8::Isolate* node_isolate;
|
33 |
|
34 |
// Defined in node.cc at startup.
|
35 |
extern v8::Persistent<v8::Object> process;
|
36 |
|
37 |
#ifdef _WIN32
|
38 |
// emulate snprintf() on windows, _snprintf() doesn't zero-terminate the buffer
|
39 |
// on overflow...
|
40 |
#include <stdarg.h> |
41 |
inline static int snprintf(char* buf, unsigned int len, const char* fmt, ...) { |
42 |
va_list ap; |
43 |
va_start(ap, fmt); |
44 |
int n = _vsprintf_p(buf, len, fmt, ap);
|
45 |
if (len) buf[len - 1] = '\0'; |
46 |
va_end(ap); |
47 |
return n;
|
48 |
} |
49 |
#endif
|
50 |
|
51 |
#if defined(__x86_64__)
|
52 |
# define BITS_PER_LONG 64 |
53 |
#else
|
54 |
# define BITS_PER_LONG 32 |
55 |
#endif
|
56 |
|
57 |
#ifndef offset_of
|
58 |
// g++ in strict mode complains loudly about the system offsetof() macro
|
59 |
// because it uses NULL as the base address.
|
60 |
# define offset_of(type, member) \
|
61 |
((intptr_t) ((char *) &(((type *) 8)->member) - 8)) |
62 |
#endif
|
63 |
|
64 |
#ifndef container_of
|
65 |
# define container_of(ptr, type, member) \
|
66 |
((type *) ((char *) (ptr) - offset_of(type, member)))
|
67 |
#endif
|
68 |
|
69 |
#ifndef ARRAY_SIZE
|
70 |
# define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) |
71 |
#endif
|
72 |
|
73 |
#ifndef ROUND_UP
|
74 |
# define ROUND_UP(a, b) ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))
|
75 |
#endif
|
76 |
|
77 |
// this would have been a template function were it not for the fact that g++
|
78 |
// sometimes fails to resolve it...
|
79 |
#define THROW_ERROR(fun) \
|
80 |
do { \
|
81 |
v8::HandleScope scope; \ |
82 |
return v8::ThrowException(fun(v8::String::New(errmsg))); \
|
83 |
} \ |
84 |
while (0) |
85 |
|
86 |
inline static v8::Handle<v8::Value> ThrowError(const char* errmsg) { |
87 |
THROW_ERROR(v8::Exception::Error); |
88 |
} |
89 |
|
90 |
inline static v8::Handle<v8::Value> ThrowTypeError(const char* errmsg) { |
91 |
THROW_ERROR(v8::Exception::TypeError); |
92 |
} |
93 |
|
94 |
inline static v8::Handle<v8::Value> ThrowRangeError(const char* errmsg) { |
95 |
THROW_ERROR(v8::Exception::RangeError); |
96 |
} |
97 |
|
98 |
#define UNWRAP(type) \
|
99 |
assert(!args.Holder().IsEmpty()); \ |
100 |
assert(args.Holder()->InternalFieldCount() > 0); \
|
101 |
type* wrap = static_cast<type*>( \ |
102 |
args.Holder()->GetPointerFromInternalField(0)); \
|
103 |
if (!wrap) { \
|
104 |
fprintf(stderr, #type ": Aborting due to unwrap failure at %s:%d\n", \ |
105 |
__FILE__, __LINE__); \ |
106 |
abort(); \ |
107 |
} |
108 |
|
109 |
v8::Handle<v8::Value> FromConstructorTemplate( |
110 |
v8::Persistent<v8::FunctionTemplate> t, |
111 |
const v8::Arguments& args);
|
112 |
|
113 |
} // namespace node
|
114 |
|
115 |
#endif // SRC_NODE_INTERNALS_H_ |