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

Side by Side Diff: src/d8.cc

Issue 160639: Add a write() command to d8. This is the same as the print() command, with th... Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 4 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 const char* cstr = ToCString(str); 139 const char* cstr = ToCString(str);
140 printf("%s\n", cstr); 140 printf("%s\n", cstr);
141 } 141 }
142 return true; 142 return true;
143 } 143 }
144 } 144 }
145 } 145 }
146 146
147 147
148 Handle<Value> Shell::Print(const Arguments& args) { 148 Handle<Value> Shell::Print(const Arguments& args) {
149 bool first = true; 149 Handle<Value> val = Write(args);
150 printf("\n");
151 return val;
152 }
153
154
155 Handle<Value> Shell::Write(const Arguments& args) {
150 for (int i = 0; i < args.Length(); i++) { 156 for (int i = 0; i < args.Length(); i++) {
151 HandleScope handle_scope; 157 HandleScope handle_scope;
152 if (first) { 158 if (i != 0) {
153 first = false;
154 } else {
155 printf(" "); 159 printf(" ");
156 } 160 }
157 v8::String::Utf8Value str(args[i]); 161 v8::String::Utf8Value str(args[i]);
158 const char* cstr = ToCString(str); 162 const char* cstr = ToCString(str);
159 printf("%s", cstr); 163 printf("%s", cstr);
160 } 164 }
161 printf("\n");
162 return Undefined(); 165 return Undefined();
163 } 166 }
164 167
165 168
166 Handle<Value> Shell::Read(const Arguments& args) { 169 Handle<Value> Shell::Read(const Arguments& args) {
167 if (args.Length() != 1) { 170 if (args.Length() != 1) {
168 return ThrowException(String::New("Bad parameters")); 171 return ThrowException(String::New("Bad parameters"));
169 } 172 }
170 String::Utf8Value file(args[0]); 173 String::Utf8Value file(args[0]);
171 if (*file == NULL) { 174 if (*file == NULL) {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 if (i::FLAG_dump_counters) { 395 if (i::FLAG_dump_counters) {
393 V8::SetCounterFunction(LookupCounter); 396 V8::SetCounterFunction(LookupCounter);
394 V8::SetCreateHistogramFunction(CreateHistogram); 397 V8::SetCreateHistogramFunction(CreateHistogram);
395 V8::SetAddHistogramSampleFunction(AddHistogramSample); 398 V8::SetAddHistogramSampleFunction(AddHistogramSample);
396 } 399 }
397 400
398 // Initialize the global objects 401 // Initialize the global objects
399 HandleScope scope; 402 HandleScope scope;
400 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); 403 Handle<ObjectTemplate> global_template = ObjectTemplate::New();
401 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); 404 global_template->Set(String::New("print"), FunctionTemplate::New(Print));
405 global_template->Set(String::New("write"), FunctionTemplate::New(Write));
402 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); 406 global_template->Set(String::New("read"), FunctionTemplate::New(Read));
403 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); 407 global_template->Set(String::New("load"), FunctionTemplate::New(Load));
404 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); 408 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
405 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); 409 global_template->Set(String::New("version"), FunctionTemplate::New(Version));
406 410
407 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); 411 Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
408 AddOSMethods(os_templ); 412 AddOSMethods(os_templ);
409 global_template->Set(String::New("os"), os_templ); 413 global_template->Set(String::New("os"), os_templ);
410 414
411 utility_context_ = Context::New(NULL, global_template); 415 utility_context_ = Context::New(NULL, global_template);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 }; 585 };
582 586
583 587
584 void ShellThread::Run() { 588 void ShellThread::Run() {
585 // Prepare the context for this thread. 589 // Prepare the context for this thread.
586 Locker locker; 590 Locker locker;
587 HandleScope scope; 591 HandleScope scope;
588 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); 592 Handle<ObjectTemplate> global_template = ObjectTemplate::New();
589 global_template->Set(String::New("print"), 593 global_template->Set(String::New("print"),
590 FunctionTemplate::New(Shell::Print)); 594 FunctionTemplate::New(Shell::Print));
595 global_template->Set(String::New("write"),
596 FunctionTemplate::New(Shell::Write));
591 global_template->Set(String::New("read"), 597 global_template->Set(String::New("read"),
592 FunctionTemplate::New(Shell::Read)); 598 FunctionTemplate::New(Shell::Read));
593 global_template->Set(String::New("load"), 599 global_template->Set(String::New("load"),
594 FunctionTemplate::New(Shell::Load)); 600 FunctionTemplate::New(Shell::Load));
595 global_template->Set(String::New("yield"), 601 global_template->Set(String::New("yield"),
596 FunctionTemplate::New(Shell::Yield)); 602 FunctionTemplate::New(Shell::Yield));
597 global_template->Set(String::New("version"), 603 global_template->Set(String::New("version"),
598 FunctionTemplate::New(Shell::Version)); 604 FunctionTemplate::New(Shell::Version));
599 605
600 char* ptr = const_cast<char*>(files_.start()); 606 char* ptr = const_cast<char*>(files_.start());
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 return 0; 750 return 0;
745 } 751 }
746 752
747 753
748 } // namespace v8 754 } // namespace v8
749 755
750 756
751 int main(int argc, char* argv[]) { 757 int main(int argc, char* argv[]) {
752 return v8::Shell::Main(argc, argv); 758 return v8::Shell::Main(argc, argv);
753 } 759 }
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