microtasks_runner.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/microtasks_runner.h"
  5. #include "shell/browser/electron_browser_main_parts.h"
  6. #include "shell/browser/javascript_environment.h"
  7. #include "shell/common/node_includes.h"
  8. #include "v8/include/v8.h"
  9. namespace electron {
  10. MicrotasksRunner::MicrotasksRunner(v8::Isolate* isolate) : isolate_(isolate) {}
  11. void MicrotasksRunner::WillProcessTask(const base::PendingTask& pending_task,
  12. bool was_blocked_or_low_priority) {}
  13. void MicrotasksRunner::DidProcessTask(const base::PendingTask& pending_task) {
  14. v8::Isolate::Scope scope(isolate_);
  15. // In the browser process we follow Node.js microtask policy of kExplicit
  16. // and let the MicrotaskRunner which is a task observer for chromium UI thread
  17. // scheduler run the microtask checkpoint. This worked fine because Node.js
  18. // also runs microtasks through its task queue, but after
  19. // https://github.com/electron/electron/issues/20013 Node.js now performs its
  20. // own microtask checkpoint and it may happen is some situations that there is
  21. // contention for performing checkpoint between Node.js and chromium, ending
  22. // up Node.js dealying its callbacks. To fix this, now we always lets Node.js
  23. // handle the checkpoint in the browser process.
  24. {
  25. v8::HandleScope scope(isolate_);
  26. node::CallbackScope microtasks_scope(isolate_, v8::Object::New(isolate_),
  27. {0, 0});
  28. }
  29. }
  30. } // namespace electron