Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions generate/templates/partials/callback_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_async(uv_as

NanAssignPersistent(baton->promise, promise);

uv_close((uv_handle_t*) &baton->req, NULL);
uv_async_init(uv_default_loop(), &baton->req, (uv_async_cb) {{ cppFunctionName }}_{{ cbFunction.name }}_asyncPromisePolling);
uv_async_send(&baton->req);
return;
Expand Down Expand Up @@ -110,7 +111,9 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_async(uv_as
baton->result = {{ cbFunction.return.noResults }};
}
{% endeach %}

baton->done = true;
uv_close((uv_handle_t*) &baton->req, NULL);
}

void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_asyncPromisePolling(uv_async_t* req, int status) {
Expand All @@ -120,19 +123,19 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_asyncPromis
Local<Object> promise = NanNew<Object>(baton->promise);
NanCallback* isPendingFn = new NanCallback(promise->Get(NanNew("isPending")).As<Function>());
Local<Value> argv[1]; // MSBUILD won't assign an array of length 0
Local<Boolean> isPending = isPendingFn->Call(0, argv)->ToBoolean();
Local<Boolean> isPending = isPendingFn->Call(promise, 0, argv)->ToBoolean();

if (isPending->Value()) {
uv_async_send(&baton->req);
return;
}

NanCallback* isFulfilledFn = new NanCallback(promise->Get(NanNew("isFulfilled")).As<Function>());
Local<Boolean> isFulfilled = isFulfilledFn->Call(0, argv)->ToBoolean();
Local<Boolean> isFulfilled = isFulfilledFn->Call(promise, 0, argv)->ToBoolean();

if (isFulfilled->Value()) {
NanCallback* resultFn = new NanCallback(promise->Get(NanNew("value")).As<Function>());
Handle<v8::Value> result = resultFn->Call(0, argv);
Handle<v8::Value> result = resultFn->Call(promise, 0, argv);

{% each cbFunction|returnsInfo false true as _return %}
if (result.IsEmpty() || result->IsNativeError()) {
Expand Down Expand Up @@ -165,6 +168,8 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_asyncPromis
baton->result = {{ cbFunction.return.error }};
baton->done = false;
}

uv_close((uv_handle_t*) &baton->req, NULL);
}
{%endif%}
{%endeach%}
10 changes: 7 additions & 3 deletions generate/templates/partials/field_accessors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@

NanAssignPersistent(baton->promise, promise);

uv_close((uv_handle_t*) &baton->req, NULL);
uv_async_init(uv_default_loop(), &baton->req, (uv_async_cb) {{ field.name }}_asyncPromisePolling);
uv_async_send(&baton->req);
return;
Expand Down Expand Up @@ -204,6 +205,7 @@
}
{% endeach %}
baton->done = true;
uv_close((uv_handle_t*) &baton->req, NULL);
}

void {{ cppClassName }}::{{ field.name }}_asyncPromisePolling(uv_async_t* req, int status) {
Expand All @@ -213,19 +215,19 @@
Local<Object> promise = NanNew<Object>(baton->promise);
NanCallback* isPendingFn = new NanCallback(promise->Get(NanNew("isPending")).As<Function>());
Local<Value> argv[1]; // MSBUILD won't assign an array of length 0
Local<Boolean> isPending = isPendingFn->Call(0, argv)->ToBoolean();
Local<Boolean> isPending = isPendingFn->Call(promise, 0, argv)->ToBoolean();

if (isPending->Value()) {
uv_async_send(&baton->req);
return;
}

NanCallback* isFulfilledFn = new NanCallback(promise->Get(NanNew("isFulfilled")).As<Function>());
Local<Boolean> isFulfilled = isFulfilledFn->Call(0, argv)->ToBoolean();
Local<Boolean> isFulfilled = isFulfilledFn->Call(promise, 0, argv)->ToBoolean();

if (isFulfilled->Value()) {
NanCallback* resultFn = new NanCallback(promise->Get(NanNew("value")).As<Function>());
Handle<v8::Value> result = resultFn->Call(0, argv);
Handle<v8::Value> result = resultFn->Call(promise, 0, argv);

{% each field|returnsInfo false true as _return %}
if (result.IsEmpty() || result->IsNativeError()) {
Expand Down Expand Up @@ -258,6 +260,8 @@
baton->result = {{ field.return.error }};
baton->done = false;
}

uv_close((uv_handle_t*) &baton->req, NULL);
}
{% endif %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ var args = cov.concat([
"--expose-gc"
]);

fork(bin, args, { cwd: path.join(__dirname, "../") }).on("close", process.exit);
fork(bin, args, { cwd: path.join(__dirname, "../") });