| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e3371f0 commit 0072a8e
8 files changed
| 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 | ||
| 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, | |
| 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: | |
| 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 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -721,20 +721,6 @@ class AsyncHooks : public MemoryRetainer { | |||
| 721 | 721 | void grow_async_ids_stack(); | |
| 722 | 722 | }; | |
| 723 | 723 | ||
| 724 | - class AsyncCallbackScope { | ||
| 725 | - public: | ||
| 726 | - AsyncCallbackScope() = delete; | ||
| 727 | - explicit AsyncCallbackScope(Environment* env); | ||
| 728 | - ~AsyncCallbackScope(); | ||
| 729 | - AsyncCallbackScope(const AsyncCallbackScope&) = delete; | ||
| 730 | - AsyncCallbackScope& operator=(const AsyncCallbackScope&) = delete; | ||
| 731 | - AsyncCallbackScope(AsyncCallbackScope&&) = delete; | ||
| 732 | - AsyncCallbackScope& operator=(AsyncCallbackScope&&) = delete; | ||
| 733 | - | ||
| 734 | - private: | ||
| 735 | - Environment* env_; | ||
| 736 | - }; | ||
| 737 | - | ||
| 738 | 724 | class ImmediateInfo : public MemoryRetainer { | |
| 739 | 725 | public: | |
| 740 | 726 | inline AliasedUint32Array& fields(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -310,10 +310,13 @@ class Parser : public AsyncWrap, public StreamListener { | |||
| 310 | 310 | ||
| 311 | 311 | argv[A_UPGRADE] = Boolean::New(env()->isolate(), parser_.upgrade); | |
| 312 | 312 | ||
| 313 | - AsyncCallbackScope callback_scope(env()); | ||
| 314 | - | ||
| 315 | - MaybeLocal<Value> head_response = | ||
| 316 | - MakeCallback(cb.As<Function>(), arraysize(argv), argv); | ||
| 313 | + MaybeLocal<Value> head_response; | ||
| 314 | + { | ||
| 315 | + InternalCallbackScope callback_scope( | ||
| 316 | + this, InternalCallbackScope::kSkipTaskQueues); | ||
| 317 | + head_response = cb.As<Function>()->Call( | ||
| 318 | + env()->context(), object(), arraysize(argv), argv); | ||
| 319 | + } | ||
| 317 | 320 | ||
| 318 | 321 | int64_t val; | |
| 319 | 322 | ||
@@ -379,9 +382,12 @@ class Parser : public AsyncWrap, public StreamListener { | |||
| 379 | 382 | if (!cb->IsFunction()) | |
| 380 | 383 | return 0; | |
| 381 | 384 | ||
| 382 | - AsyncCallbackScope callback_scope(env()); | ||
| 383 | - | ||
| 384 | - MaybeLocal<Value> r = MakeCallback(cb.As<Function>(), 0, nullptr); | ||
| 385 | + MaybeLocal<Value> r; | ||
| 386 | + { | ||
| 387 | + InternalCallbackScope callback_scope( | ||
| 388 | + this, InternalCallbackScope::kSkipTaskQueues); | ||
| 389 | + r = cb.As<Function>()->Call(env()->context(), object(), 0, nullptr); | ||
| 390 | + } | ||
| 385 | 391 | ||
| 386 | 392 | if (r.IsEmpty()) { | |
| 387 | 393 | got_exception_ = true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -204,17 +204,23 @@ v8::MaybeLocal<v8::Value> InternalMakeCallback( | |||
| 204 | 204 | class InternalCallbackScope { | |
| 205 | 205 | public: | |
| 206 | 206 | enum Flags { | |
| 207 | + kNoFlags = 0, | ||
| 207 | 208 | // Tell the constructor whether its `object` parameter may be empty or not. | |
| 208 | 209 | kAllowEmptyResource = 1, | |
| 209 | 210 | // Indicates whether 'before' and 'after' hooks should be skipped. | |
| 210 | - kSkipAsyncHooks = 2 | ||
| 211 | + kSkipAsyncHooks = 2, | ||
| 212 | + // Indicates whether nextTick and microtask queues should be skipped. | ||
| 213 | + // This should only be used when there is no call into JS in this scope. | ||
| 214 | + // (The HTTP parser also uses it for some weird backwards | ||
| 215 | + // compatibility issues, but it shouldn't.) | ||
| 216 | + kSkipTaskQueues = 4 | ||
| 211 | 217 | }; | |
| 212 | 218 | InternalCallbackScope(Environment* env, | |
| 213 | 219 | v8::Local<v8::Object> object, | |
| 214 | 220 | const async_context& asyncContext, | |
| 215 | - int flags = 0); | ||
| 221 | + int flags = kNoFlags); | ||
| 216 | 222 | // Utility that can be used by AsyncWrap classes. | |
| 217 | - explicit InternalCallbackScope(AsyncWrap* async_wrap); | ||
| 223 | + explicit InternalCallbackScope(AsyncWrap* async_wrap, int flags = 0); | ||
| 218 | 224 | ~InternalCallbackScope(); | |
| 219 | 225 | void Close(); | |
| 220 | 226 | ||
@@ -225,8 +231,8 @@ class InternalCallbackScope { | |||
| 225 | 231 | Environment* env_; | |
| 226 | 232 | async_context async_context_; | |
| 227 | 233 | v8::Local<v8::Object> object_; | |
| 228 | - AsyncCallbackScope callback_scope_; | ||
| 229 | 234 | bool skip_hooks_; | |
| 235 | + bool skip_task_queues_; | ||
| 230 | 236 | bool failed_ = false; | |
| 231 | 237 | bool pushed_ids_ = false; | |
| 232 | 238 | bool closed_ = false; | |
| 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 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments