Skip to content

Commit a7cbe3b

Browse files
committed
Added call to node::MakeCallback when returning asynchronously Ref #14
1 parent 0f5ae52 commit a7cbe3b

File tree

7 files changed

+27
-10
lines changed

7 files changed

+27
-10
lines changed

src/dispatch-v10.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void doDispatch(uv_async_t *handle,int status)
2626
{
2727
HandleScope scope;
2828

29-
callbackWithResult(scope,binding->target()->cb(),binding->res());
29+
callbackWithResult(scope,binding->target()->cb(),binding->res(),true);
3030
}
3131
}
3232

src/dispatch-v11.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void doDispatch(uv_async_t *handle)
2626
{
2727
HandleScope scope(I);
2828

29-
callbackWithResult(scope,binding->target()->cb(),binding->res());
29+
callbackWithResult(scope,binding->target()->cb(),binding->res(),true);
3030
}
3131
}
3232

src/nj-v10.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void raiseException(HandleScope &scope,const shared_ptr<nj::Result> &res)
401401
ThrowException(ex);
402402
}
403403

404-
Handle<Value> callbackWithResult(HandleScope &scope,const Local<Function> &cb,const shared_ptr<nj::Result> &res)
404+
Handle<Value> callbackWithResult(HandleScope &scope,const Local<Function> &cb,const shared_ptr<nj::Result> &res,bool useMakeCallback)
405405
{
406406
if(res.get())
407407
{
@@ -413,7 +413,8 @@ Handle<Value> callbackWithResult(HandleScope &scope,const Local<Function> &cb,co
413413
Local<Value> *argv = new Local<Value>[argc];
414414

415415
argv[0] = genError(scope,res);
416-
return callback(scope,cb,argc,argv);
416+
if(useMakeCallback) return node::MakeCallback(Context::GetCurrent()->Global(),cb,argc,argv);
417+
else return callback(scope,cb,argc,argv);
417418
}
418419
else
419420
{
@@ -422,7 +423,8 @@ Handle<Value> callbackWithResult(HandleScope &scope,const Local<Function> &cb,co
422423

423424
argv[0] = Local<Value>::New(Null());
424425
argc = createResponse(scope,res,argc,argv);
425-
return callback(scope,cb,argc,argv);
426+
if(useMakeCallback) return node::MakeCallback(Context::GetCurrent()->Global(),cb,argc,argv);
427+
else return callback(scope,cb,argc,argv);
426428
}
427429
}
428430
else return callback(scope,cb,0,0);

src/nj-v10.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
void raiseException(v8::HandleScope &scope,const std::shared_ptr<nj::Result> &res);
99
v8::Local<v8::Value> mapResult(v8::HandleScope &scope,std::shared_ptr<nj::Result> &res);
1010
v8::Local<v8::String> genError(v8::HandleScope &scope,const std::shared_ptr<nj::Result> &res);
11-
v8::Handle<v8::Value> callbackWithResult(v8::HandleScope &scope,const v8::Local<v8::Function> &cb,const std::shared_ptr<nj::Result> &res);
11+
v8::Handle<v8::Value> callbackWithResult(v8::HandleScope &scope,const v8::Local<v8::Function> &cb,const std::shared_ptr<nj::Result> &res,bool useMakeCallback);
1212
v8::Handle<v8::Value> returnResult(v8::HandleScope &scope,std::shared_ptr<nj::Result> &res);
1313

1414
#endif

src/nj-v11.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void raiseException(HandleScope &scope,const shared_ptr<nj::Result> &res)
442442
I->ThrowException(ex);
443443
}
444444

445-
void callbackWithResult(HandleScope &scope,const Local<Function> &cb,const shared_ptr<nj::Result> &res)
445+
void callbackWithResult(HandleScope &scope,const Local<Function> &cb,const shared_ptr<nj::Result> &res,bool useMakeCallback)
446446
{
447447
Isolate *I = Isolate::GetCurrent();
448448

@@ -456,7 +456,8 @@ void callbackWithResult(HandleScope &scope,const Local<Function> &cb,const share
456456
Local<Value> *argv = new Local<Value>[argc];
457457

458458
argv[0] = genError(scope,res);
459-
callback(I,cb,argc,argv);
459+
if(useMakeCallback) node::MakeCallback(I,I->GetCurrentContext()->Global(),cb,argc,argv);
460+
else callback(I,cb,argc,argv);
460461
}
461462
else
462463
{
@@ -465,7 +466,8 @@ void callbackWithResult(HandleScope &scope,const Local<Function> &cb,const share
465466

466467
argv[0] = Null(I);
467468
(void)createResponse(scope,res,argc,argv);
468-
callback(I,cb,argc,argv);
469+
if(useMakeCallback) node::MakeCallback(I,I->GetCurrentContext()->Global(),cb,argc,argv);
470+
else callback(I,cb,argc,argv);
469471
}
470472
}
471473
else callback(I,cb,0,0);

src/nj-v11.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
void raiseException(v8::HandleScope &scope,const std::shared_ptr<nj::Result> &res);
99
v8::Local<v8::Value> mapResult(v8::HandleScope &scope,std::shared_ptr<nj::Result> &res);
1010
v8::Local<v8::String> genError(v8::HandleScope &scope,const std::shared_ptr<nj::Result> &res);
11-
void callbackWithResult(v8::HandleScope &scope,const v8::Local<v8::Function> &cb,const std::shared_ptr<nj::Result> &res);
11+
void callbackWithResult(v8::HandleScope &scope,const v8::Local<v8::Function> &cb,const std::shared_ptr<nj::Result> &res,bool useMakeCallback = false);
1212
void returnResult(const v8::FunctionCallbackInfo<v8::Value> &args,v8::HandleScope &scope,std::shared_ptr<nj::Result> &res);
1313

1414
#endif

test/test.js

+13
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,19 @@ describe('Regression Tests',function()
829829
expect(x).to.equal(6);
830830
});
831831

832+
it('asynchronous call followed by process.nextTick()',function(done)
833+
{
834+
julia.eval("2+3",function(err,result)
835+
{
836+
expect(err).to.equal(null);
837+
expect(result).to.equal(5);
838+
});
839+
julia.eval("2+3",function(err,result)
840+
{
841+
process.nextTick(done);
842+
});
843+
});
844+
832845
/*
833846
it('Incremental updates',function()
834847
{

0 commit comments

Comments
 (0)