Reviewers: ,

Message:
The Sunspider command-line tool changed in order to improve its accuracy:

http://trac.webkit.org/changeset/72842

In order to execute this benchmark out-of-the-box d8 should mimic the run()
function in JavaScriptCore shell.

This patch adds the run() function to the d8 shell.

Description:
The Sunspider command-line tool changed in order to improve its accuracy:

http://trac.webkit.org/changeset/72842

In order to execute this benchmark out-of-the-box d8 should mimic
the run() function in JavaScriptCore shell.

This patch adds the run() function to the d8 shell.

Please review this at http://codereview.chromium.org/6520017/

Affected files:
  M src/d8.h
  M src/d8.cc


Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index f0da7ac8bcf4b89070c71ca7e4bc232d3a82cc15..06861bf74f87a38eaf9d2d79909efdb679fd0880 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -195,6 +195,29 @@ Handle<Value> Shell::ReadLine(const Arguments& args) {
 }


+Handle<Value> Shell::Run(const Arguments& args) {
+  double start_time, stop_time;
+  start_time = stop_time = 0;
+  for (int i = 0; i < args.Length(); i++) {
+    HandleScope handle_scope;
+    String::Utf8Value file(args[i]);
+    if (*file == NULL) {
+      return ThrowException(String::New("Error loading file"));
+    }
+    Handle<String> source = ReadFile(*file);
+    if (source.IsEmpty()) {
+      return ThrowException(String::New("Error loading file"));
+    }
+    start_time = i::OS::TimeCurrentMillis();
+    if (!ExecuteString(source, String::New(*file), false, false)) {
+      return ThrowException(String::New("Error executing file"));
+    }
+    stop_time = i::OS::TimeCurrentMillis();
+  }
+  return Integer::New(stop_time - start_time);
+}
+
+
 Handle<Value> Shell::Load(const Arguments& args) {
   for (int i = 0; i < args.Length(); i++) {
     HandleScope handle_scope;
@@ -419,6 +442,7 @@ void Shell::Initialize() {
   global_template->Set(String::New("read"), FunctionTemplate::New(Read));
   global_template->Set(String::New("readline"),
                        FunctionTemplate::New(ReadLine));
+  global_template->Set(String::New("run"), FunctionTemplate::New(Run));
   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));
Index: src/d8.h
diff --git a/src/d8.h b/src/d8.h
index de1fe0de76645b78bf8e1f5978b512c5a16b177a..61025ac0d5bc919677e87a11cdf06e2ed142fbd4 100644
--- a/src/d8.h
+++ b/src/d8.h
@@ -147,6 +147,7 @@ class Shell: public i::AllStatic {
   static Handle<Value> Yield(const Arguments& args);
   static Handle<Value> Quit(const Arguments& args);
   static Handle<Value> Version(const Arguments& args);
+  static Handle<Value> Run(const Arguments& args);
   static Handle<Value> Read(const Arguments& args);
   static Handle<Value> ReadLine(const Arguments& args);
   static Handle<Value> Load(const Arguments& args);


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to