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

Side by Side Diff: src/d8.cc

Issue 57005: Add os.chdir and os.setenv to d8. Move system() to os.system(). (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') | src/d8-posix.cc » ('j') | 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::SetEnvironment(const Arguments& args) {
167 if (args.Length() != 2) {
168 const char* message = "setenv() takes two arguments";
169 return ThrowException(String::New(message));
170 }
171 String::Utf8Value var(args[0]);
172 String::Utf8Value value(args[1]);
173 if (*var == NULL) {
174 const char* message =
175 "os.setenv(): String conversion of variable name failed.";
176 return ThrowException(String::New(message));
177 }
178 if (*value == NULL) {
179 const char* message =
180 "os.setenv(): String conversion of variable contents failed.";
181 return ThrowException(String::New(message));
182 }
183 setenv(*var, *value, 1);
184 return v8::Undefined();
185 }
186
187
166 Handle<Value> Shell::Load(const Arguments& args) { 188 Handle<Value> Shell::Load(const Arguments& args) {
167 for (int i = 0; i < args.Length(); i++) { 189 for (int i = 0; i < args.Length(); i++) {
168 HandleScope handle_scope; 190 HandleScope handle_scope;
169 String::Utf8Value file(args[i]); 191 String::Utf8Value file(args[i]);
170 if (*file == NULL) { 192 if (*file == NULL) {
171 return ThrowException(String::New("Error loading file")); 193 return ThrowException(String::New("Error loading file"));
172 } 194 }
173 Handle<String> source = ReadFile(*file); 195 Handle<String> source = ReadFile(*file);
174 if (source.IsEmpty()) { 196 if (source.IsEmpty()) {
175 return ThrowException(String::New("Error loading file")); 197 return ThrowException(String::New("Error loading file"));
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 MapCounters(i::FLAG_map_counters); 357 MapCounters(i::FLAG_map_counters);
336 if (i::FLAG_dump_counters) 358 if (i::FLAG_dump_counters)
337 V8::SetCounterFunction(LookupCounter); 359 V8::SetCounterFunction(LookupCounter);
338 // Initialize the global objects 360 // Initialize the global objects
339 HandleScope scope; 361 HandleScope scope;
340 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); 362 Handle<ObjectTemplate> global_template = ObjectTemplate::New();
341 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); 363 global_template->Set(String::New("print"), FunctionTemplate::New(Print));
342 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); 364 global_template->Set(String::New("load"), FunctionTemplate::New(Load));
343 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); 365 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
344 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); 366 global_template->Set(String::New("version"), FunctionTemplate::New(Version));
345 global_template->Set(String::New("system"), FunctionTemplate::New(System)); 367
368 Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
369 os_templ->Set(String::New("system"), FunctionTemplate::New(System));
370 os_templ->Set(String::New("chdir"), FunctionTemplate::New(ChangeDirectory));
371 os_templ->Set(String::New("setenv"), FunctionTemplate::New(SetEnvironment));
372 global_template->Set(String::New("os"), os_templ);
346 373
347 utility_context_ = Context::New(NULL, global_template); 374 utility_context_ = Context::New(NULL, global_template);
348 utility_context_->SetSecurityToken(Undefined()); 375 utility_context_->SetSecurityToken(Undefined());
349 Context::Scope utility_scope(utility_context_); 376 Context::Scope utility_scope(utility_context_);
350 377
351 i::JSArguments js_args = i::FLAG_js_arguments; 378 i::JSArguments js_args = i::FLAG_js_arguments;
352 i::Handle<i::FixedArray> arguments_array = 379 i::Handle<i::FixedArray> arguments_array =
353 i::Factory::NewFixedArray(js_args.argc()); 380 i::Factory::NewFixedArray(js_args.argc());
354 for (int j = 0; j < js_args.argc(); j++) { 381 for (int j = 0; j < js_args.argc(); j++) {
355 i::Handle<i::String> arg = 382 i::Handle<i::String> arg =
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 return 0; 692 return 0;
666 } 693 }
667 694
668 695
669 } // namespace v8 696 } // namespace v8
670 697
671 698
672 int main(int argc, char* argv[]) { 699 int main(int argc, char* argv[]) {
673 return v8::Shell::Main(argc, argv); 700 return v8::Shell::Main(argc, argv);
674 } 701 }
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/d8-posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698