OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
8 #define V8_SHARED | 8 #define V8_SHARED |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "src/d8-debug.h" | 48 #include "src/d8-debug.h" |
49 #include "src/debug.h" | 49 #include "src/debug.h" |
50 #include "src/natives.h" | 50 #include "src/natives.h" |
51 #include "src/v8.h" | 51 #include "src/v8.h" |
52 #endif // !V8_SHARED | 52 #endif // !V8_SHARED |
53 | 53 |
54 #if !defined(_WIN32) && !defined(_WIN64) | 54 #if !defined(_WIN32) && !defined(_WIN64) |
55 #include <unistd.h> // NOLINT | 55 #include <unistd.h> // NOLINT |
56 #endif | 56 #endif |
57 | 57 |
58 #ifndef ASSERT | 58 #ifndef DCHECK |
59 #define ASSERT(condition) assert(condition) | 59 #define DCHECK(condition) assert(condition) |
60 #endif | 60 #endif |
61 | 61 |
62 namespace v8 { | 62 namespace v8 { |
63 | 63 |
64 | 64 |
65 static Handle<Value> Throw(Isolate* isolate, const char* message) { | 65 static Handle<Value> Throw(Isolate* isolate, const char* message) { |
66 return isolate->ThrowException(String::NewFromUtf8(isolate, message)); | 66 return isolate->ThrowException(String::NewFromUtf8(isolate, message)); |
67 } | 67 } |
68 | 68 |
69 | 69 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 Local<UnboundScript> script = | 179 Local<UnboundScript> script = |
180 ScriptCompiler::CompileUnbound(isolate, &script_source, compile_options); | 180 ScriptCompiler::CompileUnbound(isolate, &script_source, compile_options); |
181 | 181 |
182 // Was caching requested & successful? Then compile again, now with cache. | 182 // Was caching requested & successful? Then compile again, now with cache. |
183 if (script_source.GetCachedData()) { | 183 if (script_source.GetCachedData()) { |
184 if (compile_options == ScriptCompiler::kProduceCodeCache) { | 184 if (compile_options == ScriptCompiler::kProduceCodeCache) { |
185 compile_options = ScriptCompiler::kConsumeCodeCache; | 185 compile_options = ScriptCompiler::kConsumeCodeCache; |
186 } else if (compile_options == ScriptCompiler::kProduceParserCache) { | 186 } else if (compile_options == ScriptCompiler::kProduceParserCache) { |
187 compile_options = ScriptCompiler::kConsumeParserCache; | 187 compile_options = ScriptCompiler::kConsumeParserCache; |
188 } else { | 188 } else { |
189 ASSERT(false); // A new compile option? | 189 DCHECK(false); // A new compile option? |
190 } | 190 } |
191 ScriptCompiler::Source cached_source( | 191 ScriptCompiler::Source cached_source( |
192 source, origin, new v8::ScriptCompiler::CachedData( | 192 source, origin, new v8::ScriptCompiler::CachedData( |
193 script_source.GetCachedData()->data, | 193 script_source.GetCachedData()->data, |
194 script_source.GetCachedData()->length, | 194 script_source.GetCachedData()->length, |
195 v8::ScriptCompiler::CachedData::BufferNotOwned)); | 195 v8::ScriptCompiler::CachedData::BufferNotOwned)); |
196 script = ScriptCompiler::CompileUnbound(isolate, &cached_source, | 196 script = ScriptCompiler::CompileUnbound(isolate, &cached_source, |
197 compile_options); | 197 compile_options); |
198 } | 198 } |
199 return script; | 199 return script; |
(...skipping 28 matching lines...) Expand all Loading... |
228 return false; | 228 return false; |
229 } else { | 229 } else { |
230 PerIsolateData* data = PerIsolateData::Get(isolate); | 230 PerIsolateData* data = PerIsolateData::Get(isolate); |
231 Local<Context> realm = | 231 Local<Context> realm = |
232 Local<Context>::New(isolate, data->realms_[data->realm_current_]); | 232 Local<Context>::New(isolate, data->realms_[data->realm_current_]); |
233 realm->Enter(); | 233 realm->Enter(); |
234 Handle<Value> result = script->BindToCurrentContext()->Run(); | 234 Handle<Value> result = script->BindToCurrentContext()->Run(); |
235 realm->Exit(); | 235 realm->Exit(); |
236 data->realm_current_ = data->realm_switch_; | 236 data->realm_current_ = data->realm_switch_; |
237 if (result.IsEmpty()) { | 237 if (result.IsEmpty()) { |
238 ASSERT(try_catch.HasCaught()); | 238 DCHECK(try_catch.HasCaught()); |
239 // Print errors that happened during execution. | 239 // Print errors that happened during execution. |
240 if (report_exceptions && !FLAG_debugger) | 240 if (report_exceptions && !FLAG_debugger) |
241 ReportException(isolate, &try_catch); | 241 ReportException(isolate, &try_catch); |
242 return false; | 242 return false; |
243 } else { | 243 } else { |
244 ASSERT(!try_catch.HasCaught()); | 244 DCHECK(!try_catch.HasCaught()); |
245 if (print_result) { | 245 if (print_result) { |
246 #if !defined(V8_SHARED) | 246 #if !defined(V8_SHARED) |
247 if (options.test_shell) { | 247 if (options.test_shell) { |
248 #endif | 248 #endif |
249 if (!result->IsUndefined()) { | 249 if (!result->IsUndefined()) { |
250 // If all went well and the result wasn't undefined then print | 250 // If all went well and the result wasn't undefined then print |
251 // the returned value. | 251 // the returned value. |
252 v8::String::Utf8Value str(result); | 252 v8::String::Utf8Value str(result); |
253 fwrite(*str, sizeof(**str), str.length(), stdout); | 253 fwrite(*str, sizeof(**str), str.length(), stdout); |
254 printf("\n"); | 254 printf("\n"); |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 Counter* Shell::GetCounter(const char* name, bool is_histogram) { | 740 Counter* Shell::GetCounter(const char* name, bool is_histogram) { |
741 Counter* counter = counter_map_->Lookup(name); | 741 Counter* counter = counter_map_->Lookup(name); |
742 | 742 |
743 if (counter == NULL) { | 743 if (counter == NULL) { |
744 counter = counters_->GetNextCounter(); | 744 counter = counters_->GetNextCounter(); |
745 if (counter != NULL) { | 745 if (counter != NULL) { |
746 counter_map_->Set(name, counter); | 746 counter_map_->Set(name, counter); |
747 counter->Bind(name, is_histogram); | 747 counter->Bind(name, is_histogram); |
748 } | 748 } |
749 } else { | 749 } else { |
750 ASSERT(counter->is_histogram() == is_histogram); | 750 DCHECK(counter->is_histogram() == is_histogram); |
751 } | 751 } |
752 return counter; | 752 return counter; |
753 } | 753 } |
754 | 754 |
755 | 755 |
756 int* Shell::LookupCounter(const char* name) { | 756 int* Shell::LookupCounter(const char* name) { |
757 Counter* counter = GetCounter(name, false); | 757 Counter* counter = GetCounter(name, false); |
758 | 758 |
759 if (counter != NULL) { | 759 if (counter != NULL) { |
760 return counter->ptr(); | 760 return counter->ptr(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 836 #ifdef COMPRESS_STARTUP_DATA_BZ2 |
837 class BZip2Decompressor : public v8::StartupDataDecompressor { | 837 class BZip2Decompressor : public v8::StartupDataDecompressor { |
838 public: | 838 public: |
839 virtual ~BZip2Decompressor() { } | 839 virtual ~BZip2Decompressor() { } |
840 | 840 |
841 protected: | 841 protected: |
842 virtual int DecompressData(char* raw_data, | 842 virtual int DecompressData(char* raw_data, |
843 int* raw_data_size, | 843 int* raw_data_size, |
844 const char* compressed_data, | 844 const char* compressed_data, |
845 int compressed_data_size) { | 845 int compressed_data_size) { |
846 ASSERT_EQ(v8::StartupData::kBZip2, | 846 DCHECK_EQ(v8::StartupData::kBZip2, |
847 v8::V8::GetCompressedStartupDataAlgorithm()); | 847 v8::V8::GetCompressedStartupDataAlgorithm()); |
848 unsigned int decompressed_size = *raw_data_size; | 848 unsigned int decompressed_size = *raw_data_size; |
849 int result = | 849 int result = |
850 BZ2_bzBuffToBuffDecompress(raw_data, | 850 BZ2_bzBuffToBuffDecompress(raw_data, |
851 &decompressed_size, | 851 &decompressed_size, |
852 const_cast<char*>(compressed_data), | 852 const_cast<char*>(compressed_data), |
853 compressed_data_size, | 853 compressed_data_size, |
854 0, 1); | 854 0, 1); |
855 if (result == BZ_OK) { | 855 if (result == BZ_OK) { |
856 *raw_data_size = decompressed_size; | 856 *raw_data_size = decompressed_size; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 | 953 |
954 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { | 954 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { |
955 #ifndef V8_SHARED | 955 #ifndef V8_SHARED |
956 // This needs to be a critical section since this is not thread-safe | 956 // This needs to be a critical section since this is not thread-safe |
957 base::LockGuard<base::Mutex> lock_guard(&context_mutex_); | 957 base::LockGuard<base::Mutex> lock_guard(&context_mutex_); |
958 #endif // !V8_SHARED | 958 #endif // !V8_SHARED |
959 // Initialize the global objects | 959 // Initialize the global objects |
960 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 960 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
961 EscapableHandleScope handle_scope(isolate); | 961 EscapableHandleScope handle_scope(isolate); |
962 Local<Context> context = Context::New(isolate, NULL, global_template); | 962 Local<Context> context = Context::New(isolate, NULL, global_template); |
963 ASSERT(!context.IsEmpty()); | 963 DCHECK(!context.IsEmpty()); |
964 Context::Scope scope(context); | 964 Context::Scope scope(context); |
965 | 965 |
966 #ifndef V8_SHARED | 966 #ifndef V8_SHARED |
967 i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory(); | 967 i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory(); |
968 i::JSArguments js_args = i::FLAG_js_arguments; | 968 i::JSArguments js_args = i::FLAG_js_arguments; |
969 i::Handle<i::FixedArray> arguments_array = | 969 i::Handle<i::FixedArray> arguments_array = |
970 factory->NewFixedArray(js_args.argc); | 970 factory->NewFixedArray(js_args.argc); |
971 for (int j = 0; j < js_args.argc; j++) { | 971 for (int j = 0; j < js_args.argc; j++) { |
972 i::Handle<i::String> arg = | 972 i::Handle<i::String> arg = |
973 factory->NewStringFromUtf8(i::CStrVector(js_args[j])).ToHandleChecked(); | 973 factory->NewStringFromUtf8(i::CStrVector(js_args[j])).ToHandleChecked(); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 data.GetIsolate()->AdjustAmountOfExternalAllocatedMemory( | 1100 data.GetIsolate()->AdjustAmountOfExternalAllocatedMemory( |
1101 -static_cast<intptr_t>(byte_length)); | 1101 -static_cast<intptr_t>(byte_length)); |
1102 | 1102 |
1103 delete[] data.GetParameter()->data; | 1103 delete[] data.GetParameter()->data; |
1104 data.GetParameter()->handle.Reset(); | 1104 data.GetParameter()->handle.Reset(); |
1105 delete data.GetParameter(); | 1105 delete data.GetParameter(); |
1106 } | 1106 } |
1107 | 1107 |
1108 | 1108 |
1109 void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) { | 1109 void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) { |
1110 ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT | 1110 DCHECK(sizeof(char) == sizeof(uint8_t)); // NOLINT |
1111 String::Utf8Value filename(args[0]); | 1111 String::Utf8Value filename(args[0]); |
1112 int length; | 1112 int length; |
1113 if (*filename == NULL) { | 1113 if (*filename == NULL) { |
1114 Throw(args.GetIsolate(), "Error loading file"); | 1114 Throw(args.GetIsolate(), "Error loading file"); |
1115 return; | 1115 return; |
1116 } | 1116 } |
1117 | 1117 |
1118 Isolate* isolate = args.GetIsolate(); | 1118 Isolate* isolate = args.GetIsolate(); |
1119 DataAndPersistent* data = new DataAndPersistent; | 1119 DataAndPersistent* data = new DataAndPersistent; |
1120 data->data = reinterpret_cast<uint8_t*>( | 1120 data->data = reinterpret_cast<uint8_t*>( |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1691 } | 1691 } |
1692 | 1692 |
1693 } // namespace v8 | 1693 } // namespace v8 |
1694 | 1694 |
1695 | 1695 |
1696 #ifndef GOOGLE3 | 1696 #ifndef GOOGLE3 |
1697 int main(int argc, char* argv[]) { | 1697 int main(int argc, char* argv[]) { |
1698 return v8::Shell::Main(argc, argv); | 1698 return v8::Shell::Main(argc, argv); |
1699 } | 1699 } |
1700 #endif | 1700 #endif |
OLD | NEW |