OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #error both DEBUG and NDEBUG are set | 51 #error both DEBUG and NDEBUG are set |
52 #endif | 52 #endif |
53 | 53 |
54 // Basic includes | 54 // Basic includes |
55 #include "../include/v8.h" | 55 #include "../include/v8.h" |
56 #include "globals.h" | 56 #include "globals.h" |
57 #include "checks.h" | 57 #include "checks.h" |
58 #include "allocation.h" | 58 #include "allocation.h" |
59 #include "utils.h" | 59 #include "utils.h" |
60 #include "flags.h" | 60 #include "flags.h" |
| 61 #include "v8-global-context.h" |
61 | 62 |
62 // Objects & heap | 63 // Objects & heap |
63 #include "objects.h" | 64 #include "objects.h" |
64 #include "spaces.h" | 65 #include "spaces.h" |
65 #include "heap.h" | 66 #include "heap.h" |
66 #include "objects-inl.h" | 67 #include "objects-inl.h" |
67 #include "spaces-inl.h" | 68 #include "spaces-inl.h" |
68 #include "heap-inl.h" | 69 #include "heap-inl.h" |
69 #include "log-inl.h" | 70 #include "log-inl.h" |
70 #include "messages.h" | 71 #include "messages.h" |
71 | 72 |
72 namespace v8 { | 73 namespace v8 { |
73 namespace internal { | 74 namespace internal { |
74 | 75 |
75 class Deserializer; | 76 class Deserializer; |
| 77 class V8; |
| 78 |
| 79 class V8Data { |
| 80 public: |
| 81 FatalErrorCallback exception_behavior() const { |
| 82 return exception_behavior_; |
| 83 } |
| 84 |
| 85 void exception_behavior(FatalErrorCallback exception_behavior) { |
| 86 exception_behavior_ = exception_behavior; |
| 87 } |
| 88 private: |
| 89 // Track whether this V8 instance has ever called v8::Locker. This allows the |
| 90 // API code to verify that the lock is always held when V8 is being entered. |
| 91 |
| 92 bool active_; |
| 93 |
| 94 // True if engine is currently running |
| 95 bool is_running_; |
| 96 // True if V8 has ever been run |
| 97 bool has_been_setup_; |
| 98 // True if error has been signaled for current engine |
| 99 // (reset to false if engine is restarted) |
| 100 bool has_fatal_error_; |
| 101 // True if engine has been shut down |
| 102 // (reset if engine is restarted) |
| 103 bool has_been_disposed_; |
| 104 |
| 105 // --- E x c e p t i o n B e h a v i o r --- |
| 106 FatalErrorCallback exception_behavior_; |
| 107 |
| 108 V8Data(); |
| 109 |
| 110 friend class V8Context; |
| 111 friend class V8; |
| 112 friend class Locker; |
| 113 DISALLOW_COPY_AND_ASSIGN(V8Data); |
| 114 }; |
76 | 115 |
77 class V8 : public AllStatic { | 116 class V8 : public AllStatic { |
78 public: | 117 public: |
79 // Global actions. | 118 // Global actions. |
80 | 119 |
81 // If Initialize is called with des == NULL, the initial state is | 120 // If Initialize is called with des == NULL, the initial state is |
82 // created from scratch. If a non-null Deserializer is given, the | 121 // created from scratch. If a non-null Deserializer is given, the |
83 // initial state is created by reading the deserialized data into an | 122 // initial state is created by reading the deserialized data into an |
84 // empty heap. | 123 // empty heap. |
85 static bool Initialize(Deserializer* des); | 124 static bool Initialize(Deserializer* des); |
86 static void TearDown(); | 125 static void TearDown(); |
87 static bool IsRunning() { return is_running_; } | 126 static bool IsRunning() { return v8_context()->v8_data_.is_running_; } |
88 // To be dead you have to have lived | 127 // To be dead you have to have lived |
89 static bool IsDead() { return has_fatal_error_ || has_been_disposed_; } | 128 static bool IsDead() { |
| 129 return v8_context()->v8_data_.has_fatal_error_ || |
| 130 v8_context()->v8_data_.has_been_disposed_; |
| 131 } |
90 static void SetFatalError(); | 132 static void SetFatalError(); |
91 | 133 |
92 // Report process out of memory. Implementation found in api.cc. | 134 // Report process out of memory. Implementation found in api.cc. |
93 static void FatalProcessOutOfMemory(const char* location); | 135 static void FatalProcessOutOfMemory(const char* location); |
94 | 136 |
95 // Random number generation support. Not cryptographically safe. | 137 // Random number generation support. Not cryptographically safe. |
96 static uint32_t Random(); | 138 static uint32_t Random(); |
97 static Smi* RandomPositiveSmi(); | 139 static Smi* RandomPositiveSmi(); |
98 | 140 |
99 // Idle notification directly from the API. | 141 // Idle notification directly from the API. |
100 static bool IdleNotification(); | 142 static bool IdleNotification(); |
101 | |
102 private: | |
103 // True if engine is currently running | |
104 static bool is_running_; | |
105 // True if V8 has ever been run | |
106 static bool has_been_setup_; | |
107 // True if error has been signaled for current engine | |
108 // (reset to false if engine is restarted) | |
109 static bool has_fatal_error_; | |
110 // True if engine has been shut down | |
111 // (reset if engine is restarted) | |
112 static bool has_been_disposed_; | |
113 }; | 143 }; |
114 | 144 |
115 } } // namespace v8::internal | 145 } } // namespace v8::internal |
116 | 146 |
117 namespace i = v8::internal; | 147 namespace i = v8::internal; |
118 | 148 |
119 #endif // V8_V8_H_ | 149 #endif // V8_V8_H_ |
OLD | NEW |