33#include < v8.h>
44#include < uv.h>
55
6- using namespace v8 ;
7- using namespace node ;
8-
96struct async_req {
107 uv_work_t req;
118 int input;
129 int output;
13- Persistent<Function> callback;
10+ v8:: Persistent<v8:: Function> callback;
1411};
1512
1613void DoAsync (uv_work_t * r) {
1714 async_req* req = reinterpret_cast <async_req*>(r->data );
18- sleep (1 ); // simulate CPU intensive process...
15+ sleep (1 ); // Simulate CPU intensive process...
1916 req->output = req->input * 2 ;
2017}
2118
2219void AfterAsync (uv_work_t * r) {
23- Isolate* isolate = Isolate::GetCurrent ();
24- HandleScope scope (isolate);
20+ v8:: Isolate* isolate = v8:: Isolate::GetCurrent ();
21+ v8:: HandleScope scope (isolate);
2522 async_req* req = reinterpret_cast <async_req*>(r->data );
2623
27- Handle<Value> argv[2 ] = {
28- Null (isolate),
29- Integer::New (isolate, req->output )
24+ v8:: Handle<v8:: Value> argv[2 ] = {
25+ v8:: Null (isolate),
26+ v8:: Integer::New (isolate, req->output )
3027 };
3128
32- TryCatch try_catch;
29+ v8:: TryCatch try_catch (isolate) ;
3330
34- Local<Function> callback = Local<Function>::New (isolate, req->callback );
31+ v8::Local<v8::Function> callback =
32+ v8::Local<v8::Function>::New (isolate, req->callback );
3533 callback->Call (isolate->GetCurrentContext ()->Global (), 2 , argv);
3634
3735 // cleanup
3836 req->callback .Reset ();
3937 delete req;
4038
4139 if (try_catch.HasCaught ()) {
42- FatalException (isolate, try_catch);
40+ node:: FatalException (isolate, try_catch);
4341 }
4442}
4543
46- void Method (const FunctionCallbackInfo<Value>& args) {
47- Isolate* isolate = Isolate::GetCurrent ();
48- HandleScope scope (isolate);
44+ void Method (const v8:: FunctionCallbackInfo<v8:: Value>& args) {
45+ v8:: Isolate* isolate = v8:: Isolate::GetCurrent ();
46+ v8:: HandleScope scope (isolate);
4947
5048 async_req* req = new async_req;
5149 req->req .data = req;
5250
5351 req->input = args[0 ]->IntegerValue ();
5452 req->output = 0 ;
5553
56- Local<Function> callback = Local<Function>::Cast (args[1 ]);
54+ v8:: Local<v8:: Function> callback = v8:: Local<v8:: Function>::Cast (args[1 ]);
5755 req->callback .Reset (isolate, callback);
5856
5957 uv_queue_work (uv_default_loop (),
@@ -62,7 +60,7 @@ void Method(const FunctionCallbackInfo<Value>& args) {
6260 (uv_after_work_cb)AfterAsync);
6361}
6462
65- void init (Handle<Object> exports, Handle<Object> module ) {
63+ void init (v8:: Handle<v8:: Object> exports, v8:: Handle<v8:: Object> module ) {
6664 NODE_SET_METHOD (module , " exports" , Method);
6765}
6866
0 commit comments