v8  4.5.103 (node 4.8.7)
V8 is Google's open source JavaScript engine
v8-platform.h
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_V8_PLATFORM_H_
6 #define V8_V8_PLATFORM_H_
7 
8 namespace v8 {
9 
10 class Isolate;
11 
12 /**
13  * A Task represents a unit of work.
14  */
15 class Task {
16  public:
17  virtual ~Task() {}
18 
19  virtual void Run() = 0;
20 };
21 
22 /**
23  * V8 Platform abstraction layer.
24  *
25  * The embedder has to provide an implementation of this interface before
26  * initializing the rest of V8.
27  */
28 class Platform {
29  public:
30  /**
31  * This enum is used to indicate whether a task is potentially long running,
32  * or causes a long wait. The embedder might want to use this hint to decide
33  * whether to execute the task on a dedicated thread.
34  */
38  };
39 
40  virtual ~Platform() {}
41 
42  /**
43  * Schedules a task to be invoked on a background thread. |expected_runtime|
44  * indicates that the task will run a long time. The Platform implementation
45  * takes ownership of |task|. There is no guarantee about order of execution
46  * of tasks wrt order of scheduling, nor is there a guarantee about the
47  * thread the task will be run on.
48  */
49  virtual void CallOnBackgroundThread(Task* task,
50  ExpectedRuntime expected_runtime) = 0;
51 
52  /**
53  * Schedules a task to be invoked on a foreground thread wrt a specific
54  * |isolate|. Tasks posted for the same isolate should be execute in order of
55  * scheduling. The definition of "foreground" is opaque to V8.
56  */
57  virtual void CallOnForegroundThread(Isolate* isolate, Task* task) = 0;
58 
59  /**
60  * Schedules a task to be invoked on a foreground thread wrt a specific
61  * |isolate| after the given number of seconds |delay_in_seconds|.
62  * Tasks posted for the same isolate should be execute in order of
63  * scheduling. The definition of "foreground" is opaque to V8.
64  */
65  virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
66  double delay_in_seconds) {
67  // TODO(ulan): Make this function abstract after V8 roll in Chromium.
68  }
69 
70  /**
71  * Monotonically increasing time in seconds from an arbitrary fixed point in
72  * the past. This function is expected to return at least
73  * millisecond-precision values. For this reason,
74  * it is recommended that the fixed point be no further in the past than
75  * the epoch.
76  **/
77  virtual double MonotonicallyIncreasingTime() = 0;
78 };
79 
80 } // namespace v8
81 
82 #endif // V8_V8_PLATFORM_H_