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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
===================================================================
--- src/d8.cc (revision 1260)
+++ src/d8.cc (working copy)
@@ -419,6 +419,27 @@
}
+static char* ReadToken(const char* data, char token) {
+ char* next = ::strchr(data, token);
+ if (next != NULL) {
+ *next = '\0';
+ return (next + 1);
+ }
+
+ return NULL;
+}
+
+
+static char* ReadLine(const char* data) {
+ return ReadToken(data, '\n');
+}
+
+
+static char* ReadWord(const char* data) {
+ return ReadToken(data, ' ');
+}
+
+
// Reads a file into a v8 string.
Handle<String> Shell::ReadFile(const char* name) {
int size = 0;
@@ -473,27 +494,42 @@
global_template->Set(String::New("version"),
FunctionTemplate::New(Shell::Version));
- Persistent<Context> thread_context = Context::New(NULL, global_template);
- thread_context->SetSecurityToken(Undefined());
-
- Context::Scope context_scope(thread_context);
-
char* ptr = const_cast<char*>(files_.start());
while ((ptr != NULL) && (*ptr != '\0')) {
// For each newline-separated line.
- char *filename = ptr;
- char* next = ::strchr(ptr, '\n');
- if (next != NULL) {
- *next = '\0';
- ptr = (next + 1);
- } else {
- ptr = NULL;
+ char* next_line = ReadLine(ptr);
+
+ if (*ptr == '#') {
+ // Skip comment lines.
+ ptr = next_line;
+ continue;
}
- Handle<String> str = Shell::ReadFile(filename);
- Shell::ExecuteString(str, String::New(filename), false, false);
+
+ Persistent<Context> thread_context = Context::New(NULL, global_template);
+ thread_context->SetSecurityToken(Undefined());
+ Context::Scope context_scope(thread_context);
+
+ while ((ptr != NULL) && (*ptr != '\0')) {
+ char* filename = ptr;
+ ptr = ReadWord(ptr);
+
+ // Skip empty strings.
+ if (strlen(filename) == 0) {
+ break;
+ }
+
+ Handle<String> str = Shell::ReadFile(filename);
+ if (str.IsEmpty()) {
+ printf("WARNING: %s not found\n", filename);
+ break;
+ }
+
+ Shell::ExecuteString(str, String::New(filename), false, false);
+ }
+
+ thread_context.Dispose();
+ ptr = next_line;
}
-
- thread_context.Dispose();
}
« 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