blob: 36ec43ec6d8baee160a52a3642d4461403cf35d9 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_D8_H_
6#define V8_D8_H_
7
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008#ifndef V8_SHARED
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/allocation.h"
Ben Murdoch61f157c2016-09-16 13:49:30 +010010#include "src/base/hashmap.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000011#include "src/base/platform/time.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012#include "src/list.h"
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000013#else
Ben Murdochb8a8cc12014-11-26 15:28:44 +000014#include "include/v8.h"
15#include "src/base/compiler-specific.h"
16#endif // !V8_SHARED
Steve Blocka7e24c12009-10-30 11:49:00 +000017
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000018#include "src/base/once.h"
19
20
Steve Blocka7e24c12009-10-30 11:49:00 +000021namespace v8 {
22
Steve Blocka7e24c12009-10-30 11:49:00 +000023
Ben Murdoch69a99ed2011-11-30 16:03:39 +000024#ifndef V8_SHARED
Steve Blocka7e24c12009-10-30 11:49:00 +000025// A single counter in a counter collection.
26class Counter {
27 public:
28 static const int kMaxNameSize = 64;
29 int32_t* Bind(const char* name, bool histogram);
30 int32_t* ptr() { return &count_; }
31 int32_t count() { return count_; }
32 int32_t sample_total() { return sample_total_; }
33 bool is_histogram() { return is_histogram_; }
34 void AddSample(int32_t sample);
35 private:
36 int32_t count_;
37 int32_t sample_total_;
38 bool is_histogram_;
39 uint8_t name_[kMaxNameSize];
40};
41
42
43// A set of counters and associated information. An instance of this
44// class is stored directly in the memory-mapped counters file if
45// the --map-counters options is used
46class CounterCollection {
47 public:
48 CounterCollection();
49 Counter* GetNextCounter();
50 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051 static const unsigned kMaxCounters = 512;
Steve Blocka7e24c12009-10-30 11:49:00 +000052 uint32_t magic_number_;
53 uint32_t max_counters_;
54 uint32_t max_name_size_;
55 uint32_t counters_in_use_;
56 Counter counters_[kMaxCounters];
57};
58
59
60class CounterMap {
61 public:
62 CounterMap(): hash_map_(Match) { }
63 Counter* Lookup(const char* name) {
Ben Murdoch61f157c2016-09-16 13:49:30 +010064 base::HashMap::Entry* answer =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000065 hash_map_.Lookup(const_cast<char*>(name), Hash(name));
Steve Blocka7e24c12009-10-30 11:49:00 +000066 if (!answer) return NULL;
67 return reinterpret_cast<Counter*>(answer->value);
68 }
69 void Set(const char* name, Counter* value) {
Ben Murdoch61f157c2016-09-16 13:49:30 +010070 base::HashMap::Entry* answer =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071 hash_map_.LookupOrInsert(const_cast<char*>(name), Hash(name));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072 DCHECK(answer != NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +000073 answer->value = value;
74 }
75 class Iterator {
76 public:
77 explicit Iterator(CounterMap* map)
78 : map_(&map->hash_map_), entry_(map_->Start()) { }
79 void Next() { entry_ = map_->Next(entry_); }
80 bool More() { return entry_ != NULL; }
81 const char* CurrentKey() { return static_cast<const char*>(entry_->key); }
82 Counter* CurrentValue() { return static_cast<Counter*>(entry_->value); }
83 private:
Ben Murdoch61f157c2016-09-16 13:49:30 +010084 base::HashMap* map_;
85 base::HashMap::Entry* entry_;
Steve Blocka7e24c12009-10-30 11:49:00 +000086 };
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000087
Steve Blocka7e24c12009-10-30 11:49:00 +000088 private:
89 static int Hash(const char* name);
90 static bool Match(void* key1, void* key2);
Ben Murdoch61f157c2016-09-16 13:49:30 +010091 base::HashMap hash_map_;
Steve Blocka7e24c12009-10-30 11:49:00 +000092};
Ben Murdochb8a8cc12014-11-26 15:28:44 +000093#endif // !V8_SHARED
Steve Blocka7e24c12009-10-30 11:49:00 +000094
95
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000096class SourceGroup {
97 public:
98 SourceGroup() :
Ben Murdoch69a99ed2011-11-30 16:03:39 +000099#ifndef V8_SHARED
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000100 next_semaphore_(0),
101 done_semaphore_(0),
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000102 thread_(NULL),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000103#endif // !V8_SHARED
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000104 argv_(NULL),
105 begin_offset_(0),
Ben Murdoch589d6972011-11-30 16:04:58 +0000106 end_offset_(0) {}
107
108 ~SourceGroup();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000109
110 void Begin(char** argv, int offset) {
111 argv_ = const_cast<const char**>(argv);
112 begin_offset_ = offset;
113 }
114
115 void End(int offset) { end_offset_ = offset; }
116
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000117 void Execute(Isolate* isolate);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000118
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000119#ifndef V8_SHARED
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000120 void StartExecuteInThread();
121 void WaitForThread();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000122 void JoinThread();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000123
124 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000125 class IsolateThread : public base::Thread {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000126 public:
127 explicit IsolateThread(SourceGroup* group)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128 : base::Thread(GetThreadOptions()), group_(group) {}
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000129
130 virtual void Run() {
131 group_->ExecuteInThread();
132 }
133
134 private:
135 SourceGroup* group_;
136 };
137
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000138 static base::Thread::Options GetThreadOptions();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000139 void ExecuteInThread();
140
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000141 base::Semaphore next_semaphore_;
142 base::Semaphore done_semaphore_;
143 base::Thread* thread_;
144#endif // !V8_SHARED
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000145
146 void ExitShell(int exit_code);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000147 Local<String> ReadFile(Isolate* isolate, const char* name);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000148
149 const char** argv_;
150 int begin_offset_;
151 int end_offset_;
152};
153
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000154#ifndef V8_SHARED
155enum SerializationTag {
156 kSerializationTagUndefined,
157 kSerializationTagNull,
158 kSerializationTagTrue,
159 kSerializationTagFalse,
160 kSerializationTagNumber,
161 kSerializationTagString,
162 kSerializationTagArray,
163 kSerializationTagObject,
164 kSerializationTagArrayBuffer,
165 kSerializationTagTransferredArrayBuffer,
166 kSerializationTagTransferredSharedArrayBuffer,
167};
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000168
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000169
170class SerializationData {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100171 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000172 SerializationData() {}
173 ~SerializationData();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100174
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000175 void WriteTag(SerializationTag tag);
176 void WriteMemory(const void* p, int length);
177 void WriteArrayBufferContents(const ArrayBuffer::Contents& contents);
178 void WriteSharedArrayBufferContents(
179 const SharedArrayBuffer::Contents& contents);
180
181 template <typename T>
182 void Write(const T& data) {
183 WriteMemory(&data, sizeof(data));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100184 }
185
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000186 SerializationTag ReadTag(int* offset) const;
187 void ReadMemory(void* p, int length, int* offset) const;
188 void ReadArrayBufferContents(ArrayBuffer::Contents* contents,
189 int* offset) const;
190 void ReadSharedArrayBufferContents(SharedArrayBuffer::Contents* contents,
191 int* offset) const;
192
193 template <typename T>
194 T Read(int* offset) const {
195 T value;
196 ReadMemory(&value, sizeof(value), offset);
197 return value;
198 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100199
200 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000201 i::List<uint8_t> data_;
202 i::List<ArrayBuffer::Contents> array_buffer_contents_;
203 i::List<SharedArrayBuffer::Contents> shared_array_buffer_contents_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100204};
205
206
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000207class SerializationDataQueue {
208 public:
209 void Enqueue(SerializationData* data);
210 bool Dequeue(SerializationData** data);
211 bool IsEmpty();
212 void Clear();
213
214 private:
215 base::Mutex mutex_;
216 i::List<SerializationData*> data_;
217};
218
219
220class Worker {
221 public:
222 Worker();
223 ~Worker();
224
225 // Run the given script on this Worker. This function should only be called
226 // once, and should only be called by the thread that created the Worker.
227 void StartExecuteInThread(const char* script);
228 // Post a message to the worker's incoming message queue. The worker will
229 // take ownership of the SerializationData.
230 // This function should only be called by the thread that created the Worker.
231 void PostMessage(SerializationData* data);
232 // Synchronously retrieve messages from the worker's outgoing message queue.
233 // If there is no message in the queue, block until a message is available.
234 // If there are no messages in the queue and the worker is no longer running,
235 // return nullptr.
236 // This function should only be called by the thread that created the Worker.
237 SerializationData* GetMessage();
238 // Terminate the worker's event loop. Messages from the worker that have been
239 // queued can still be read via GetMessage().
240 // This function can be called by any thread.
241 void Terminate();
242 // Terminate and join the thread.
243 // This function can be called by any thread.
244 void WaitForThread();
245
246 private:
247 class WorkerThread : public base::Thread {
248 public:
249 explicit WorkerThread(Worker* worker)
250 : base::Thread(base::Thread::Options("WorkerThread")),
251 worker_(worker) {}
252
253 virtual void Run() { worker_->ExecuteInThread(); }
254
255 private:
256 Worker* worker_;
257 };
258
259 void ExecuteInThread();
260 static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args);
261
262 base::Semaphore in_semaphore_;
263 base::Semaphore out_semaphore_;
264 SerializationDataQueue in_queue_;
265 SerializationDataQueue out_queue_;
266 base::Thread* thread_;
267 char* script_;
268 base::Atomic32 running_;
269};
270#endif // !V8_SHARED
271
272
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000273class ShellOptions {
274 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000275 ShellOptions()
276 : script_executed(false),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000277 send_idle_notification(false),
278 invoke_weak_callbacks(false),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000279 omit_quit(false),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000280 stress_opt(false),
281 stress_deopt(false),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000282 stress_runs(1),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000283 interactive_shell(false),
284 test_shell(false),
285 dump_heap_constants(false),
286 expected_to_throw(false),
287 mock_arraybuffer_allocator(false),
288 num_isolates(1),
289 compile_options(v8::ScriptCompiler::kNoCompileOptions),
290 isolate_sources(NULL),
291 icu_data_file(NULL),
292 natives_blob(NULL),
293 snapshot_blob(NULL) {}
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000294
Ben Murdoch589d6972011-11-30 16:04:58 +0000295 ~ShellOptions() {
Ben Murdoch589d6972011-11-30 16:04:58 +0000296 delete[] isolate_sources;
297 }
298
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000299 bool use_interactive_shell() {
300 return (interactive_shell || !script_executed) && !test_shell;
301 }
302
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000303 bool script_executed;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000304 bool send_idle_notification;
305 bool invoke_weak_callbacks;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000306 bool omit_quit;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000307 bool stress_opt;
308 bool stress_deopt;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000309 int stress_runs;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000310 bool interactive_shell;
311 bool test_shell;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000312 bool dump_heap_constants;
313 bool expected_to_throw;
314 bool mock_arraybuffer_allocator;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000315 int num_isolates;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000316 v8::ScriptCompiler::CompileOptions compile_options;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000317 SourceGroup* isolate_sources;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000318 const char* icu_data_file;
319 const char* natives_blob;
320 const char* snapshot_blob;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000321};
322
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000323#ifdef V8_SHARED
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000324class Shell {
325#else
326class Shell : public i::AllStatic {
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000327#endif // V8_SHARED
Ben Murdoch589d6972011-11-30 16:04:58 +0000328
Steve Blocka7e24c12009-10-30 11:49:00 +0000329 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000330 enum SourceType { SCRIPT, MODULE };
331
332 static MaybeLocal<Script> CompileString(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000333 Isolate* isolate, Local<String> source, Local<Value> name,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000334 v8::ScriptCompiler::CompileOptions compile_options,
335 SourceType source_type);
336 static bool ExecuteString(Isolate* isolate, Local<String> source,
337 Local<Value> name, bool print_result,
338 bool report_exceptions,
339 SourceType source_type = SCRIPT);
Steve Block6ded16b2010-05-10 14:33:55 +0100340 static const char* ToCString(const v8::String::Utf8Value& value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000341 static void ReportException(Isolate* isolate, TryCatch* try_catch);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000342 static Local<String> ReadFile(Isolate* isolate, const char* name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000343 static Local<Context> CreateEvaluationContext(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000344 static int RunMain(Isolate* isolate, int argc, char* argv[], bool last_run);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000345 static int Main(int argc, char* argv[]);
Ben Murdoch589d6972011-11-30 16:04:58 +0000346 static void Exit(int exit_code);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400347 static void OnExit(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000348 static void CollectGarbage(Isolate* isolate);
349 static void EmptyMessageQueues(Isolate* isolate);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000350
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000351#ifndef V8_SHARED
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000352 // TODO(binji): stupid implementation for now. Is there an easy way to hash an
Ben Murdoch61f157c2016-09-16 13:49:30 +0100353 // object for use in base::HashMap? By pointer?
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000354 typedef i::List<Local<Object>> ObjectList;
355 static bool SerializeValue(Isolate* isolate, Local<Value> value,
356 const ObjectList& to_transfer,
357 ObjectList* seen_objects,
358 SerializationData* out_data);
359 static MaybeLocal<Value> DeserializeValue(Isolate* isolate,
360 const SerializationData& data,
361 int* offset);
362 static void CleanupWorkers();
Steve Blocka7e24c12009-10-30 11:49:00 +0000363 static int* LookupCounter(const char* name);
364 static void* CreateHistogram(const char* name,
365 int min,
366 int max,
367 size_t buckets);
368 static void AddHistogramSample(void* histogram, int sample);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000369 static void MapCounters(v8::Isolate* isolate, const char* name);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000370
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000371 static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args);
372#endif // !V8_SHARED
Ben Murdochb0fe1622011-05-05 13:52:32 +0100373
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000374 static void RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args);
375 static void RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args);
376 static void RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args);
377 static void RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100378 static void RealmCreateAllowCrossRealmAccess(
379 const v8::FunctionCallbackInfo<v8::Value>& args);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000380 static void RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args);
381 static void RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args);
382 static void RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args);
383 static void RealmSharedGet(Local<String> property,
384 const PropertyCallbackInfo<Value>& info);
385 static void RealmSharedSet(Local<String> property,
386 Local<Value> value,
387 const PropertyCallbackInfo<void>& info);
388
389 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
390 static void Write(const v8::FunctionCallbackInfo<v8::Value>& args);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000391 static void QuitOnce(v8::FunctionCallbackInfo<v8::Value>* args);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000392 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
393 static void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
394 static void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
395 static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000396 static Local<String> ReadFromStdin(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000397 static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
398 args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100399 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000400 static void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000401 static void WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args);
402 static void WorkerPostMessage(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000403 const v8::FunctionCallbackInfo<v8::Value>& args);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000404 static void WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args);
405 static void WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000406 // The OS object on the global object contains methods for performing
407 // operating system calls:
408 //
409 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will
410 // run the command, passing the arguments to the program. The standard output
411 // of the program will be picked up and returned as a multiline string. If
412 // timeout1 is present then it should be a number. -1 indicates no timeout
413 // and a positive number is used as a timeout in milliseconds that limits the
414 // time spent waiting between receiving output characters from the program.
415 // timeout2, if present, should be a number indicating the limit in
416 // milliseconds on the total running time of the program. Exceptions are
417 // thrown on timeouts or other errors or if the exit status of the program
418 // indicates an error.
419 //
420 // os.chdir(dir) changes directory to the given directory. Throws an
421 // exception/ on error.
422 //
423 // os.setenv(variable, value) sets an environment variable. Repeated calls to
424 // this method leak memory due to the API of setenv in the standard C library.
425 //
426 // os.umask(alue) calls the umask system call and returns the old umask.
427 //
428 // os.mkdirp(name, mask) creates a directory. The mask (if present) is anded
429 // with the current umask. Intermediate directories are created if necessary.
430 // An exception is not thrown if the directory already exists. Analogous to
431 // the "mkdir -p" command.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000432 static void System(const v8::FunctionCallbackInfo<v8::Value>& args);
433 static void ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
434 static void SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args);
435 static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args);
436 static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args);
437 static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
438 static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000439
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000440 static void AddOSMethods(v8::Isolate* isolate,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000441 Local<ObjectTemplate> os_template);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100442
Steve Blocka7e24c12009-10-30 11:49:00 +0000443 static const char* kPrompt;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000444 static ShellOptions options;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000445 static ArrayBuffer::Allocator* array_buffer_allocator;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000446
Steve Blocka7e24c12009-10-30 11:49:00 +0000447 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000448 static Global<Context> evaluation_context_;
449 static base::OnceType quit_once_;
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000450#ifndef V8_SHARED
Ben Murdochda12d292016-06-02 14:46:10 +0100451 static Global<Function> stringify_function_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000452 static CounterMap* counter_map_;
453 // We statically allocate a set of local counters to be used if we
454 // don't want to store the stats in a memory-mapped file
455 static CounterCollection local_counters_;
456 static CounterCollection* counters_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000457 static base::OS::MemoryMappedFile* counters_file_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000458 static base::LazyMutex context_mutex_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000459 static const base::TimeTicks kInitialTicks;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000460
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000461 static base::LazyMutex workers_mutex_;
462 static bool allow_new_workers_;
463 static i::List<Worker*> workers_;
464 static i::List<SharedArrayBuffer::Contents> externalized_shared_contents_;
465
Ben Murdochc5610432016-08-08 18:44:38 +0100466 static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000467 static Counter* GetCounter(const char* name, bool is_histogram);
Ben Murdochda12d292016-06-02 14:46:10 +0100468 static Local<String> Stringify(Isolate* isolate, Local<Value> value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000469#endif // !V8_SHARED
470 static void Initialize(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000471 static void RunShell(Isolate* isolate);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000472 static bool SetOptions(int argc, char* argv[]);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000473 static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100474 static MaybeLocal<Context> CreateRealm(
475 const v8::FunctionCallbackInfo<v8::Value>& args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000476};
477
478
Steve Blocka7e24c12009-10-30 11:49:00 +0000479} // namespace v8
480
481
482#endif // V8_D8_H_