Author: [email protected]
Date: Wed Feb 18 20:26:04 2009
New Revision: 1306
Modified:
branches/bleeding_edge/src/d8.cc
Log:
Update d8 preemption mode to support multiple files per line. Each line is
run
in its own context. Files are separated by spaces, and will be run in
order,
left to right.
Also add support for comment lines, which start with '#'.
Review URL: http://codereview.chromium.org/20319
Modified: branches/bleeding_edge/src/d8.cc
==============================================================================
--- branches/bleeding_edge/src/d8.cc (original)
+++ branches/bleeding_edge/src/d8.cc Wed Feb 18 20:26:04 2009
@@ -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);
- }
- thread_context.Dispose();
+ 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;
+ }
}
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---