| 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
|
|
|