| 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 410 } |
| 411 printf("\n"); | 411 printf("\n"); |
| 412 fflush(stdout); | 412 fflush(stdout); |
| 413 } | 413 } |
| 414 | 414 |
| 415 | 415 |
| 416 // The callback that is invoked by v8 whenever the JavaScript 'read_line' | 416 // The callback that is invoked by v8 whenever the JavaScript 'read_line' |
| 417 // function is called. Reads a string from standard input and returns. | 417 // function is called. Reads a string from standard input and returns. |
| 418 void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) { | 418 void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 419 if (args.Length() > 0) { | 419 if (args.Length() > 0) { |
| 420 v8::ThrowException(v8::String::New("Unexpected arguments")); | 420 args.GetIsolate()->ThrowException(v8::String::New("Unexpected arguments")); |
| 421 return; | 421 return; |
| 422 } | 422 } |
| 423 args.GetReturnValue().Set(ReadLine()); | 423 args.GetReturnValue().Set(ReadLine()); |
| 424 } | 424 } |
| 425 | 425 |
| 426 | 426 |
| 427 v8::Handle<v8::String> ReadLine() { | 427 v8::Handle<v8::String> ReadLine() { |
| 428 const int kBufferSize = 1024 + 1; | 428 const int kBufferSize = 1024 + 1; |
| 429 char buffer[kBufferSize]; | 429 char buffer[kBufferSize]; |
| 430 | 430 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 441 } | 441 } |
| 442 // Remove newline char | 442 // Remove newline char |
| 443 for (char* pos = buffer; *pos != '\0'; pos++) { | 443 for (char* pos = buffer; *pos != '\0'; pos++) { |
| 444 if (*pos == '\n') { | 444 if (*pos == '\n') { |
| 445 *pos = '\0'; | 445 *pos = '\0'; |
| 446 break; | 446 break; |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 return v8::String::New(buffer); | 449 return v8::String::New(buffer); |
| 450 } | 450 } |
| OLD | NEW |