forked from nodejs/node-v0.x-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_events.h
More file actions
94 lines (71 loc) · 2.47 KB
/
node_events.h
File metadata and controls
94 lines (71 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#ifndef SRC_EVENTS_H_
#define SRC_EVENTS_H_
#include <node.h>
#include <node_object_wrap.h>
#include <v8.h>
namespace node {
// Legacy interface, do no use.
class EventEmitter : public ObjectWrap {
public:
static void Initialize(v8::Local<v8::FunctionTemplate> ctemplate);
static v8::Persistent<v8::FunctionTemplate> constructor_template;
bool Emit(v8::Handle<v8::String> event,
int argc,
v8::Handle<v8::Value> argv[]);
protected:
EventEmitter() : ObjectWrap () { }
};
// "hard emitter" base class
class EventSource : public ObjectWrap {
public:
// All subclasses must call this function to initialize their JavaScript
// counterparts. Subclasses are free to decorate the template with additional
// and such.
template <class T>
static v8::Local<v8::FunctionTemplate> BuildTemplate(const char *name) {
// TODO node_events_impl.h
v8::HandleScope scope;
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(EventSource::JSNew<T>);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(v8::String::NewSymbol(name));
return scope.Close(t);
}
// Subclasses to call this when they go from inactive to active.
void Active();
// And this when going from active to inactive
void Inactive();
EventSource() : ObjectWrap() { }
virtual ~EventSource() {
ClearStack();
DeleteParent();
}
// Subclasses call this when they get a event.
v8::Local<v8::Value> MakeCallback(int argc, v8::Handle<v8::Value> argv[]);
private:
template <class T>
static v8::Handle<v8::Value> JSNew(const v8::Arguments& args) {
// TODO node_events_impl.h
v8::HandleScope scope;
T *t = new T();
t->Wrap(args.This());
return args.This();
}
static void WeakParent(v8::Persistent<v8::Value> object, void* data);
// Internal MakeCallback function.
v8::Local<v8::Value> _MakeCallback(v8::Handle<v8::Function> cb,
v8::Handle<v8::Object> target,
int argc,
v8::Handle<v8::Value> argv[]);
void RecordStack();
void ClearStack();
void DeleteParent();
void PrintStack(int count = 0);
v8::Persistent<v8::Object> parent_source_;
v8::Persistent<v8::StackTrace> trace_;
static const int kFrameLimit = 10;
static const int kAncestorStackLimit = 10;
static EventSource* current_source;
};
} // namespace node
#endif // SRC_EVENTS_H_