erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_D8_H_ |
| 29 | #define V8_D8_H_ |
| 30 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 31 | #ifndef V8_SHARED |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 32 | #include "allocation.h" |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 33 | #include "hashmap.h" |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 34 | #include "smart-pointers.h" |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 35 | #include "v8.h" |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 36 | #else |
| 37 | #include "../include/v8.h" |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 38 | #endif // V8_SHARED |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 39 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 40 | namespace v8 { |
| 41 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 42 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 43 | #ifndef V8_SHARED |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 44 | // A single counter in a counter collection. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 45 | class Counter { |
| 46 | public: |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 47 | static const int kMaxNameSize = 64; |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 48 | int32_t* Bind(const char* name, bool histogram); |
| 49 | int32_t* ptr() { return &count_; } |
| 50 | int32_t count() { return count_; } |
| 51 | int32_t sample_total() { return sample_total_; } |
| 52 | bool is_histogram() { return is_histogram_; } |
| 53 | void AddSample(int32_t sample); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 54 | private: |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 55 | int32_t count_; |
| 56 | int32_t sample_total_; |
| 57 | bool is_histogram_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 58 | uint8_t name_[kMaxNameSize]; |
| 59 | }; |
| 60 | |
| 61 | |
| 62 | // A set of counters and associated information. An instance of this |
| 63 | // class is stored directly in the memory-mapped counters file if |
| 64 | // the --map-counters options is used |
| 65 | class CounterCollection { |
| 66 | public: |
| 67 | CounterCollection(); |
| 68 | Counter* GetNextCounter(); |
| 69 | private: |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 70 | static const unsigned kMaxCounters = 512; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 71 | uint32_t magic_number_; |
| 72 | uint32_t max_counters_; |
| 73 | uint32_t max_name_size_; |
| 74 | uint32_t counters_in_use_; |
| 75 | Counter counters_[kMaxCounters]; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 79 | class CounterMap { |
| 80 | public: |
| 81 | CounterMap(): hash_map_(Match) { } |
| 82 | Counter* Lookup(const char* name) { |
| 83 | i::HashMap::Entry* answer = hash_map_.Lookup( |
| 84 | const_cast<char*>(name), |
| 85 | Hash(name), |
| 86 | false); |
| 87 | if (!answer) return NULL; |
| 88 | return reinterpret_cast<Counter*>(answer->value); |
| 89 | } |
| 90 | void Set(const char* name, Counter* value) { |
| 91 | i::HashMap::Entry* answer = hash_map_.Lookup( |
| 92 | const_cast<char*>(name), |
| 93 | Hash(name), |
| 94 | true); |
| 95 | ASSERT(answer != NULL); |
| 96 | answer->value = value; |
| 97 | } |
| 98 | class Iterator { |
| 99 | public: |
| 100 | explicit Iterator(CounterMap* map) |
| 101 | : map_(&map->hash_map_), entry_(map_->Start()) { } |
| 102 | void Next() { entry_ = map_->Next(entry_); } |
| 103 | bool More() { return entry_ != NULL; } |
| 104 | const char* CurrentKey() { return static_cast<const char*>(entry_->key); } |
| 105 | Counter* CurrentValue() { return static_cast<Counter*>(entry_->value); } |
| 106 | private: |
| 107 | i::HashMap* map_; |
| 108 | i::HashMap::Entry* entry_; |
| 109 | }; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 110 | |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 111 | private: |
| 112 | static int Hash(const char* name); |
| 113 | static bool Match(void* key1, void* key2); |
| 114 | i::HashMap hash_map_; |
| 115 | }; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 116 | #endif // V8_SHARED |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 117 | |
| 118 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 119 | class LineEditor { |
| 120 | public: |
| 121 | enum Type { DUMB = 0, READLINE = 1 }; |
| 122 | LineEditor(Type type, const char* name); |
| 123 | virtual ~LineEditor() { } |
| 124 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 125 | virtual Handle<String> Prompt(const char* prompt) = 0; |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 126 | virtual bool Open(Isolate* isolate) { return true; } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 127 | virtual bool Close() { return true; } |
| 128 | virtual void AddHistory(const char* str) { } |
| 129 | |
| 130 | const char* name() { return name_; } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 131 | static LineEditor* Get() { return current_; } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 132 | private: |
| 133 | Type type_; |
| 134 | const char* name_; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 135 | static LineEditor* current_; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 136 | }; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 137 | |
| 138 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 139 | class SourceGroup { |
| 140 | public: |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 141 | SourceGroup() : |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 142 | #ifndef V8_SHARED |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 143 | next_semaphore_(0), |
| 144 | done_semaphore_(0), |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 145 | thread_(NULL), |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 146 | #endif // V8_SHARED |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 147 | argv_(NULL), |
| 148 | begin_offset_(0), |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 149 | end_offset_(0) {} |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 150 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 151 | ~SourceGroup(); |
| 152 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 153 | void Begin(char** argv, int offset) { |
| 154 | argv_ = const_cast<const char**>(argv); |
| 155 | begin_offset_ = offset; |
| 156 | } |
| 157 | |
| 158 | void End(int offset) { end_offset_ = offset; } |
| 159 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 160 | void Execute(Isolate* isolate); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 161 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 162 | #ifndef V8_SHARED |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 163 | void StartExecuteInThread(); |
| 164 | void WaitForThread(); |
| 165 | |
| 166 | private: |
| 167 | class IsolateThread : public i::Thread { |
| 168 | public: |
| 169 | explicit IsolateThread(SourceGroup* group) |
| 170 | : i::Thread(GetThreadOptions()), group_(group) {} |
| 171 | |
| 172 | virtual void Run() { |
| 173 | group_->ExecuteInThread(); |
| 174 | } |
| 175 | |
| 176 | private: |
| 177 | SourceGroup* group_; |
| 178 | }; |
| 179 | |
| 180 | static i::Thread::Options GetThreadOptions(); |
| 181 | void ExecuteInThread(); |
| 182 | |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 183 | i::Semaphore next_semaphore_; |
| 184 | i::Semaphore done_semaphore_; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 185 | i::Thread* thread_; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 186 | #endif // V8_SHARED |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 187 | |
| 188 | void ExitShell(int exit_code); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 189 | Handle<String> ReadFile(Isolate* isolate, const char* name); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 190 | |
| 191 | const char** argv_; |
| 192 | int begin_offset_; |
| 193 | int end_offset_; |
| 194 | }; |
| 195 | |
| 196 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 197 | class BinaryResource : public v8::String::ExternalAsciiStringResource { |
| 198 | public: |
| 199 | BinaryResource(const char* string, int length) |
| 200 | : data_(string), |
| 201 | length_(length) { } |
| 202 | |
| 203 | ~BinaryResource() { |
| 204 | delete[] data_; |
| 205 | data_ = NULL; |
| 206 | length_ = 0; |
| 207 | } |
| 208 | |
| 209 | virtual const char* data() const { return data_; } |
| 210 | virtual size_t length() const { return length_; } |
| 211 | |
| 212 | private: |
| 213 | const char* data_; |
| 214 | size_t length_; |
| 215 | }; |
| 216 | |
| 217 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 218 | class ShellOptions { |
| 219 | public: |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 220 | ShellOptions() : |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 221 | #ifndef V8_SHARED |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 222 | use_preemption(true), |
| 223 | preemption_interval(10), |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 224 | num_parallel_files(0), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 225 | parallel_files(NULL), |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 226 | #endif // V8_SHARED |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 227 | script_executed(false), |
| 228 | last_run(true), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 229 | send_idle_notification(false), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 230 | stress_opt(false), |
| 231 | stress_deopt(false), |
| 232 | interactive_shell(false), |
| 233 | test_shell(false), |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 234 | dump_heap_constants(false), |
mvstanton@chromium.org | 63ea3d2 | 2013-10-10 09:24:12 +0000 | [diff] [blame] | 235 | expected_to_throw(false), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 236 | num_isolates(1), |
| 237 | isolate_sources(NULL) { } |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 238 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 239 | ~ShellOptions() { |
| 240 | #ifndef V8_SHARED |
| 241 | delete[] parallel_files; |
| 242 | #endif // V8_SHARED |
| 243 | delete[] isolate_sources; |
| 244 | } |
| 245 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 246 | #ifndef V8_SHARED |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 247 | bool use_preemption; |
| 248 | int preemption_interval; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 249 | int num_parallel_files; |
| 250 | char** parallel_files; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 251 | #endif // V8_SHARED |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 252 | bool script_executed; |
| 253 | bool last_run; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 254 | bool send_idle_notification; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 255 | bool stress_opt; |
| 256 | bool stress_deopt; |
| 257 | bool interactive_shell; |
| 258 | bool test_shell; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 259 | bool dump_heap_constants; |
mvstanton@chromium.org | 63ea3d2 | 2013-10-10 09:24:12 +0000 | [diff] [blame] | 260 | bool expected_to_throw; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 261 | int num_isolates; |
| 262 | SourceGroup* isolate_sources; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 265 | #ifdef V8_SHARED |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 266 | class Shell { |
| 267 | #else |
| 268 | class Shell : public i::AllStatic { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 269 | #endif // V8_SHARED |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 270 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 271 | public: |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 272 | static bool ExecuteString(Isolate* isolate, |
| 273 | Handle<String> source, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 274 | Handle<Value> name, |
| 275 | bool print_result, |
| 276 | bool report_exceptions); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 277 | static const char* ToCString(const v8::String::Utf8Value& value); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 278 | static void ReportException(Isolate* isolate, TryCatch* try_catch); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 279 | static Handle<String> ReadFile(Isolate* isolate, const char* name); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 280 | static Local<Context> CreateEvaluationContext(Isolate* isolate); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 281 | static int RunMain(Isolate* isolate, int argc, char* argv[]); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 282 | static int Main(int argc, char* argv[]); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 283 | static void Exit(int exit_code); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 284 | static void OnExit(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 285 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 286 | #ifndef V8_SHARED |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 287 | static Handle<Array> GetCompletions(Isolate* isolate, |
| 288 | Handle<String> text, |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 289 | Handle<String> full); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 290 | static int* LookupCounter(const char* name); |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 291 | static void* CreateHistogram(const char* name, |
| 292 | int min, |
| 293 | int max, |
| 294 | size_t buckets); |
| 295 | static void AddHistogramSample(void* histogram, int sample); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 296 | static void MapCounters(const char* name); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 297 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 298 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 299 | static Handle<Object> DebugMessageDetails(Isolate* isolate, |
| 300 | Handle<String> message); |
| 301 | static Handle<Value> DebugCommandToJSONRequest(Isolate* isolate, |
| 302 | Handle<String> command); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 303 | static void DispatchDebugMessages(); |
| 304 | #endif // ENABLE_DEBUGGER_SUPPORT |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 305 | |
| 306 | static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 307 | #endif // V8_SHARED |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 308 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 309 | static void RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 310 | static void RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 311 | static void RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 312 | static void RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 313 | static void RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 314 | static void RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 315 | static void RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 316 | static void RealmSharedGet(Local<String> property, |
| 317 | const PropertyCallbackInfo<Value>& info); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 318 | static void RealmSharedSet(Local<String> property, |
| 319 | Local<Value> value, |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 320 | const PropertyCallbackInfo<void>& info); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 321 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 322 | static void Print(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 323 | static void Write(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 324 | static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 325 | static void Version(const v8::FunctionCallbackInfo<v8::Value>& args); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 326 | static void Read(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 327 | static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 328 | static Handle<String> ReadFromStdin(Isolate* isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 329 | static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 330 | args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate())); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 331 | } |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 332 | static void Load(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 333 | static void ArrayBuffer(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 334 | static void Int8Array(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 335 | static void Uint8Array(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 336 | static void Int16Array(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 337 | static void Uint16Array(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 338 | static void Int32Array(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 339 | static void Uint32Array(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 340 | static void Float32Array(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 341 | static void Float64Array(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 342 | static void Uint8ClampedArray( |
| 343 | const v8::FunctionCallbackInfo<v8::Value>& args); |
| 344 | static void ArrayBufferSlice(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 345 | static void ArraySubArray(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 346 | static void ArraySet(const v8::FunctionCallbackInfo<v8::Value>& args); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 347 | // The OS object on the global object contains methods for performing |
| 348 | // operating system calls: |
| 349 | // |
| 350 | // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will |
| 351 | // run the command, passing the arguments to the program. The standard output |
| 352 | // of the program will be picked up and returned as a multiline string. If |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 353 | // timeout1 is present then it should be a number. -1 indicates no timeout |
| 354 | // and a positive number is used as a timeout in milliseconds that limits the |
| 355 | // time spent waiting between receiving output characters from the program. |
| 356 | // timeout2, if present, should be a number indicating the limit in |
| 357 | // milliseconds on the total running time of the program. Exceptions are |
| 358 | // thrown on timeouts or other errors or if the exit status of the program |
| 359 | // indicates an error. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 360 | // |
| 361 | // os.chdir(dir) changes directory to the given directory. Throws an |
| 362 | // exception/ on error. |
| 363 | // |
| 364 | // os.setenv(variable, value) sets an environment variable. Repeated calls to |
| 365 | // this method leak memory due to the API of setenv in the standard C library. |
| 366 | // |
| 367 | // os.umask(alue) calls the umask system call and returns the old umask. |
| 368 | // |
| 369 | // os.mkdirp(name, mask) creates a directory. The mask (if present) is anded |
| 370 | // with the current umask. Intermediate directories are created if necessary. |
| 371 | // An exception is not thrown if the directory already exists. Analogous to |
| 372 | // the "mkdir -p" command. |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 373 | static void OSObject(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 374 | static void System(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 375 | static void ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 376 | static void SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 377 | static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 378 | static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 379 | static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 380 | static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 381 | |
| 382 | static void AddOSMethods(Handle<ObjectTemplate> os_template); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 383 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 384 | static const char* kPrompt; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 385 | static ShellOptions options; |
| 386 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 387 | private: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 388 | static Persistent<Context> evaluation_context_; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 389 | #ifndef V8_SHARED |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 390 | static Persistent<Context> utility_context_; |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 391 | static CounterMap* counter_map_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 392 | // We statically allocate a set of local counters to be used if we |
| 393 | // don't want to store the stats in a memory-mapped file |
| 394 | static CounterCollection local_counters_; |
| 395 | static CounterCollection* counters_; |
| 396 | static i::OS::MemoryMappedFile* counters_file_; |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 397 | static i::Mutex context_mutex_; |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 398 | static const i::TimeTicks kInitialTicks; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 399 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 400 | static Counter* GetCounter(const char* name, bool is_histogram); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 401 | static void InstallUtilityScript(Isolate* isolate); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 402 | #endif // V8_SHARED |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 403 | static void Initialize(Isolate* isolate); |
| 404 | static void InitializeDebugger(Isolate* isolate); |
| 405 | static void RunShell(Isolate* isolate); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 406 | static bool SetOptions(int argc, char* argv[]); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 407 | static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 408 | static Handle<FunctionTemplate> CreateArrayBufferTemplate(FunctionCallback); |
| 409 | static Handle<FunctionTemplate> CreateArrayTemplate(FunctionCallback); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 410 | static Handle<Value> CreateExternalArrayBuffer(Isolate* isolate, |
| 411 | Handle<Object> buffer, |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 412 | int32_t size); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 413 | static Handle<Object> CreateExternalArray(Isolate* isolate, |
| 414 | Handle<Object> array, |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 415 | Handle<Object> buffer, |
| 416 | ExternalArrayType type, |
| 417 | int32_t length, |
| 418 | int32_t byteLength, |
| 419 | int32_t byteOffset, |
| 420 | int32_t element_size); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 421 | static void CreateExternalArray( |
| 422 | const v8::FunctionCallbackInfo<v8::Value>& args, |
| 423 | ExternalArrayType type, |
| 424 | int32_t element_size); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 425 | static void ExternalArrayWeakCallback(Isolate* isolate, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 426 | Persistent<Object>* object, |
| 427 | uint8_t* data); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 428 | }; |
| 429 | |
| 430 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 431 | } // namespace v8 |
| 432 | |
| 433 | |
| 434 | #endif // V8_D8_H_ |