Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(782)

Unified Diff: include/v8.h

Issue 1741893003: Introduce v8::MicrotasksScope. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: SetAutorunMicrotasks fix Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index f804496eaf6d4a8b2bce8be8708fdcbc6e7fb350..dc2479406797383cbfd714c2069d1cf17fb7b68e 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -5059,6 +5059,53 @@ typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
typedef void (*MicrotasksCompletedCallback)(Isolate*);
typedef void (*MicrotaskCallback)(void* data);
+
+/**
+ * Policy for running microtasks:
+ * - explicit: microtasks are invoked with Isolate::RunMicrotasks() method;
+ * - scoped: microtasks invocation is controlled by MicrotasksScope objects;
+ * - auto: microtasks are invoked when the script call depth decrements
+ * to zero.
+ */
+enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
+
+
+/**
+ * This scope is used to control microtasks when kScopeMicrotasksInvocation
+ * is used on Isolate. In this mode every non-primitive call to V8 should be
+ * done inside some MicrotasksScope.
+ * Microtasks are executed when topmost MicrotasksScope marked as kRunMicrotasks
+ * exits.
+ * kDoNotRunMicrotasks should be used to annotate calls not intended to trigger
+ * microtasks.
+ */
+class V8_EXPORT MicrotasksScope {
+ public:
+ enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
+
+ MicrotasksScope(Isolate* isolate, Type type);
+ ~MicrotasksScope();
+
+ /**
+ * Runs microtasks if no kRunMicrotasks scope is currently active.
+ */
+ static void PerformCheckpoint(Isolate* isolate);
+
+ /**
+ * Returns current depth of nested kRunMicrotasks scopes.
+ */
+ static int GetCurrentDepth(Isolate* isolate);
+
+ private:
+ internal::Isolate* const isolate_;
+ bool run_;
+
+ // Prevent copying.
+ MicrotasksScope(const MicrotasksScope&);
+ MicrotasksScope& operator=(const MicrotasksScope&);
+};
+
+
// --- Failed Access Check Callback ---
typedef void (*FailedAccessCheckCallback)(Local<Object> target,
AccessType type,
@@ -5884,17 +5931,20 @@ class V8_EXPORT Isolate {
*/
void EnqueueMicrotask(MicrotaskCallback microtask, void* data = NULL);
- /**
- * Experimental: Controls whether the Microtask Work Queue is automatically
- * run when the script call depth decrements to zero.
+ /**
+ * Experimental: Controls how Microtasks are invoked. See MicrotasksPolicy
+ * for details.
*/
- void SetAutorunMicrotasks(bool autorun);
+ void SetMicrotasksPolicy(MicrotasksPolicy policy);
+ V8_DEPRECATE_SOON("Use SetMicrotasksPolicy",
+ void SetAutorunMicrotasks(bool autorun));
/**
- * Experimental: Returns whether the Microtask Work Queue is automatically
- * run when the script call depth decrements to zero.
+ * Experimental: Returns the policy controlling how Microtasks are invoked.
*/
- bool WillAutorunMicrotasks() const;
+ MicrotasksPolicy GetMicrotasksPolicy() const;
+ V8_DEPRECATE_SOON("Use GetMicrotasksPolicy",
+ bool WillAutorunMicrotasks() const);
/**
* Experimental: adds a callback to notify the host application after
« no previous file with comments | « no previous file | src/api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698