summaryrefslogtreecommitdiff
path: root/test/addons/async-resource
diff options
context:
space:
mode:
authorAndreas Madsen <amwebdk@gmail.com>2017-07-06 08:20:03 +0200
committerAndreas Madsen <amwebdk@gmail.com>2017-07-06 08:20:03 +0200
commitc6ce500edf364692efa9d46bc1bd9e959611f7da (patch)
tree86c66ae1c5317ccb9942797fe3907dbae0ca1f9e /test/addons/async-resource
parent6809429cfa035b35ca8c83815e644234092f53be (diff)
downloadandroid-node-v8-c6ce500edf364692efa9d46bc1bd9e959611f7da.tar.gz
android-node-v8-c6ce500edf364692efa9d46bc1bd9e959611f7da.tar.bz2
android-node-v8-c6ce500edf364692efa9d46bc1bd9e959611f7da.zip
async_hooks: C++ Embedder API overhaul
* Fix AsyncHooksGetTriggerAsyncId such it corresponds to async_hooks.triggerAsyncId and not async_hooks.initTriggerId. * Use an async_context struct instead of two async_uid values. This change was necessary since the fixing AsyncHooksGetTriggerAsyncId otherwise makes it impossible to get the correct default trigger id. It also prevents an invalid triggerAsyncId in MakeCallback. * Rename async_uid to async_id for consistency * Rename get_uid to get_async_id * Add get_trigger_async_id to AsyncResource class PR-URL: https://github.com/nodejs/node/pull/14040 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/addons/async-resource')
-rw-r--r--test/addons/async-resource/binding.cc19
-rw-r--r--test/addons/async-resource/test.js10
2 files changed, 15 insertions, 14 deletions
diff --git a/test/addons/async-resource/binding.cc b/test/addons/async-resource/binding.cc
index 372f7a6fa4..9d3ab37e12 100644
--- a/test/addons/async-resource/binding.cc
+++ b/test/addons/async-resource/binding.cc
@@ -80,21 +80,22 @@ void CallViaUtf8Name(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(ret.FromMaybe(Local<Value>()));
}
-void GetUid(const FunctionCallbackInfo<Value>& args) {
+void GetAsyncId(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
- args.GetReturnValue().Set(r->get_uid());
+ args.GetReturnValue().Set(r->get_async_id());
}
-void GetResource(const FunctionCallbackInfo<Value>& args) {
+void GetTriggerAsyncId(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
- args.GetReturnValue().Set(r->get_resource());
+ args.GetReturnValue().Set(r->get_trigger_async_id());
}
-void GetCurrentId(const FunctionCallbackInfo<Value>& args) {
- args.GetReturnValue().Set(
- node::AsyncHooksGetExecutionAsyncId(args.GetIsolate()));
+void GetResource(const FunctionCallbackInfo<Value>& args) {
+ assert(args[0]->IsExternal());
+ auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
+ args.GetReturnValue().Set(r->get_resource());
}
void Initialize(Local<Object> exports) {
@@ -103,9 +104,9 @@ void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "callViaFunction", CallViaFunction);
NODE_SET_METHOD(exports, "callViaString", CallViaString);
NODE_SET_METHOD(exports, "callViaUtf8Name", CallViaUtf8Name);
- NODE_SET_METHOD(exports, "getUid", GetUid);
+ NODE_SET_METHOD(exports, "getAsyncId", GetAsyncId);
+ NODE_SET_METHOD(exports, "getTriggerAsyncId", GetTriggerAsyncId);
NODE_SET_METHOD(exports, "getResource", GetResource);
- NODE_SET_METHOD(exports, "getCurrentId", GetCurrentId);
}
} // namespace
diff --git a/test/addons/async-resource/test.js b/test/addons/async-resource/test.js
index b52db61a95..f19ad58637 100644
--- a/test/addons/async-resource/test.js
+++ b/test/addons/async-resource/test.js
@@ -6,6 +6,7 @@ const binding = require(`./build/${common.buildType}/binding`);
const async_hooks = require('async_hooks');
const kObjectTag = Symbol('kObjectTag');
+const rootAsyncId = async_hooks.executionAsyncId();
const bindingUids = [];
let expectedTriggerId;
@@ -38,8 +39,6 @@ async_hooks.createHook({
}
}).enable();
-assert.strictEqual(binding.getCurrentId(), 1);
-
for (const call of [binding.callViaFunction,
binding.callViaString,
binding.callViaUtf8Name]) {
@@ -49,14 +48,14 @@ for (const call of [binding.callViaFunction,
methöd(arg) {
assert.strictEqual(this, object);
assert.strictEqual(arg, 42);
- assert.strictEqual(binding.getCurrentId(), uid);
+ assert.strictEqual(async_hooks.executionAsyncId(), uid);
return 'baz';
},
kObjectTag
};
if (passedTriggerId === undefined)
- expectedTriggerId = 1;
+ expectedTriggerId = rootAsyncId;
else
expectedTriggerId = passedTriggerId;
@@ -66,7 +65,8 @@ for (const call of [binding.callViaFunction,
const ret = call(resource);
assert.strictEqual(ret, 'baz');
assert.strictEqual(binding.getResource(resource), object);
- assert.strictEqual(binding.getUid(resource), uid);
+ assert.strictEqual(binding.getAsyncId(resource), uid);
+ assert.strictEqual(binding.getTriggerAsyncId(resource), expectedTriggerId);
binding.destroyAsyncResource(resource);
}