Skip to content

Commit 793282f

Browse files
committed
Give top-level an empty object as a resource
1 parent 8fba1da commit 793282f

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

doc/api/async_hooks.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,6 @@ const server = createServer(function(req, res) {
509509
}).listen(3000);
510510
```
511511

512-
`executionAsyncResource()` will return `null` during application bootstrap.
513-
514512
Resource objects returned by `executionAsyncResource()` are often internal
515513
handle objects with undocumented APIs. Using any functions or properties
516514
on the object is not recommended and may crash your application.

src/env.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ Environment::Environment(IsolateData* isolate_data,
382382
async_hooks_.no_force_checks();
383383
}
384384

385+
async_hooks_.push_execution_async_resource(v8::Object::New(isolate_));
386+
385387
// TODO(joyeecheung): deserialize when the snapshot covers the environment
386388
// properties.
387389
CreateProperties();
@@ -418,6 +420,8 @@ Environment::~Environment() {
418420
TRACE_EVENT_NESTABLE_ASYNC_END0(
419421
TRACING_CATEGORY_NODE1(environment), "Environment", this);
420422

423+
async_hooks_.pop_execution_async_resource();
424+
421425
// Do not unload addons on the main thread. Some addons need to retain memory
422426
// beyond the Environment's lifetime, and unloading them early would break
423427
// them; with Worker threads, we have the opportunity to be stricter.

test/parallel/test-async-hooks-current-resource-await.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const id = Symbol('id');
1111
// Tests continuation local storage with the currentResource API
1212
// through an async function
1313

14+
assert.ok(executionAsyncResource());
15+
1416
createHook({
1517
init(asyncId, type, triggerAsyncId, resource) {
1618
const cr = executionAsyncResource();

test/parallel/test-async-hooks-current-resource.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const id = Symbol('id');
99

1010
// Tests continuation local storage with the executionAsyncResource API
1111

12+
assert.ok(executionAsyncResource());
13+
1214
createHook({
1315
init(asyncId, type, triggerAsyncId, resource) {
1416
const cr = executionAsyncResource();

0 commit comments

Comments
 (0)