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

Unified 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, 9 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 | « src/d8.h ('k') | src/d8-posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
===================================================================
--- src/d8.cc (revision 1633)
+++ src/d8.cc (working copy)
@@ -163,6 +163,28 @@
}
+Handle<Value> Shell::SetEnvironment(const Arguments& args) {
+ if (args.Length() != 2) {
+ const char* message = "setenv() takes two arguments";
+ return ThrowException(String::New(message));
+ }
+ String::Utf8Value var(args[0]);
+ String::Utf8Value value(args[1]);
+ if (*var == NULL) {
+ const char* message =
+ "os.setenv(): String conversion of variable name failed.";
+ return ThrowException(String::New(message));
+ }
+ if (*value == NULL) {
+ const char* message =
+ "os.setenv(): String conversion of variable contents failed.";
+ return ThrowException(String::New(message));
+ }
+ setenv(*var, *value, 1);
+ return v8::Undefined();
+}
+
+
Handle<Value> Shell::Load(const Arguments& args) {
for (int i = 0; i < args.Length(); i++) {
HandleScope handle_scope;
@@ -342,8 +364,13 @@
global_template->Set(String::New("load"), FunctionTemplate::New(Load));
global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
global_template->Set(String::New("version"), FunctionTemplate::New(Version));
- global_template->Set(String::New("system"), FunctionTemplate::New(System));
+ Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
+ os_templ->Set(String::New("system"), FunctionTemplate::New(System));
+ os_templ->Set(String::New("chdir"), FunctionTemplate::New(ChangeDirectory));
+ os_templ->Set(String::New("setenv"), FunctionTemplate::New(SetEnvironment));
+ global_template->Set(String::New("os"), os_templ);
+
utility_context_ = Context::New(NULL, global_template);
utility_context_->SetSecurityToken(Undefined());
Context::Scope utility_scope(utility_context_);
« 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