};
/**
+ * Do not run microtasks while this scope is active, even if microtasks are
+ * automatically executed otherwise.
+ */
+ class V8_EXPORT SuppressMicrotaskExecutionScope {
+ public:
+ explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
+ ~SuppressMicrotaskExecutionScope();
+
+ private:
+ internal::Isolate* isolate_;
+
+ // Prevent copying of Scope objects.
+ SuppressMicrotaskExecutionScope(const SuppressMicrotaskExecutionScope&);
+ SuppressMicrotaskExecutionScope& operator=(
+ const SuppressMicrotaskExecutionScope&);
+ };
+
+ /**
* Types of garbage collections that can be requested via
* RequestGarbageCollectionForTesting.
*/
*/
void RemoveCallCompletedCallback(CallCompletedCallback callback);
+ /**
+ * Experimental: Runs the Microtask Work Queue until empty
+ */
+ void RunMicrotasks();
+
+ /**
+ * Experimental: Enqueues the callback to the Microtask Work Queue
+ */
+ void EnqueueMicrotask(Handle<Function> microtask);
+
+ /**
+ * Experimental: Controls whether the Microtask Work Queue is automatically
+ * run when the script call depth decrements to zero.
+ */
+ void SetAutorunMicrotasks(bool autorun);
+
private:
template<class K, class V, class Traits> friend class PersistentValueMap;
/**
* Experimental: Runs the Microtask Work Queue until empty
+ *
+ * Deprecated: Use methods on Isolate instead.
*/
static void RunMicrotasks(Isolate* isolate);
/**
* Experimental: Enqueues the callback to the Microtask Work Queue
+ *
+ * Deprecated: Use methods on Isolate instead.
*/
static void EnqueueMicrotask(Isolate* isolate, Handle<Function> microtask);
/**
* Experimental: Controls whether the Microtask Work Queue is automatically
* run when the script call depth decrements to zero.
+ *
+ * Deprecated: Use methods on Isolate instead.
*/
static void SetAutorunMicrotasks(Isolate *source, bool autorun);
void V8::RunMicrotasks(Isolate* isolate) {
- i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
- i::HandleScope scope(i_isolate);
- i::V8::RunMicrotasks(i_isolate);
+ isolate->RunMicrotasks();
}
void V8::EnqueueMicrotask(Isolate* isolate, Handle<Function> microtask) {
- i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
- ENTER_V8(i_isolate);
- i::Execution::EnqueueMicrotask(i_isolate, Utils::OpenHandle(*microtask));
+ isolate->EnqueueMicrotask(microtask);
}
void V8::SetAutorunMicrotasks(Isolate* isolate, bool autorun) {
- reinterpret_cast<i::Isolate*>(isolate)->set_autorun_microtasks(autorun);
+ isolate->SetAutorunMicrotasks(autorun);
}
}
+Isolate::SuppressMicrotaskExecutionScope::SuppressMicrotaskExecutionScope(
+ Isolate* isolate)
+ : isolate_(reinterpret_cast<i::Isolate*>(isolate)) {
+ isolate_->handle_scope_implementer()->IncrementCallDepth();
+}
+
+
+Isolate::SuppressMicrotaskExecutionScope::~SuppressMicrotaskExecutionScope() {
+ isolate_->handle_scope_implementer()->DecrementCallDepth();
+}
+
+
void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
if (!isolate->IsInitialized()) {
}
+void Isolate::RunMicrotasks() {
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
+ i::HandleScope scope(i_isolate);
+ i_isolate->RunMicrotasks();
+}
+
+
+void Isolate::EnqueueMicrotask(Handle<Function> microtask) {
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
+ ENTER_V8(i_isolate);
+ i::Execution::EnqueueMicrotask(i_isolate, Utils::OpenHandle(*microtask));
+}
+
+
+void Isolate::SetAutorunMicrotasks(bool autorun) {
+ reinterpret_cast<i::Isolate*>(this)->set_autorun_microtasks(autorun);
+}
+
+
String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
: str_(NULL), length_(0) {
i::Isolate* isolate = i::Isolate::Current();
CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
- v8::V8::EnqueueMicrotask(env->GetIsolate(),
- Function::New(env->GetIsolate(), MicrotaskOne));
+ env->GetIsolate()->EnqueueMicrotask(
+ Function::New(env->GetIsolate(), MicrotaskOne));
CompileRun("1+1;");
CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
- v8::V8::EnqueueMicrotask(env->GetIsolate(),
- Function::New(env->GetIsolate(), MicrotaskOne));
- v8::V8::EnqueueMicrotask(env->GetIsolate(),
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ env->GetIsolate()->EnqueueMicrotask(
+ Function::New(env->GetIsolate(), MicrotaskOne));
+ env->GetIsolate()->EnqueueMicrotask(
+ Function::New(env->GetIsolate(), MicrotaskTwo));
CompileRun("1+1;");
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value());
- v8::V8::EnqueueMicrotask(env->GetIsolate(),
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ env->GetIsolate()->EnqueueMicrotask(
+ Function::New(env->GetIsolate(), MicrotaskTwo));
CompileRun("1+1;");
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
- v8::V8::EnqueueMicrotask(env->GetIsolate(),
- Function::New(env->GetIsolate(), MicrotaskOne));
+ env->GetIsolate()->EnqueueMicrotask(
+ Function::New(env->GetIsolate(), MicrotaskOne));
CompileRun("1+1;");
CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
- V8::SetAutorunMicrotasks(env->GetIsolate(), false);
- v8::V8::EnqueueMicrotask(env->GetIsolate(),
- Function::New(env->GetIsolate(), MicrotaskOne));
- v8::V8::EnqueueMicrotask(env->GetIsolate(),
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ env->GetIsolate()->SetAutorunMicrotasks(false);
+ env->GetIsolate()->EnqueueMicrotask(
+ Function::New(env->GetIsolate(), MicrotaskOne));
+ env->GetIsolate()->EnqueueMicrotask(
+ Function::New(env->GetIsolate(), MicrotaskTwo));
CompileRun("1+1;");
CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
- V8::RunMicrotasks(env->GetIsolate());
+ env->GetIsolate()->RunMicrotasks();
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value());
- v8::V8::EnqueueMicrotask(env->GetIsolate(),
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ env->GetIsolate()->EnqueueMicrotask(
+ Function::New(env->GetIsolate(), MicrotaskTwo));
CompileRun("1+1;");
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value());
- V8::RunMicrotasks(env->GetIsolate());
+ env->GetIsolate()->RunMicrotasks();
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value());
- V8::SetAutorunMicrotasks(env->GetIsolate(), true);
- v8::V8::EnqueueMicrotask(env->GetIsolate(),
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ env->GetIsolate()->SetAutorunMicrotasks(true);
+ env->GetIsolate()->EnqueueMicrotask(
+ Function::New(env->GetIsolate(), MicrotaskTwo));
CompileRun("1+1;");
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value());
+
+ env->GetIsolate()->EnqueueMicrotask(
+ Function::New(env->GetIsolate(), MicrotaskTwo));
+ {
+ v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate());
+ CompileRun("1+1;");
+ CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
+ CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value());
+ }
+
+ CompileRun("1+1;");
+ CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
+ CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value());
}
p->Chain(f1);
CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
- V8::RunMicrotasks(isolate);
+ isolate->RunMicrotasks();
CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value());
p->Catch(f2);
- V8::RunMicrotasks(isolate);
+ isolate->RunMicrotasks();
CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
r->Catch(f2);
CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
- V8::RunMicrotasks(isolate);
+ isolate->RunMicrotasks();
CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value());
r->Chain(f1);
- V8::RunMicrotasks(isolate);
+ isolate->RunMicrotasks();
CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value());
// Chaining pending promises.
pr->GetPromise()->Chain(f1);
rr->GetPromise()->Catch(f2);
- V8::RunMicrotasks(isolate);
+ isolate->RunMicrotasks();
CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
- V8::RunMicrotasks(isolate);
+ isolate->RunMicrotasks();
CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value());
CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value());
pr->Resolve(v8::Integer::New(isolate, 3));
CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
- V8::RunMicrotasks(isolate);
+ isolate->RunMicrotasks();
CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value());
CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value());
rr->Reject(v8::Integer::New(isolate, 3));
CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value());
- V8::RunMicrotasks(isolate);
+ isolate->RunMicrotasks();
CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value());
CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value());
}