GeezerVison is showing github.com — src: remove AsyncScope and AsyncCallbackScope · nodejs/node@f080239
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/api/callback.cc +8-5Lines changed: 8 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,11 +34,12 @@ CallbackScope::~CallbackScope() { | 34 | 34 | delete private_; | 35 | 35 | } | 36 | 36 |
| 37 | | -InternalCallbackScope::InternalCallbackScope(AsyncWrap* async_wrap) | | 37 | +InternalCallbackScope::InternalCallbackScope(AsyncWrap* async_wrap, int flags) | 38 | 38 | : InternalCallbackScope(async_wrap->env(), | 39 | 39 | async_wrap->object(), | 40 | 40 | { async_wrap->get_async_id(), | 41 | | - async_wrap->get_trigger_async_id() }) {} | | 41 | + async_wrap->get_trigger_async_id() }, | | 42 | + flags) {} | 42 | 43 |
| 43 | 44 | InternalCallbackScope::InternalCallbackScope(Environment* env, | 44 | 45 | Local<Object> object, | @@ -47,10 +48,11 @@ InternalCallbackScope::InternalCallbackScope(Environment* env, | 47 | 48 | : env_(env), | 48 | 49 | async_context_(asyncContext), | 49 | 50 | object_(object), | 50 | | - callback_scope_(env), | 51 | | - skip_hooks_(flags & kSkipAsyncHooks) { | | 51 | + skip_hooks_(flags & kSkipAsyncHooks), | | 52 | + skip_task_queues_(flags & kSkipTaskQueues) { | 52 | 53 | CHECK_IMPLIES(!(flags & kAllowEmptyResource), !object.IsEmpty()); | 53 | 54 | CHECK_NOT_NULL(env); | | 55 | + env->PushAsyncCallbackScope(); | 54 | 56 |
| 55 | 57 | if (!env->can_call_into_js()) { | 56 | 58 | failed_ = true; | @@ -74,6 +76,7 @@ InternalCallbackScope::InternalCallbackScope(Environment* env, | 74 | 76 |
| 75 | 77 | InternalCallbackScope::~InternalCallbackScope() { | 76 | 78 | Close(); | | 79 | + env_->PopAsyncCallbackScope(); | 77 | 80 | } | 78 | 81 |
| 79 | 82 | void InternalCallbackScope::Close() { | @@ -94,7 +97,7 @@ void InternalCallbackScope::Close() { | 94 | 97 | AsyncWrap::EmitAfter(env_, async_context_.async_id); | 95 | 98 | } | 96 | 99 |
| 97 | | - if (env_->async_callback_scope_depth() > 1) { | | 100 | + if (env_->async_callback_scope_depth() > 1 || skip_task_queues_) { | 98 | 101 | return; | 99 | 102 | } | 100 | 103 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/async_wrap-inl.h -14Lines changed: 0 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,20 +50,6 @@ inline double AsyncWrap::get_trigger_async_id() const { | 50 | 50 | } | 51 | 51 |
| 52 | 52 |
| 53 | | -inline AsyncWrap::AsyncScope::AsyncScope(AsyncWrap* wrap) | 54 | | - : wrap_(wrap) { | 55 | | - Environment* env = wrap->env(); | 56 | | - if (env->async_hooks()->fields()[AsyncHooks::kBefore] == 0) return; | 57 | | - EmitBefore(env, wrap->get_async_id()); | 58 | | -} | 59 | | - | 60 | | -inline AsyncWrap::AsyncScope::~AsyncScope() { | 61 | | - Environment* env = wrap_->env(); | 62 | | - if (env->async_hooks()->fields()[AsyncHooks::kAfter] == 0) return; | 63 | | - EmitAfter(env, wrap_->get_async_id()); | 64 | | -} | 65 | | - | 66 | | - | 67 | 53 | inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback( | 68 | 54 | const v8::Local<v8::String> symbol, | 69 | 55 | int argc, | |
Collapse file Copy file name to clipboardExpand all lines: src/async_wrap.h -13Lines changed: 0 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -162,7 +162,6 @@ class AsyncWrap : public BaseObject { | 162 | 162 | inline ProviderType set_provider_type(ProviderType provider); | 163 | 163 |
| 164 | 164 | inline double get_async_id() const; | 165 | | - | 166 | 165 | inline double get_trigger_async_id() const; | 167 | 166 |
| 168 | 167 | void AsyncReset(v8::Local<v8::Object> resource, | @@ -200,18 +199,6 @@ class AsyncWrap : public BaseObject { | 200 | 199 | static v8::Local<v8::Object> GetOwner(Environment* env, | 201 | 200 | v8::Local<v8::Object> obj); | 202 | 201 |
| 203 | | - // This is a simplified version of InternalCallbackScope that only runs | 204 | | - // the `before` and `after` hooks. Only use it when not actually calling | 205 | | - // back into JS; otherwise, use InternalCallbackScope. | 206 | | - class AsyncScope { | 207 | | - public: | 208 | | - explicit inline AsyncScope(AsyncWrap* wrap); | 209 | | - ~AsyncScope(); | 210 | | - | 211 | | - private: | 212 | | - AsyncWrap* wrap_ = nullptr; | 213 | | - }; | 214 | | - | 215 | 202 | bool IsDoneInitializing() const override; | 216 | 203 |
| 217 | 204 | private: | |
Collapse file Copy file name to clipboardExpand all lines: src/env-inl.h -8Lines changed: 0 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -211,14 +211,6 @@ Environment* Environment::ForAsyncHooks(AsyncHooks* hooks) { | 211 | 211 | return ContainerOf(&Environment::async_hooks_, hooks); | 212 | 212 | } | 213 | 213 |
| 214 | | -inline AsyncCallbackScope::AsyncCallbackScope(Environment* env) : env_(env) { | 215 | | - env_->PushAsyncCallbackScope(); | 216 | | -} | 217 | | - | 218 | | -inline AsyncCallbackScope::~AsyncCallbackScope() { | 219 | | - env_->PopAsyncCallbackScope(); | 220 | | -} | 221 | | - | 222 | 214 | inline size_t Environment::async_callback_scope_depth() const { | 223 | 215 | return async_callback_scope_depth_; | 224 | 216 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/env.h -14Lines changed: 0 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -723,20 +723,6 @@ class AsyncHooks : public MemoryRetainer { | 723 | 723 | void grow_async_ids_stack(); | 724 | 724 | }; | 725 | 725 |
| 726 | | -class AsyncCallbackScope { | 727 | | - public: | 728 | | - AsyncCallbackScope() = delete; | 729 | | - explicit AsyncCallbackScope(Environment* env); | 730 | | - ~AsyncCallbackScope(); | 731 | | - AsyncCallbackScope(const AsyncCallbackScope&) = delete; | 732 | | - AsyncCallbackScope& operator=(const AsyncCallbackScope&) = delete; | 733 | | - AsyncCallbackScope(AsyncCallbackScope&&) = delete; | 734 | | - AsyncCallbackScope& operator=(AsyncCallbackScope&&) = delete; | 735 | | - | 736 | | - private: | 737 | | - Environment* env_; | 738 | | -}; | 739 | | - | 740 | 726 | class ImmediateInfo : public MemoryRetainer { | 741 | 727 | public: | 742 | 728 | inline AliasedUint32Array& fields(); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_http_parser_impl.h +13-7Lines changed: 13 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -321,10 +321,13 @@ class Parser : public AsyncWrap, public StreamListener { | 321 | 321 |
| 322 | 322 | argv[A_UPGRADE] = Boolean::New(env()->isolate(), parser_.upgrade); | 323 | 323 |
| 324 | | - AsyncCallbackScope callback_scope(env()); | 325 | | - | 326 | | - MaybeLocal<Value> head_response = | 327 | | - MakeCallback(cb.As<Function>(), arraysize(argv), argv); | | 324 | + MaybeLocal<Value> head_response; | | 325 | + { | | 326 | + InternalCallbackScope callback_scope( | | 327 | + this, InternalCallbackScope::kSkipTaskQueues); | | 328 | + head_response = cb.As<Function>()->Call( | | 329 | + env()->context(), object(), arraysize(argv), argv); | | 330 | + } | 328 | 331 |
| 329 | 332 | int64_t val; | 330 | 333 |
| @@ -392,9 +395,12 @@ class Parser : public AsyncWrap, public StreamListener { | 392 | 395 | if (!cb->IsFunction()) | 393 | 396 | return 0; | 394 | 397 |
| 395 | | - AsyncCallbackScope callback_scope(env()); | 396 | | - | 397 | | - MaybeLocal<Value> r = MakeCallback(cb.As<Function>(), 0, nullptr); | | 398 | + MaybeLocal<Value> r; | | 399 | + { | | 400 | + InternalCallbackScope callback_scope( | | 401 | + this, InternalCallbackScope::kSkipTaskQueues); | | 402 | + r = cb.As<Function>()->Call(env()->context(), object(), 0, nullptr); | | 403 | + } | 398 | 404 |
| 399 | 405 | if (r.IsEmpty()) { | 400 | 406 | got_exception_ = true; | |
Collapse file Copy file name to clipboardExpand all lines: src/node_internals.h +10-4Lines changed: 10 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -206,17 +206,23 @@ v8::MaybeLocal<v8::Value> InternalMakeCallback( | 206 | 206 | class InternalCallbackScope { | 207 | 207 | public: | 208 | 208 | enum Flags { | | 209 | + kNoFlags = 0, | 209 | 210 | // Tell the constructor whether its `object` parameter may be empty or not. | 210 | 211 | kAllowEmptyResource = 1, | 211 | 212 | // Indicates whether 'before' and 'after' hooks should be skipped. | 212 | | - kSkipAsyncHooks = 2 | | 213 | + kSkipAsyncHooks = 2, | | 214 | + // Indicates whether nextTick and microtask queues should be skipped. | | 215 | + // This should only be used when there is no call into JS in this scope. | | 216 | + // (The HTTP parser also uses it for some weird backwards | | 217 | + // compatibility issues, but it shouldn't.) | | 218 | + kSkipTaskQueues = 4 | 213 | 219 | }; | 214 | 220 | InternalCallbackScope(Environment* env, | 215 | 221 | v8::Local<v8::Object> object, | 216 | 222 | const async_context& asyncContext, | 217 | | - int flags = 0); | | 223 | + int flags = kNoFlags); | 218 | 224 | // Utility that can be used by AsyncWrap classes. | 219 | | - explicit InternalCallbackScope(AsyncWrap* async_wrap); | | 225 | + explicit InternalCallbackScope(AsyncWrap* async_wrap, int flags = 0); | 220 | 226 | ~InternalCallbackScope(); | 221 | 227 | void Close(); | 222 | 228 |
| @@ -227,8 +233,8 @@ class InternalCallbackScope { | 227 | 233 | Environment* env_; | 228 | 234 | async_context async_context_; | 229 | 235 | v8::Local<v8::Object> object_; | 230 | | - AsyncCallbackScope callback_scope_; | 231 | 236 | bool skip_hooks_; | | 237 | + bool skip_task_queues_; | 232 | 238 | bool failed_ = false; | 233 | 239 | bool pushed_ids_ = false; | 234 | 240 | bool closed_ = false; | |
Collapse file Copy file name to clipboardExpand all lines: src/stream_pipe.cc +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -119,7 +119,6 @@ void StreamPipe::ReadableListener::OnStreamRead(ssize_t nread, | 119 | 119 | const uv_buf_t& buf_) { | 120 | 120 | StreamPipe* pipe = ContainerOf(&StreamPipe::readable_listener_, this); | 121 | 121 | AllocatedBuffer buf(pipe->env(), buf_); | 122 | | - AsyncScope async_scope(pipe); | 123 | 122 | if (nread < 0) { | 124 | 123 | // EOF or error; stop reading and pass the error to the previous listener | 125 | 124 | // (which might end up in JS). | @@ -162,7 +161,9 @@ void StreamPipe::WritableListener::OnStreamAfterWrite(WriteWrap* w, | 162 | 161 | StreamPipe* pipe = ContainerOf(&StreamPipe::writable_listener_, this); | 163 | 162 | pipe->is_writing_ = false; | 164 | 163 | if (pipe->is_eof_) { | 165 | | - AsyncScope async_scope(pipe); | | 164 | + HandleScope handle_scope(pipe->env()->isolate()); | | 165 | + InternalCallbackScope callback_scope(pipe, | | 166 | + InternalCallbackScope::kSkipTaskQueues); | 166 | 167 | pipe->ShutdownWritable(); | 167 | 168 | pipe->Unpipe(); | 168 | 169 | return; | @@ -206,7 +207,9 @@ void StreamPipe::WritableListener::OnStreamWantsWrite(size_t suggested_size) { | 206 | 207 | pipe->wanted_data_ = suggested_size; | 207 | 208 | if (pipe->is_reading_ || pipe->is_closed_) | 208 | 209 | return; | 209 | | - AsyncScope async_scope(pipe); | | 210 | + HandleScope handle_scope(pipe->env()->isolate()); | | 211 | + InternalCallbackScope callback_scope(pipe, | | 212 | + InternalCallbackScope::kSkipTaskQueues); | 210 | 213 | pipe->is_reading_ = true; | 211 | 214 | pipe->source()->ReadStart(); | 212 | 215 | } | |
|