Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/d8.cc

Issue 20319: Update d8 preemption mode to support multiple files per line. Each line is r... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 for (int i = 0; i < size;) { 412 for (int i = 0; i < size;) {
413 int read = fread(&chars[i], 1, size - i, file); 413 int read = fread(&chars[i], 1, size - i, file);
414 i += read; 414 i += read;
415 } 415 }
416 fclose(file); 416 fclose(file);
417 *size_out = size; 417 *size_out = size;
418 return chars; 418 return chars;
419 } 419 }
420 420
421 421
422 static char* ReadToken(const char* data, char token) {
423 char* next = ::strchr(data, token);
424 if (next != NULL) {
425 *next = '\0';
426 return (next + 1);
427 }
428
429 return NULL;
430 }
431
432
433 static char* ReadLine(const char* data) {
434 return ReadToken(data, '\n');
435 }
436
437
438 static char* ReadWord(const char* data) {
439 return ReadToken(data, ' ');
440 }
441
442
422 // Reads a file into a v8 string. 443 // Reads a file into a v8 string.
423 Handle<String> Shell::ReadFile(const char* name) { 444 Handle<String> Shell::ReadFile(const char* name) {
424 int size = 0; 445 int size = 0;
425 char* chars = ReadChars(name, &size); 446 char* chars = ReadChars(name, &size);
426 if (chars == NULL) return Handle<String>(); 447 if (chars == NULL) return Handle<String>();
427 Handle<String> result = String::New(chars); 448 Handle<String> result = String::New(chars);
428 delete[] chars; 449 delete[] chars;
429 return result; 450 return result;
430 } 451 }
431 452
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 Locker locker; 487 Locker locker;
467 HandleScope scope; 488 HandleScope scope;
468 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); 489 Handle<ObjectTemplate> global_template = ObjectTemplate::New();
469 global_template->Set(String::New("print"), 490 global_template->Set(String::New("print"),
470 FunctionTemplate::New(Shell::Print)); 491 FunctionTemplate::New(Shell::Print));
471 global_template->Set(String::New("load"), 492 global_template->Set(String::New("load"),
472 FunctionTemplate::New(Shell::Load)); 493 FunctionTemplate::New(Shell::Load));
473 global_template->Set(String::New("version"), 494 global_template->Set(String::New("version"),
474 FunctionTemplate::New(Shell::Version)); 495 FunctionTemplate::New(Shell::Version));
475 496
476 Persistent<Context> thread_context = Context::New(NULL, global_template);
477 thread_context->SetSecurityToken(Undefined());
478
479 Context::Scope context_scope(thread_context);
480
481 char* ptr = const_cast<char*>(files_.start()); 497 char* ptr = const_cast<char*>(files_.start());
482 while ((ptr != NULL) && (*ptr != '\0')) { 498 while ((ptr != NULL) && (*ptr != '\0')) {
483 // For each newline-separated line. 499 // For each newline-separated line.
484 char *filename = ptr; 500 char* next_line = ReadLine(ptr);
485 char* next = ::strchr(ptr, '\n'); 501
486 if (next != NULL) { 502 if (*ptr == '#') {
487 *next = '\0'; 503 // Skip comment lines.
488 ptr = (next + 1); 504 ptr = next_line;
489 } else { 505 continue;
490 ptr = NULL;
491 } 506 }
492 Handle<String> str = Shell::ReadFile(filename); 507
493 Shell::ExecuteString(str, String::New(filename), false, false); 508 Persistent<Context> thread_context = Context::New(NULL, global_template);
509 thread_context->SetSecurityToken(Undefined());
510 Context::Scope context_scope(thread_context);
511
512 while ((ptr != NULL) && (*ptr != '\0')) {
513 char* filename = ptr;
514 ptr = ReadWord(ptr);
515
516 // Skip empty strings.
517 if (strlen(filename) == 0) {
518 break;
519 }
520
521 Handle<String> str = Shell::ReadFile(filename);
522 if (str.IsEmpty()) {
523 printf("WARNING: %s not found\n", filename);
524 break;
525 }
526
527 Shell::ExecuteString(str, String::New(filename), false, false);
528 }
529
530 thread_context.Dispose();
531 ptr = next_line;
494 } 532 }
495
496 thread_context.Dispose();
497 } 533 }
498 534
499 535
500 int Shell::Main(int argc, char* argv[]) { 536 int Shell::Main(int argc, char* argv[]) {
501 i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); 537 i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
502 if (i::FLAG_help) { 538 if (i::FLAG_help) {
503 return 1; 539 return 1;
504 } 540 }
505 Initialize(); 541 Initialize();
506 bool run_shell = (argc == 1); 542 bool run_shell = (argc == 1);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 return 0; 605 return 0;
570 } 606 }
571 607
572 608
573 } // namespace v8 609 } // namespace v8
574 610
575 611
576 int main(int argc, char* argv[]) { 612 int main(int argc, char* argv[]) {
577 return v8::Shell::Main(argc, argv); 613 return v8::Shell::Main(argc, argv);
578 } 614 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698