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

Unified Diff: include/v8.h

Issue 1741893003: Introduce v8::MicrotasksScope. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Merged scopes 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') | src/api.h » ('J')
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 db4c31e9042a855982f19b0323a0ed8496ede895..71bff6ae2ed78c1b33803f55cde1a2586dfe998b 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -5450,6 +5450,21 @@ class V8_EXPORT Isolate {
kMinorGarbageCollection
};
+
+ /**
+ * Policy for running microtasks:
+ * - explicit: microtasks are invoked with RunMicrotasks() method;
+ * - scoped: microtasks invocation is controlled by MicrotasksScope objects;
+ * - auto: microtasks are invoked when the script call depth decrements
+ * to zero.
+ */
+ enum MicrotasksPolicy {
jochen (gone - plz use gerrit) 2016/03/01 14:26:08 i'd prefer an enum class
dgozman 2016/03/03 01:22:06 Done.
+ kExplicitMicrotasksInvocation,
+ kScopedMicrotasksInvocation,
+ kAutoMicrotasksInvocation
+ };
+
+
/**
* Features reported via the SetUseCounterCallback callback. Do not change
* assigned numbers of existing items; add new features to the end of this
@@ -5884,17 +5899,22 @@ 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
@@ -6144,6 +6164,41 @@ class V8_EXPORT StartupData {
/**
+ * 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*);
+
+ /**
+ * Returns current recursion level of scope objects.
+ */
+ static int GetRecursionLevel(Isolate*);
+
+ private:
+ void* internal_;
+
+ // Prevent copying.
+ MicrotasksScope(const MicrotasksScope&);
+ MicrotasksScope& operator=(const MicrotasksScope&);
+};
+
+
+/**
* EntropySource is used as a callback function when v8 needs a source
* of entropy.
*/
« no previous file with comments | « no previous file | src/api.h » ('j') | src/api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698