OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 enum MainCycleType { | 95 enum MainCycleType { |
96 CycleInCpp, | 96 CycleInCpp, |
97 CycleInJs | 97 CycleInJs |
98 }; | 98 }; |
99 | 99 |
100 const char* ToCString(const v8::String::Utf8Value& value); | 100 const char* ToCString(const v8::String::Utf8Value& value); |
101 void ReportException(v8::Isolate* isolate, v8::TryCatch* handler); | 101 void ReportException(v8::Isolate* isolate, v8::TryCatch* handler); |
102 v8::Handle<v8::String> ReadFile(const char* name); | 102 v8::Handle<v8::String> ReadFile(const char* name); |
103 v8::Handle<v8::String> ReadLine(); | 103 v8::Handle<v8::String> ReadLine(); |
104 | 104 |
105 v8::Handle<v8::Value> Print(const v8::Arguments& args); | 105 void Print(const v8::FunctionCallbackInfo<v8::Value>& args); |
106 v8::Handle<v8::Value> ReadLine(const v8::Arguments& args); | 106 void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args); |
107 bool RunCppCycle(v8::Handle<v8::Script> script, | 107 bool RunCppCycle(v8::Handle<v8::Script> script, |
108 v8::Local<v8::Context> context, | 108 v8::Local<v8::Context> context, |
109 bool report_exceptions); | 109 bool report_exceptions); |
110 | 110 |
111 | 111 |
112 #ifdef ENABLE_DEBUGGER_SUPPORT | 112 #ifdef ENABLE_DEBUGGER_SUPPORT |
113 v8::Persistent<v8::Context> debug_message_context; | 113 v8::Persistent<v8::Context> debug_message_context; |
114 | 114 |
115 void DispatchDebugMessages() { | 115 void DispatchDebugMessages() { |
116 // We are in some random thread. We should already have v8::Locker acquired | 116 // We are in some random thread. We should already have v8::Locker acquired |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 printf("^"); | 386 printf("^"); |
387 } | 387 } |
388 printf("\n"); | 388 printf("\n"); |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 | 392 |
393 // The callback that is invoked by v8 whenever the JavaScript 'print' | 393 // The callback that is invoked by v8 whenever the JavaScript 'print' |
394 // function is called. Prints its arguments on stdout separated by | 394 // function is called. Prints its arguments on stdout separated by |
395 // spaces and ending with a newline. | 395 // spaces and ending with a newline. |
396 v8::Handle<v8::Value> Print(const v8::Arguments& args) { | 396 void Print(const v8::FunctionCallbackInfo<v8::Value>& args) { |
397 bool first = true; | 397 bool first = true; |
398 for (int i = 0; i < args.Length(); i++) { | 398 for (int i = 0; i < args.Length(); i++) { |
399 v8::HandleScope handle_scope(args.GetIsolate()); | 399 v8::HandleScope handle_scope(args.GetIsolate()); |
400 if (first) { | 400 if (first) { |
401 first = false; | 401 first = false; |
402 } else { | 402 } else { |
403 printf(" "); | 403 printf(" "); |
404 } | 404 } |
405 v8::String::Utf8Value str(args[i]); | 405 v8::String::Utf8Value str(args[i]); |
406 const char* cstr = ToCString(str); | 406 const char* cstr = ToCString(str); |
407 printf("%s", cstr); | 407 printf("%s", cstr); |
408 } | 408 } |
409 printf("\n"); | 409 printf("\n"); |
410 fflush(stdout); | 410 fflush(stdout); |
411 return v8::Undefined(); | |
412 } | 411 } |
413 | 412 |
414 | 413 |
415 // The callback that is invoked by v8 whenever the JavaScript 'read_line' | 414 // The callback that is invoked by v8 whenever the JavaScript 'read_line' |
416 // function is called. Reads a string from standard input and returns. | 415 // function is called. Reads a string from standard input and returns. |
417 v8::Handle<v8::Value> ReadLine(const v8::Arguments& args) { | 416 void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) { |
418 if (args.Length() > 0) { | 417 if (args.Length() > 0) { |
419 return v8::ThrowException(v8::String::New("Unexpected arguments")); | 418 v8::ThrowException(v8::String::New("Unexpected arguments")); |
| 419 return; |
420 } | 420 } |
421 return ReadLine(); | 421 args.GetReturnValue().Set(ReadLine()); |
422 } | 422 } |
423 | 423 |
424 v8::Handle<v8::String> ReadLine() { | 424 v8::Handle<v8::String> ReadLine() { |
425 const int kBufferSize = 1024 + 1; | 425 const int kBufferSize = 1024 + 1; |
426 char buffer[kBufferSize]; | 426 char buffer[kBufferSize]; |
427 | 427 |
428 char* res; | 428 char* res; |
429 { | 429 { |
430 #ifdef ENABLE_DEBUGGER_SUPPORT | 430 #ifdef ENABLE_DEBUGGER_SUPPORT |
431 v8::Unlocker unlocker(v8::Isolate::GetCurrent()); | 431 v8::Unlocker unlocker(v8::Isolate::GetCurrent()); |
432 #endif // ENABLE_DEBUGGER_SUPPORT | 432 #endif // ENABLE_DEBUGGER_SUPPORT |
433 res = fgets(buffer, kBufferSize, stdin); | 433 res = fgets(buffer, kBufferSize, stdin); |
434 } | 434 } |
435 if (res == NULL) { | 435 if (res == NULL) { |
436 v8::Handle<v8::Primitive> t = v8::Undefined(); | 436 v8::Handle<v8::Primitive> t = v8::Undefined(); |
437 return v8::Handle<v8::String>::Cast(t); | 437 return v8::Handle<v8::String>::Cast(t); |
438 } | 438 } |
439 // Remove newline char | 439 // Remove newline char |
440 for (char* pos = buffer; *pos != '\0'; pos++) { | 440 for (char* pos = buffer; *pos != '\0'; pos++) { |
441 if (*pos == '\n') { | 441 if (*pos == '\n') { |
442 *pos = '\0'; | 442 *pos = '\0'; |
443 break; | 443 break; |
444 } | 444 } |
445 } | 445 } |
446 return v8::String::New(buffer); | 446 return v8::String::New(buffer); |
447 } | 447 } |
OLD | NEW |