Skip to content

Commit d316772

Browse files
committed
Cleanup some things
1 parent 58c109e commit d316772

File tree

10 files changed

+14
-30
lines changed

10 files changed

+14
-30
lines changed

lib/internal/async_hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function executionAsyncResource() {
106106
const index = async_hook_fields[kStackLength] - 1;
107107
if (index === -1) return topLevelResource;
108108
const resource = execution_async_resources[index];
109-
return resource || topLevelResource;
109+
return resource;
110110
}
111111

112112
// Used to fatally abort the process if a callback throws.

src/api/callback.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
5050
object_(object),
5151
skip_hooks_(flags & kSkipAsyncHooks),
5252
skip_task_queues_(flags & kSkipTaskQueues) {
53-
CHECK_IMPLIES(!(flags & kAllowEmptyResource), !object.IsEmpty());
5453
CHECK_NOT_NULL(env);
5554
env->PushAsyncCallbackScope();
5655

src/env-inl.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ inline AsyncHooks::AsyncHooks()
6868
: async_ids_stack_(env()->isolate(), 16 * 2),
6969
fields_(env()->isolate(), kFieldsCount),
7070
async_id_fields_(env()->isolate(), kUidFieldsCount) {
71-
v8::Isolate* isolate = env()->isolate();
72-
v8::HandleScope handle_scope(isolate);
73-
74-
execution_async_resources_.Reset(isolate, v8::Array::New(isolate));
71+
clear_async_id_stack();
7572

7673
// Always perform async_hooks checks, not just when async_hooks is enabled.
7774
// TODO(AndreasMadsen): Consider removing this for LTS releases.
@@ -117,7 +114,7 @@ inline AliasedFloat64Array& AsyncHooks::async_ids_stack() {
117114
}
118115

119116
inline v8::Local<v8::Array> AsyncHooks::execution_async_resources() {
120-
return execution_async_resources_.Get(env()->isolate());
117+
return PersistentToLocal::Strong(execution_async_resources_);
121118
}
122119

123120
inline v8::Local<v8::String> AsyncHooks::provider_string(int idx) {
@@ -155,7 +152,7 @@ inline void AsyncHooks::push_async_context(double async_id,
155152
async_id_fields_[kTriggerAsyncId] = trigger_async_id;
156153

157154
auto resources = execution_async_resources();
158-
resources->Set(env()->context(), offset, resource).Check();
155+
USE(resources->Set(env()->context(), offset, resource));
159156
}
160157

161158
// Remember to keep this code aligned with popAsyncContext() in JS.
@@ -189,14 +186,15 @@ inline bool AsyncHooks::pop_async_context(double async_id) {
189186
fields_[kStackLength] = offset;
190187

191188
auto resources = execution_async_resources();
192-
resources->Delete(env()->context(), offset).FromJust();
189+
USE(resources->Delete(env()->context(), offset));
193190

194191
return fields_[kStackLength] > 0;
195192
}
196193

197194
// Keep in sync with clearAsyncIdStack in lib/internal/async_hooks.js.
198195
inline void AsyncHooks::clear_async_id_stack() {
199196
auto isolate = env()->isolate();
197+
v8::HandleScope handle_scope(isolate);
200198
execution_async_resources_.Reset(isolate, v8::Array::New(isolate));
201199

202200
async_id_fields_[kExecutionAsyncId] = 0;

src/env.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include <cstdint>
4646
#include <functional>
4747
#include <list>
48-
#include <stack>
4948
#include <unordered_map>
5049
#include <unordered_set>
5150
#include <vector>
@@ -684,7 +683,7 @@ class AsyncHooks : public MemoryRetainer {
684683
inline Environment* env();
685684

686685
inline void push_async_context(double async_id, double trigger_async_id,
687-
v8::Local<v8::Value> execution_async_resource_);
686+
v8::Local<v8::Value> execution_async_resource_);
688687
inline bool pop_async_context(double async_id);
689688
inline void clear_async_id_stack(); // Used in fatal exceptions.
690689

src/node_internals.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,13 @@ class InternalCallbackScope {
204204
public:
205205
enum Flags {
206206
kNoFlags = 0,
207-
// Tell the constructor whether its `object` parameter may be empty or not.
208-
kAllowEmptyResource = 1,
209207
// Indicates whether 'before' and 'after' hooks should be skipped.
210-
kSkipAsyncHooks = 2,
208+
kSkipAsyncHooks = 1,
211209
// Indicates whether nextTick and microtask queues should be skipped.
212210
// This should only be used when there is no call into JS in this scope.
213211
// (The HTTP parser also uses it for some weird backwards
214212
// compatibility issues, but it shouldn't.)
215-
kSkipTaskQueues = 4
213+
kSkipTaskQueues = 2
216214
};
217215
InternalCallbackScope(Environment* env,
218216
v8::Local<v8::Object> object,

src/node_main_instance.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ int NodeMainInstance::Run() {
123123
env.get(),
124124
Object::New(isolate_),
125125
{ 1, 0 },
126-
InternalCallbackScope::kAllowEmptyResource |
127-
InternalCallbackScope::kSkipAsyncHooks);
126+
InternalCallbackScope::kSkipAsyncHooks);
128127
LoadEnvironment(env.get());
129128
}
130129

src/node_platform.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ void PerIsolatePlatformData::RunForegroundTask(std::unique_ptr<Task> task) {
389389
if (env != nullptr) {
390390
v8::HandleScope scope(isolate);
391391
InternalCallbackScope cb_scope(env, Object::New(isolate), { 0, 0 },
392-
InternalCallbackScope::kAllowEmptyResource);
392+
InternalCallbackScope::kNoFlags);
393393
task->Run();
394394
} else {
395395
task->Run();

src/node_worker.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ void Worker::Run() {
335335
env_.get(),
336336
Object::New(isolate_),
337337
{ 1, 0 },
338-
InternalCallbackScope::kAllowEmptyResource |
339-
InternalCallbackScope::kSkipAsyncHooks);
338+
InternalCallbackScope::kSkipAsyncHooks);
340339

341340
if (!env_->RunBootstrapping().IsEmpty()) {
342341
CreateEnvMessagePort(env_.get());

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const assert = require('assert');
66
const { executionAsyncResource, createHook } = require('async_hooks');
77
const { createServer, get } = require('http');
88
const sym = Symbol('cls');
9-
const id = Symbol('id');
109

1110
// Tests continuation local storage with the currentResource API
1211
// through an async function
@@ -16,10 +15,7 @@ assert.ok(executionAsyncResource());
1615
createHook({
1716
init(asyncId, type, triggerAsyncId, resource) {
1817
const cr = executionAsyncResource();
19-
resource[id] = asyncId;
20-
if (cr) {
21-
resource[sym] = cr[sym];
22-
}
18+
resource[sym] = cr[sym];
2319
}
2420
}).enable();
2521

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const assert = require('assert');
55
const { executionAsyncResource, createHook } = require('async_hooks');
66
const { createServer, get } = require('http');
77
const sym = Symbol('cls');
8-
const id = Symbol('id');
98

109
// Tests continuation local storage with the executionAsyncResource API
1110

@@ -14,10 +13,7 @@ assert.ok(executionAsyncResource());
1413
createHook({
1514
init(asyncId, type, triggerAsyncId, resource) {
1615
const cr = executionAsyncResource();
17-
resource[id] = asyncId;
18-
if (cr) {
19-
resource[sym] = cr[sym];
20-
}
16+
resource[sym] = cr[sym];
2117
}
2218
}).enable();
2319

0 commit comments

Comments
 (0)