Skip to content

Commit

Permalink
Give top-level an empty object as a resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Qard committed Dec 19, 2019
1 parent 8fba1da commit 793282f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 0 additions & 2 deletions doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,6 @@ const server = createServer(function(req, res) {
}).listen(3000);
```

`executionAsyncResource()` will return `null` during application bootstrap.

Resource objects returned by `executionAsyncResource()` are often internal
handle objects with undocumented APIs. Using any functions or properties
on the object is not recommended and may crash your application.
Expand Down
4 changes: 4 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ Environment::Environment(IsolateData* isolate_data,
async_hooks_.no_force_checks();
}

async_hooks_.push_execution_async_resource(v8::Object::New(isolate_));

// TODO(joyeecheung): deserialize when the snapshot covers the environment
// properties.
CreateProperties();
Expand Down Expand Up @@ -418,6 +420,8 @@ Environment::~Environment() {
TRACE_EVENT_NESTABLE_ASYNC_END0(
TRACING_CATEGORY_NODE1(environment), "Environment", this);

async_hooks_.pop_execution_async_resource();

// Do not unload addons on the main thread. Some addons need to retain memory
// beyond the Environment's lifetime, and unloading them early would break
// them; with Worker threads, we have the opportunity to be stricter.
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-async-hooks-current-resource-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const id = Symbol('id');
// Tests continuation local storage with the currentResource API
// through an async function

assert.ok(executionAsyncResource());

createHook({
init(asyncId, type, triggerAsyncId, resource) {
const cr = executionAsyncResource();
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-async-hooks-current-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const id = Symbol('id');

// Tests continuation local storage with the executionAsyncResource API

assert.ok(executionAsyncResource());

createHook({
init(asyncId, type, triggerAsyncId, resource) {
const cr = executionAsyncResource();
Expand Down

0 comments on commit 793282f

Please sign in to comment.