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

Side by Side Diff: src/d8.cc

Issue 67262: Add a "read" extension to the shell programs. This global function... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 8 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 | « src/d8.h ('k') | 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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 156 }
157 v8::String::Utf8Value str(args[i]); 157 v8::String::Utf8Value str(args[i]);
158 const char* cstr = ToCString(str); 158 const char* cstr = ToCString(str);
159 printf("%s", cstr); 159 printf("%s", cstr);
160 } 160 }
161 printf("\n"); 161 printf("\n");
162 return Undefined(); 162 return Undefined();
163 } 163 }
164 164
165 165
166 Handle<Value> Shell::Read(const Arguments& args) {
167 if (args.Length() != 1) {
168 return ThrowException(String::New("Bad parameters"));
169 }
170 String::Utf8Value file(args[0]);
171 if (*file == NULL) {
172 return ThrowException(String::New("Error loading file"));
173 }
174 Handle<String> source = ReadFile(*file);
175 if (source.IsEmpty()) {
176 return ThrowException(String::New("Error loading file"));
177 }
178 return source;
179 }
180
181
166 Handle<Value> Shell::Load(const Arguments& args) { 182 Handle<Value> Shell::Load(const Arguments& args) {
167 for (int i = 0; i < args.Length(); i++) { 183 for (int i = 0; i < args.Length(); i++) {
168 HandleScope handle_scope; 184 HandleScope handle_scope;
169 String::Utf8Value file(args[i]); 185 String::Utf8Value file(args[i]);
170 if (*file == NULL) { 186 if (*file == NULL) {
171 return ThrowException(String::New("Error loading file")); 187 return ThrowException(String::New("Error loading file"));
172 } 188 }
173 Handle<String> source = ReadFile(*file); 189 Handle<String> source = ReadFile(*file);
174 if (source.IsEmpty()) { 190 if (source.IsEmpty()) {
175 return ThrowException(String::New("Error loading file")); 191 return ThrowException(String::New("Error loading file"));
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 if (i::FLAG_dump_counters) { 390 if (i::FLAG_dump_counters) {
375 V8::SetCounterFunction(LookupCounter); 391 V8::SetCounterFunction(LookupCounter);
376 V8::SetCreateHistogramFunction(CreateHistogram); 392 V8::SetCreateHistogramFunction(CreateHistogram);
377 V8::SetAddHistogramSampleFunction(AddHistogramSample); 393 V8::SetAddHistogramSampleFunction(AddHistogramSample);
378 } 394 }
379 395
380 // Initialize the global objects 396 // Initialize the global objects
381 HandleScope scope; 397 HandleScope scope;
382 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); 398 Handle<ObjectTemplate> global_template = ObjectTemplate::New();
383 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); 399 global_template->Set(String::New("print"), FunctionTemplate::New(Print));
400 global_template->Set(String::New("read"), FunctionTemplate::New(Read));
384 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); 401 global_template->Set(String::New("load"), FunctionTemplate::New(Load));
385 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); 402 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
386 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); 403 global_template->Set(String::New("version"), FunctionTemplate::New(Version));
387 404
388 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); 405 Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
389 AddOSMethods(os_templ); 406 AddOSMethods(os_templ);
390 global_template->Set(String::New("os"), os_templ); 407 global_template->Set(String::New("os"), os_templ);
391 408
392 utility_context_ = Context::New(NULL, global_template); 409 utility_context_ = Context::New(NULL, global_template);
393 utility_context_->SetSecurityToken(Undefined()); 410 utility_context_->SetSecurityToken(Undefined());
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 }; 565 };
549 566
550 567
551 void ShellThread::Run() { 568 void ShellThread::Run() {
552 // Prepare the context for this thread. 569 // Prepare the context for this thread.
553 Locker locker; 570 Locker locker;
554 HandleScope scope; 571 HandleScope scope;
555 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); 572 Handle<ObjectTemplate> global_template = ObjectTemplate::New();
556 global_template->Set(String::New("print"), 573 global_template->Set(String::New("print"),
557 FunctionTemplate::New(Shell::Print)); 574 FunctionTemplate::New(Shell::Print));
575 global_template->Set(String::New("read"),
576 FunctionTemplate::New(Shell::Read));
558 global_template->Set(String::New("load"), 577 global_template->Set(String::New("load"),
559 FunctionTemplate::New(Shell::Load)); 578 FunctionTemplate::New(Shell::Load));
560 global_template->Set(String::New("yield"), 579 global_template->Set(String::New("yield"),
561 FunctionTemplate::New(Shell::Yield)); 580 FunctionTemplate::New(Shell::Yield));
562 global_template->Set(String::New("version"), 581 global_template->Set(String::New("version"),
563 FunctionTemplate::New(Shell::Version)); 582 FunctionTemplate::New(Shell::Version));
564 583
565 char* ptr = const_cast<char*>(files_.start()); 584 char* ptr = const_cast<char*>(files_.start());
566 while ((ptr != NULL) && (*ptr != '\0')) { 585 while ((ptr != NULL) && (*ptr != '\0')) {
567 // For each newline-separated line. 586 // For each newline-separated line.
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 return 0; 736 return 0;
718 } 737 }
719 738
720 739
721 } // namespace v8 740 } // namespace v8
722 741
723 742
724 int main(int argc, char* argv[]) { 743 int main(int argc, char* argv[]) {
725 return v8::Shell::Main(argc, argv); 744 return v8::Shell::Main(argc, argv);
726 } 745 }
OLDNEW
« no previous file with comments | « src/d8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698