Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | |
| 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 | |
| 31 | |
| 32 // Disable exceptions on windows to not generate warnings from <map>. | |
| 33 #define _HAS_EXCEPTIONS 0 | |
| 34 #include <map> | |
| 35 | |
| 36 #include "v8.h" | |
| 37 | |
| 38 | |
| 39 namespace v8 { | |
| 40 | |
| 41 | |
| 42 namespace i = v8::internal; | |
| 43 | |
| 44 | |
| 45 class Counter { | |
| 46 public: | |
| 47 explicit Counter(const wchar_t* name) | |
| 48 : name_(name), value_(0) { } | |
| 49 int* GetValuePtr() { return &value_; } | |
| 50 const wchar_t* name() { return name_; } | |
| 51 int value() { return value_; } | |
| 52 private: | |
| 53 const wchar_t* name_; | |
| 54 int value_; | |
| 55 }; | |
| 56 | |
| 57 | |
| 58 class Shell: public i::AllStatic { | |
| 59 public: | |
| 60 static bool ExecuteString(Handle<String> source, | |
| 61 Handle<Value> name, | |
| 62 bool print_result, | |
| 63 bool report_exceptions); | |
| 64 static void ReportException(TryCatch* try_catch); | |
| 65 static void Initialize(); | |
| 66 static void OnExit(); | |
| 67 static int* LookupCounter(const wchar_t* name); | |
| 68 static Handle<String> ReadFile(const char* name); | |
| 69 static void RunShell(); | |
| 70 static int Main(int argc, char* argv[]); | |
| 71 static Handle<Array> GetCompletions(Handle<String> text, | |
| 72 Handle<String> full); | |
| 73 | |
| 74 static Handle<Value> Print(const Arguments& args); | |
| 75 static Handle<Value> Quit(const Arguments& args); | |
| 76 static Handle<Value> Version(const Arguments& args); | |
| 77 static Handle<Value> Load(const Arguments& args); | |
| 78 | |
| 79 static const char* kHistoryFileName; | |
| 80 static const char* kPrompt; | |
| 81 private: | |
| 82 static Persistent<Context> utility_context_; | |
| 83 static Persistent<Context> evaluation_context_; | |
| 84 typedef std::map<const wchar_t*, Counter*> CounterMap; | |
| 85 static CounterMap counter_map_; | |
| 86 }; | |
| 87 | |
| 88 | |
| 89 class LineEditor { | |
| 90 public: | |
| 91 enum Type { DUMB = 0, READLINE = 1 }; | |
| 92 LineEditor(Type type, const char* name); | |
| 93 virtual ~LineEditor() { } | |
| 94 | |
| 95 virtual i::SmartPointer<char> Prompt(const char* prompt) = 0; | |
| 96 virtual bool Open() { return true; } | |
| 97 virtual bool Close() { return true; } | |
| 98 virtual void AddHistory(const char* str) { } | |
| 99 | |
| 100 const char* name() { return name_; } | |
| 101 static LineEditor* Get(); | |
| 102 private: | |
| 103 Type type_; | |
| 104 const char* name_; | |
| 105 LineEditor* next_; | |
| 106 static LineEditor* first_; | |
| 107 }; | |
| 108 } // v8 | |
|
Kasper Lund
2008/10/21 08:26:56
Maybe add some more whitespace here. There's plent
| |
| 109 | |
| 110 #endif // V8_D8_H_ | |
| OLD | NEW |