| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e11a376 commit ce13d43
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,12 +43,13 @@ InternalCallbackScope::InternalCallbackScope(AsyncWrap* async_wrap) | |||
| 43 | 43 | InternalCallbackScope::InternalCallbackScope(Environment* env, | |
| 44 | 44 | Local<Object> object, | |
| 45 | 45 | const async_context& asyncContext, | |
| 46 | - ResourceExpectation expect) | ||
| 46 | + int flags) | ||
| 47 | 47 | : env_(env), | |
| 48 | 48 | async_context_(asyncContext), | |
| 49 | 49 | object_(object), | |
| 50 | - callback_scope_(env) { | ||
| 51 | - CHECK_IMPLIES(expect == kRequireResource, !object.IsEmpty()); | ||
| 50 | + callback_scope_(env), | ||
| 51 | + skip_hooks_(flags & kSkipAsyncHooks) { | ||
| 52 | + CHECK_IMPLIES(!(flags & kAllowEmptyResource), !object.IsEmpty()); | ||
| 52 | 53 | CHECK_NOT_NULL(env); | |
| 53 | 54 | ||
| 54 | 55 | if (!env->can_call_into_js()) { | |
@@ -60,7 +61,7 @@ InternalCallbackScope::InternalCallbackScope(Environment* env, | |||
| 60 | 61 | // If you hit this assertion, you forgot to enter the v8::Context first. | |
| 61 | 62 | CHECK_EQ(Environment::GetCurrent(env->isolate()), env); | |
| 62 | 63 | ||
| 63 | - if (asyncContext.async_id != 0) { | ||
| 64 | + if (asyncContext.async_id != 0 && !skip_hooks_) { | ||
| 64 | 65 | // No need to check a return value because the application will exit if | |
| 65 | 66 | // an exception occurs. | |
| 66 | 67 | AsyncWrap::EmitBefore(env, asyncContext.async_id); | |
@@ -89,7 +90,7 @@ void InternalCallbackScope::Close() { | |||
| 89 | 90 | ||
| 90 | 91 | if (failed_) return; | |
| 91 | 92 | ||
| 92 | - if (async_context_.async_id != 0) { | ||
| 93 | + if (async_context_.async_id != 0 && !skip_hooks_) { | ||
| 93 | 94 | AsyncWrap::EmitAfter(env_, async_context_.async_id); | |
| 94 | 95 | } | |
| 95 | 96 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -374,13 +374,8 @@ MaybeLocal<Value> StartExecution(Environment* env, const char* main_script_id) { | |||
| 374 | 374 | ->GetFunction(env->context()) | |
| 375 | 375 | .ToLocalChecked()}; | |
| 376 | 376 | ||
| 377 | - Local<Value> result; | ||
| 378 | - if (!ExecuteBootstrapper(env, main_script_id, ¶meters, &arguments) | ||
| 379 | - .ToLocal(&result) || | ||
| 380 | - !task_queue::RunNextTicksNative(env)) { | ||
| 381 | - return MaybeLocal<Value>(); | ||
| 382 | - } | ||
| 383 | - return scope.Escape(result); | ||
| 377 | + return scope.EscapeMaybe( | ||
| 378 | + ExecuteBootstrapper(env, main_script_id, ¶meters, &arguments)); | ||
| 384 | 379 | } | |
| 385 | 380 | ||
| 386 | 381 | MaybeLocal<Value> StartMainThreadExecution(Environment* env) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -205,12 +205,16 @@ v8::MaybeLocal<v8::Value> InternalMakeCallback( | |||
| 205 | 205 | ||
| 206 | 206 | class InternalCallbackScope { | |
| 207 | 207 | public: | |
| 208 | - // Tell the constructor whether its `object` parameter may be empty or not. | ||
| 209 | - enum ResourceExpectation { kRequireResource, kAllowEmptyResource }; | ||
| 208 | + enum Flags { | ||
| 209 | + // Tell the constructor whether its `object` parameter may be empty or not. | ||
| 210 | + kAllowEmptyResource = 1, | ||
| 211 | + // Indicates whether 'before' and 'after' hooks should be skipped. | ||
| 212 | + kSkipAsyncHooks = 2 | ||
| 213 | + }; | ||
| 210 | 214 | InternalCallbackScope(Environment* env, | |
| 211 | 215 | v8::Local<v8::Object> object, | |
| 212 | 216 | const async_context& asyncContext, | |
| 213 | - ResourceExpectation expect = kRequireResource); | ||
| 217 | + int flags = 0); | ||
| 214 | 218 | // Utility that can be used by AsyncWrap classes. | |
| 215 | 219 | explicit InternalCallbackScope(AsyncWrap* async_wrap); | |
| 216 | 220 | ~InternalCallbackScope(); | |
@@ -224,6 +228,7 @@ class InternalCallbackScope { | |||
| 224 | 228 | async_context async_context_; | |
| 225 | 229 | v8::Local<v8::Object> object_; | |
| 226 | 230 | AsyncCallbackScope callback_scope_; | |
| 231 | + bool skip_hooks_; | ||
| 227 | 232 | bool failed_ = false; | |
| 228 | 233 | bool pushed_ids_ = false; | |
| 229 | 234 | bool closed_ = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,7 @@ using v8::HandleScope; | |||
| 18 | 18 | using v8::Isolate; | |
| 19 | 19 | using v8::Local; | |
| 20 | 20 | using v8::Locker; | |
| 21 | + using v8::Object; | ||
| 21 | 22 | using v8::SealHandleScope; | |
| 22 | 23 | ||
| 23 | 24 | NodeMainInstance::NodeMainInstance(Isolate* isolate, | |
@@ -112,10 +113,13 @@ int NodeMainInstance::Run() { | |||
| 112 | 113 | ||
| 113 | 114 | if (exit_code == 0) { | |
| 114 | 115 | { | |
| 115 | - AsyncCallbackScope callback_scope(env.get()); | ||
| 116 | - env->async_hooks()->push_async_ids(1, 0); | ||
| 116 | + InternalCallbackScope callback_scope( | ||
| 117 | + env.get(), | ||
| 118 | + Local<Object>(), | ||
| 119 | + { 1, 0 }, | ||
| 120 | + InternalCallbackScope::kAllowEmptyResource | | ||
| 121 | + InternalCallbackScope::kSkipAsyncHooks); | ||
| 117 | 122 | LoadEnvironment(env.get()); | |
| 118 | - env->async_hooks()->pop_async_id(1); | ||
| 119 | 123 | } | |
| 120 | 124 | ||
| 121 | 125 | env->set_trace_sync_io(env->options()->trace_sync_io); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,15 +34,6 @@ v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env, | |||
| 34 | 34 | v8::MaybeLocal<v8::Object> CreateProcessObject(Environment* env); | |
| 35 | 35 | void PatchProcessObject(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 36 | 36 | ||
| 37 | - namespace task_queue { | ||
| 38 | - // Handle any nextTicks added in the first tick of the program. | ||
| 39 | - // We use the native version here for once so that any microtasks | ||
| 40 | - // created by the main module is then handled from C++, and | ||
| 41 | - // the call stack of the main script does not show up in the async error | ||
| 42 | - // stack trace. | ||
| 43 | - bool RunNextTicksNative(Environment* env); | ||
| 44 | - } // namespace task_queue | ||
| 45 | - | ||
| 46 | 37 | } // namespace node | |
| 47 | 38 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| 48 | 39 | #endif // SRC_NODE_PROCESS_H_ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,22 +41,6 @@ static void EnqueueMicrotask(const FunctionCallbackInfo<Value>& args) { | |||
| 41 | 41 | isolate->EnqueueMicrotask(args[0].As<Function>()); | |
| 42 | 42 | } | |
| 43 | 43 | ||
| 44 | - // Should be in sync with runNextTicks in internal/process/task_queues.js | ||
| 45 | - bool RunNextTicksNative(Environment* env) { | ||
| 46 | - OnScopeLeave weakref_cleanup([&]() { env->RunWeakRefCleanup(); }); | ||
| 47 | - | ||
| 48 | - TickInfo* tick_info = env->tick_info(); | ||
| 49 | - if (!tick_info->has_tick_scheduled() && !tick_info->has_rejection_to_warn()) | ||
| 50 | - MicrotasksScope::PerformCheckpoint(env->isolate()); | ||
| 51 | - if (!tick_info->has_tick_scheduled() && !tick_info->has_rejection_to_warn()) | ||
| 52 | - return true; | ||
| 53 | - | ||
| 54 | - Local<Function> callback = env->tick_callback_function(); | ||
| 55 | - CHECK(!callback.IsEmpty()); | ||
| 56 | - return !callback->Call(env->context(), env->process_object(), 0, nullptr) | ||
| 57 | - .IsEmpty(); | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | 44 | static void RunMicrotasks(const FunctionCallbackInfo<Value>& args) { | |
| 61 | 45 | MicrotasksScope::PerformCheckpoint(args.GetIsolate()); | |
| 62 | 46 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -254,17 +254,20 @@ void Worker::Run() { | |||
| 254 | 254 | env_->InitializeInspector(std::move(inspector_parent_handle_)); | |
| 255 | 255 | #endif | |
| 256 | 256 | HandleScope handle_scope(isolate_); | |
| 257 | - AsyncCallbackScope callback_scope(env_.get()); | ||
| 258 | - env_->async_hooks()->push_async_ids(1, 0); | ||
| 257 | + InternalCallbackScope callback_scope( | ||
| 258 | + env_.get(), | ||
| 259 | + Local<Object>(), | ||
| 260 | + { 1, 0 }, | ||
| 261 | + InternalCallbackScope::kAllowEmptyResource | | ||
| 262 | + InternalCallbackScope::kSkipAsyncHooks); | ||
| 263 | + | ||
| 259 | 264 | if (!env_->RunBootstrapping().IsEmpty()) { | |
| 260 | 265 | CreateEnvMessagePort(env_.get()); | |
| 261 | 266 | if (is_stopped()) return; | |
| 262 | 267 | Debug(this, "Created message port for worker %llu", thread_id_); | |
| 263 | 268 | USE(StartExecution(env_.get(), "internal/main/worker_thread")); | |
| 264 | 269 | } | |
| 265 | 270 | ||
| 266 | - env_->async_hooks()->pop_async_id(1); | ||
| 267 | - | ||
| 268 | 271 | Debug(this, "Loaded environment for worker %llu", thread_id_); | |
| 269 | 272 | } | |
| 270 | 273 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments