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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // Executes a string within the current v8 context. | 300 // Executes a string within the current v8 context. |
301 bool Shell::ExecuteString(Isolate* isolate, Handle<String> source, | 301 bool Shell::ExecuteString(Isolate* isolate, Handle<String> source, |
302 Handle<Value> name, bool print_result, | 302 Handle<Value> name, bool print_result, |
303 bool report_exceptions, SourceType source_type) { | 303 bool report_exceptions, SourceType source_type) { |
304 #ifndef V8_SHARED | 304 #ifndef V8_SHARED |
305 bool FLAG_debugger = i::FLAG_debugger; | 305 bool FLAG_debugger = i::FLAG_debugger; |
306 #else | 306 #else |
307 bool FLAG_debugger = false; | 307 bool FLAG_debugger = false; |
308 #endif // !V8_SHARED | 308 #endif // !V8_SHARED |
309 HandleScope handle_scope(isolate); | 309 HandleScope handle_scope(isolate); |
310 TryCatch try_catch; | 310 TryCatch try_catch(isolate); |
311 options.script_executed = true; | 311 options.script_executed = true; |
312 if (FLAG_debugger) { | 312 if (FLAG_debugger) { |
313 // When debugging make exceptions appear to be uncaught. | 313 // When debugging make exceptions appear to be uncaught. |
314 try_catch.SetVerbose(true); | 314 try_catch.SetVerbose(true); |
315 } | 315 } |
316 | 316 |
317 Handle<Value> result; | 317 Handle<Value> result; |
318 { | 318 { |
319 PerIsolateData* data = PerIsolateData::Get(isolate); | 319 PerIsolateData* data = PerIsolateData::Get(isolate); |
320 Local<Context> realm = | 320 Local<Context> realm = |
(...skipping 24 matching lines...) Expand all Loading... |
345 #endif | 345 #endif |
346 if (!result->IsUndefined()) { | 346 if (!result->IsUndefined()) { |
347 // If all went well and the result wasn't undefined then print | 347 // If all went well and the result wasn't undefined then print |
348 // the returned value. | 348 // the returned value. |
349 v8::String::Utf8Value str(result); | 349 v8::String::Utf8Value str(result); |
350 fwrite(*str, sizeof(**str), str.length(), stdout); | 350 fwrite(*str, sizeof(**str), str.length(), stdout); |
351 printf("\n"); | 351 printf("\n"); |
352 } | 352 } |
353 #if !defined(V8_SHARED) | 353 #if !defined(V8_SHARED) |
354 } else { | 354 } else { |
355 v8::TryCatch try_catch; | 355 v8::TryCatch try_catch(isolate); |
356 v8::Local<v8::Context> context = | 356 v8::Local<v8::Context> context = |
357 v8::Local<v8::Context>::New(isolate, utility_context_); | 357 v8::Local<v8::Context>::New(isolate, utility_context_); |
358 v8::Context::Scope context_scope(context); | 358 v8::Context::Scope context_scope(context); |
359 Handle<Object> global = context->Global(); | 359 Handle<Object> global = context->Global(); |
360 Handle<Value> fun = | 360 Handle<Value> fun = |
361 global->Get(String::NewFromUtf8(isolate, "Stringify")); | 361 global->Get(String::NewFromUtf8(isolate, "Stringify")); |
362 Handle<Value> argv[1] = {result}; | 362 Handle<Value> argv[1] = {result}; |
363 Handle<Value> s = Handle<Function>::Cast(fun)->Call(global, 1, argv); | 363 Handle<Value> s = Handle<Function>::Cast(fun)->Call(global, 1, argv); |
364 if (try_catch.HasCaught()) return true; | 364 if (try_catch.HasCaught()) return true; |
365 v8::String::Utf8Value str(s); | 365 v8::String::Utf8Value str(s); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 | 564 |
565 | 565 |
566 void Shell::Write(const v8::FunctionCallbackInfo<v8::Value>& args) { | 566 void Shell::Write(const v8::FunctionCallbackInfo<v8::Value>& args) { |
567 for (int i = 0; i < args.Length(); i++) { | 567 for (int i = 0; i < args.Length(); i++) { |
568 HandleScope handle_scope(args.GetIsolate()); | 568 HandleScope handle_scope(args.GetIsolate()); |
569 if (i != 0) { | 569 if (i != 0) { |
570 printf(" "); | 570 printf(" "); |
571 } | 571 } |
572 | 572 |
573 // Explicitly catch potential exceptions in toString(). | 573 // Explicitly catch potential exceptions in toString(). |
574 v8::TryCatch try_catch; | 574 v8::TryCatch try_catch(args.GetIsolate()); |
575 Handle<String> str_obj = args[i]->ToString(args.GetIsolate()); | 575 Handle<String> str_obj = args[i]->ToString(args.GetIsolate()); |
576 if (try_catch.HasCaught()) { | 576 if (try_catch.HasCaught()) { |
577 try_catch.ReThrow(); | 577 try_catch.ReThrow(); |
578 return; | 578 return; |
579 } | 579 } |
580 | 580 |
581 v8::String::Utf8Value str(str_obj); | 581 v8::String::Utf8Value str(str_obj); |
582 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout)); | 582 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout)); |
583 if (n != str.length()) { | 583 if (n != str.length()) { |
584 printf("Error in fwrite\n"); | 584 printf("Error in fwrite\n"); |
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 } | 1748 } |
1749 | 1749 |
1750 } // namespace v8 | 1750 } // namespace v8 |
1751 | 1751 |
1752 | 1752 |
1753 #ifndef GOOGLE3 | 1753 #ifndef GOOGLE3 |
1754 int main(int argc, char* argv[]) { | 1754 int main(int argc, char* argv[]) { |
1755 return v8::Shell::Main(argc, argv); | 1755 return v8::Shell::Main(argc, argv); |
1756 } | 1756 } |
1757 #endif | 1757 #endif |
OLD | NEW |