Skip to content

Commit afe27e3

Browse files
trevnorrispiscisaureus
authored andcommitted
async-wrap: expose async-wrap as binding
Expose basic hooks for AsyncWrap via the async_wrap binding. Right now only the PROVIDER types are exposed. This is a preliminary step before more functionality is added. PR-URL: nodejs/node-v0.x-archive#8110 Signed-off-by: Trevor Norris <trev.norris@gmail.com> Reviewed-by: Fedor Indutny <fedor@indutny.com> Reviewed-by: Alexis Campailla <alexis@janeasystems.com> Reviewed-by: Julien Gilli <julien.gilli@joyent.com>
1 parent f39b48c commit afe27e3

File tree

2 files changed

+51
-22
lines changed

2 files changed

+51
-22
lines changed

src/async-wrap.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,36 @@
2828

2929
#include "v8.h"
3030

31+
using v8::Context;
3132
using v8::Function;
3233
using v8::Handle;
34+
using v8::HandleScope;
35+
using v8::Integer;
36+
using v8::Isolate;
3337
using v8::Local;
3438
using v8::Object;
3539
using v8::TryCatch;
3640
using v8::Value;
3741

3842
namespace node {
3943

44+
static void Initialize(Handle<Object> target,
45+
Handle<Value> unused,
46+
Handle<Context> context) {
47+
Environment* env = Environment::GetCurrent(context);
48+
Isolate* isolate = env->isolate();
49+
HandleScope scope(isolate);
50+
51+
Local<Object> async_providers = Object::New(isolate);
52+
#define V(PROVIDER) \
53+
async_providers->Set(FIXED_ONE_BYTE_STRING(isolate, #PROVIDER), \
54+
Integer::New(isolate, AsyncWrap::PROVIDER_ ## PROVIDER));
55+
NODE_ASYNC_PROVIDER_TYPES(V)
56+
#undef V
57+
target->Set(FIXED_ONE_BYTE_STRING(isolate, "Providers"), async_providers);
58+
}
59+
60+
4061
Handle<Value> AsyncWrap::MakeCallback(const Handle<Function> cb,
4162
int argc,
4263
Handle<Value>* argv) {
@@ -114,3 +135,5 @@ Handle<Value> AsyncWrap::MakeCallback(const Handle<Function> cb,
114135
}
115136

116137
} // namespace node
138+
139+
NODE_MODULE_CONTEXT_AWARE_BUILTIN(async_wrap, node::Initialize)

src/async-wrap.h

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,37 @@
2828

2929
namespace node {
3030

31+
#define NODE_ASYNC_PROVIDER_TYPES(V) \
32+
V(NONE) \
33+
V(CARES) \
34+
V(CONNECTWRAP) \
35+
V(CRYPTO) \
36+
V(FSEVENTWRAP) \
37+
V(FSREQWRAP) \
38+
V(GETADDRINFOREQWRAP) \
39+
V(GETNAMEINFOREQWRAP) \
40+
V(PIPEWRAP) \
41+
V(PROCESSWRAP) \
42+
V(QUERYWRAP) \
43+
V(REQWRAP) \
44+
V(SHUTDOWNWRAP) \
45+
V(SIGNALWRAP) \
46+
V(STATWATCHER) \
47+
V(TCPWRAP) \
48+
V(TIMERWRAP) \
49+
V(TLSWRAP) \
50+
V(TTYWRAP) \
51+
V(UDPWRAP) \
52+
V(WRITEWRAP) \
53+
V(ZLIB)
54+
3155
class AsyncWrap : public BaseObject {
3256
public:
3357
enum ProviderType {
34-
PROVIDER_NONE,
35-
PROVIDER_CARES,
36-
PROVIDER_CONNECTWRAP,
37-
PROVIDER_CRYPTO,
38-
PROVIDER_FSEVENTWRAP,
39-
PROVIDER_FSREQWRAP,
40-
PROVIDER_GETADDRINFOREQWRAP,
41-
PROVIDER_GETNAMEINFOREQWRAP,
42-
PROVIDER_PIPEWRAP,
43-
PROVIDER_PROCESSWRAP,
44-
PROVIDER_QUERYWRAP,
45-
PROVIDER_REQWRAP,
46-
PROVIDER_SHUTDOWNWRAP,
47-
PROVIDER_SIGNALWRAP,
48-
PROVIDER_STATWATCHER,
49-
PROVIDER_TCPWRAP,
50-
PROVIDER_TIMERWRAP,
51-
PROVIDER_TLSWRAP,
52-
PROVIDER_TTYWRAP,
53-
PROVIDER_UDPWRAP,
54-
PROVIDER_WRITEWRAP,
55-
PROVIDER_ZLIB
58+
#define V(PROVIDER) \
59+
PROVIDER_ ## PROVIDER,
60+
NODE_ASYNC_PROVIDER_TYPES(V)
61+
#undef V
5662
};
5763

5864
inline AsyncWrap(Environment* env,

0 commit comments

Comments
 (0)