Index: src/d8.cc |
diff --git a/src/d8.cc b/src/d8.cc |
index b73ab0bd6a6be5b171a1c1258d65e05c0c8f079f..6494727a6c8b69ff6269cc83b35076d1b4e184da 100644 |
--- a/src/d8.cc |
+++ b/src/d8.cc |
@@ -101,6 +101,48 @@ class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
}; |
+#ifndef V8_SHARED |
+// Predictable v8::Platform implementation. All background and foreground |
+// tasks are run immediately, delayed tasks are not executed at all. |
+class PredictablePlatform : public Platform { |
+ public: |
+ PredictablePlatform() {} |
+ |
+ void CallOnBackgroundThread(Task* task, |
+ ExpectedRuntime expected_runtime) override { |
+ task->Run(); |
+ delete task; |
+ } |
+ |
+ void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override { |
+ task->Run(); |
+ delete task; |
+ } |
+ |
+ void CallDelayedOnForegroundThread(v8::Isolate* isolate, Task* task, |
+ double delay_in_seconds) override { |
+ delete task; |
+ } |
+ |
+ void CallIdleOnForegroundThread(v8::Isolate* isolate, |
+ IdleTask* task) override { |
+ UNREACHABLE(); |
+ } |
+ |
+ bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; } |
+ |
+ double MonotonicallyIncreasingTime() override { |
+ return synthetic_time_in_sec_ += 0.00001; |
+ } |
+ |
+ private: |
+ double synthetic_time_in_sec_ = 0.0; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PredictablePlatform); |
+}; |
+#endif // !V8_SHARED |
+ |
+ |
v8::Platform* g_platform = NULL; |
@@ -425,13 +467,11 @@ int PerIsolateData::RealmIndexOrThrow( |
#ifndef V8_SHARED |
// performance.now() returns a time stamp as double, measured in milliseconds. |
-// When FLAG_verify_predictable mode is enabled it returns current value |
-// of Heap::allocations_count(). |
+// When FLAG_verify_predictable mode is enabled it returns result of |
+// v8::Platform::MonotonicallyIncreasingTime(). |
void Shell::PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args) { |
if (i::FLAG_verify_predictable) { |
- Isolate* v8_isolate = args.GetIsolate(); |
- i::Heap* heap = reinterpret_cast<i::Isolate*>(v8_isolate)->heap(); |
- args.GetReturnValue().Set(heap->synthetic_time()); |
+ args.GetReturnValue().Set(g_platform->MonotonicallyIncreasingTime()); |
} else { |
base::TimeDelta delta = |
base::TimeTicks::HighResolutionNow() - kInitialTicks; |
@@ -2016,7 +2056,13 @@ void Shell::CollectGarbage(Isolate* isolate) { |
void Shell::EmptyMessageQueues(Isolate* isolate) { |
- while (v8::platform::PumpMessageLoop(g_platform, isolate)) continue; |
+#ifndef V8_SHARED |
+ if (!i::FLAG_verify_predictable) { |
+#endif |
+ while (v8::platform::PumpMessageLoop(g_platform, isolate)) continue; |
+#ifndef V8_SHARED |
+ } |
+#endif |
} |
@@ -2358,7 +2404,14 @@ int Shell::Main(int argc, char* argv[]) { |
#endif // defined(_WIN32) || defined(_WIN64) |
if (!SetOptions(argc, argv)) return 1; |
v8::V8::InitializeICU(options.icu_data_file); |
+#ifndef V8_SHARED |
+ g_platform = i::FLAG_verify_predictable |
+ ? new PredictablePlatform() |
+ : v8::platform::CreateDefaultPlatform(); |
+#else |
g_platform = v8::platform::CreateDefaultPlatform(); |
+#endif // !V8_SHARED |
+ |
v8::V8::InitializePlatform(g_platform); |
v8::V8::Initialize(); |
if (options.natives_blob || options.snapshot_blob) { |