<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[27031] trunk/JavaScriptCore</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/27031">27031</a></dd>
<dt>Author</dt> <dd>eseidel</dd>
<dt>Date</dt> <dd>2007-10-25 02:08:51 -0700 (Thu, 25 Oct 2007)</dd>
</dl>

<h3>Log Message</h3>
<pre>2007-10-25  Eric Seidel  &lt;eric@webkit.org&gt;

        Reviewed by Maciej.
        
        More preparation work before adding long-running mode to testkjs.

        * kjs/testkjs.cpp:
        (TestFunctionImp::callAsFunction):
        (prettyPrintScript):
        (runWithScripts):
        (parseArguments):
        (kjsmain):
        (fillBufferWithContentsOfFile):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkJavaScriptCoreChangeLog">trunk/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkJavaScriptCorekjstestkjscpp">trunk/JavaScriptCore/kjs/testkjs.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/JavaScriptCore/ChangeLog (27030 => 27031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JavaScriptCore/ChangeLog        2007-10-25 08:53:15 UTC (rev 27030)
+++ trunk/JavaScriptCore/ChangeLog        2007-10-25 09:08:51 UTC (rev 27031)
</span><span class="lines">@@ -2,6 +2,20 @@
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Maciej.
</span><span class="cx">         
</span><ins>+        More preparation work before adding long-running mode to testkjs.
+
+        * kjs/testkjs.cpp:
+        (TestFunctionImp::callAsFunction):
+        (prettyPrintScript):
+        (runWithScripts):
+        (parseArguments):
+        (kjsmain):
+        (fillBufferWithContentsOfFile):
+
+2007-10-25  Eric Seidel  &lt;eric@webkit.org&gt;
+
+        Reviewed by Maciej.
+        
</ins><span class="cx">         Bring testkjs code out of the dark ages in preparation for more
</span><span class="cx">         radical improvements (like long-running testing support!)
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (27030 => 27031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2007-10-25 08:53:15 UTC (rev 27030)
+++ trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2007-10-25 09:08:51 UTC (rev 27031)
</span><span class="lines">@@ -1379,7 +1379,6 @@
</span><span class="cx">                 0867D690FE84028FC02AAC07 /* Project object */ = {
</span><span class="cx">                         isa = PBXProject;
</span><span class="cx">                         buildConfigurationList = 149C277108902AFE008A9EFC /* Build configuration list for PBXProject &quot;JavaScriptCore&quot; */;
</span><del>-                        compatibilityVersion = &quot;Xcode 2.4&quot;;
</del><span class="cx">                         hasScannedForEncodings = 1;
</span><span class="cx">                         mainGroup = 0867D691FE84028FC02AAC07 /* JavaScriptCore */;
</span><span class="cx">                         productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
</span></span></pre></div>
<a id="trunkJavaScriptCorekjstestkjscpp"></a>
<div class="modfile"><h4>Modified: trunk/JavaScriptCore/kjs/testkjs.cpp (27030 => 27031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JavaScriptCore/kjs/testkjs.cpp        2007-10-25 08:53:15 UTC (rev 27030)
+++ trunk/JavaScriptCore/kjs/testkjs.cpp        2007-10-25 09:08:51 UTC (rev 27031)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx"> using namespace WTF;
</span><span class="cx"> 
</span><span class="cx"> static void testIsInteger();
</span><del>-static bool fillBufferWithContentsOfFile(const char* fileName, Vector&lt;char&gt;&amp; buffer);
</del><ins>+static bool fillBufferWithContentsOfFile(const UString&amp; fileName, Vector&lt;char&gt;&amp; buffer);
</ins><span class="cx"> 
</span><span class="cx"> class StopWatch
</span><span class="cx"> {
</span><span class="lines">@@ -159,7 +159,7 @@
</span><span class="cx">       StopWatch stopWatch;
</span><span class="cx">       UString fileName = args[0]-&gt;toString(exec);
</span><span class="cx">       Vector&lt;char&gt; script;
</span><del>-      if (!fillBufferWithContentsOfFile(fileName.UTF8String().c_str(), script))
</del><ins>+      if (!fillBufferWithContentsOfFile(fileName, script))
</ins><span class="cx">         return throwError(exec, GeneralError, &quot;Could not open file.&quot;);
</span><span class="cx"> 
</span><span class="cx">       stopWatch.start();
</span><span class="lines">@@ -172,7 +172,7 @@
</span><span class="cx">     {
</span><span class="cx">       UString fileName = args[0]-&gt;toString(exec);
</span><span class="cx">       Vector&lt;char&gt; script;
</span><del>-      if (!fillBufferWithContentsOfFile(fileName.UTF8String().c_str(), script))
</del><ins>+      if (!fillBufferWithContentsOfFile(fileName, script))
</ins><span class="cx">         return throwError(exec, GeneralError, &quot;Could not open file.&quot;);
</span><span class="cx"> 
</span><span class="cx">       exec-&gt;dynamicInterpreter()-&gt;evaluate(fileName, 0, script.data());
</span><span class="lines">@@ -187,26 +187,17 @@
</span><span class="cx">   return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if PLATFORM(WIN_OS)
-
</del><span class="cx"> // Use SEH for Release builds only to get rid of the crash report dialog
</span><del>-// (luckyly the same tests fail in Release and Debug builds so far). Need to
</del><ins>+// (luckily the same tests fail in Release and Debug builds so far). Need to
</ins><span class="cx"> // be in a separate main function because the kjsmain function requires object
</span><span class="cx"> // unwinding.
</span><span class="cx"> 
</span><del>-#if defined(_DEBUG)
-#define TRY
-#define EXCEPT(x)
-#else
</del><ins>+#if PLATFORM(WIN_OS) &amp;&amp; !defined(_DEBUG)
</ins><span class="cx"> #define TRY       __try {
</span><span class="cx"> #define EXCEPT(x) } __except (EXCEPTION_EXECUTE_HANDLER) { x; }
</span><del>-#endif
-
</del><span class="cx"> #else
</span><del>-
</del><span class="cx"> #define TRY
</span><span class="cx"> #define EXCEPT(x)
</span><del>-
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> int kjsmain(int argc, char** argv);
</span><span class="lines">@@ -250,13 +241,13 @@
</span><span class="cx">   return interp.release();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool prettyPrintScript(const char* fileName, const Vector&lt;char&gt;&amp; script)
</del><ins>+static bool prettyPrintScript(const UString&amp; fileName, const Vector&lt;char&gt;&amp; script)
</ins><span class="cx"> {
</span><span class="cx">   int errLine = 0;
</span><span class="cx">   UString errMsg;
</span><span class="cx">   UString s = Parser::prettyPrint(script.data(), &amp;errLine, &amp;errMsg);
</span><span class="cx">   if (s.isNull()) {
</span><del>-    fprintf(stderr, &quot;%s:%d: %s.\n&quot;, fileName, errLine, errMsg.UTF8String().c_str());
</del><ins>+    fprintf(stderr, &quot;%s:%d: %s.\n&quot;, fileName.UTF8String().c_str(), errLine, errMsg.UTF8String().c_str());
</ins><span class="cx">     return false;
</span><span class="cx">   }
</span><span class="cx">   
</span><span class="lines">@@ -264,28 +255,18 @@
</span><span class="cx">   return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool doIt(int argc, char** argv)
</del><ins>+static bool runWithScripts(const Vector&lt;UString&gt;&amp; fileNames, bool prettyPrint)
</ins><span class="cx"> {
</span><del>-  bool success = true;
-  bool prettyPrint = false;
-
</del><span class="cx">   RefPtr&lt;Interpreter&gt; interp = setupInterpreter();
</span><span class="cx">   Vector&lt;char&gt; script;
</span><span class="cx">   
</span><del>-  for (int i = 1; i &lt; argc; i++) {
-    const char* fileName = argv[i];
-    if (strcmp(fileName, &quot;-f&quot;) == 0) // mozilla test driver script uses &quot;-f&quot; prefix for files
-      continue;
-    if (strcmp(fileName, &quot;-p&quot;) == 0) {
-      prettyPrint = true;
-      continue;
-    }
</del><ins>+  bool success = true;
+  
+  for (size_t i = 0; i &lt; fileNames.size(); i++) {
+    UString fileName = fileNames[i];
</ins><span class="cx">     
</span><del>-    script.clear();
-    if (!fillBufferWithContentsOfFile(fileName, script)) {
-      success = false;
-      break; // fail early so we can catch missing files
-    }
</del><ins>+    if (!fillBufferWithContentsOfFile(fileName, script))
+      return false; // fail early so we can catch missing files
</ins><span class="cx">     
</span><span class="cx">     if (prettyPrint)
</span><span class="cx">       prettyPrintScript(fileName, script);
</span><span class="lines">@@ -294,24 +275,40 @@
</span><span class="cx">       success = success &amp;&amp; completion.complType() != Throw;
</span><span class="cx">     }
</span><span class="cx">   }
</span><del>-
</del><span class="cx">   return success;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
-int kjsmain(int argc, char** argv)
</del><ins>+static void parseArguments(int argc, char** argv, Vector&lt;UString&gt;&amp; fileNames, bool&amp; prettyPrint)
</ins><span class="cx"> {
</span><span class="cx">   if (argc &lt; 2) {
</span><span class="cx">     fprintf(stderr, &quot;Usage: testkjs file1 [file2...]\n&quot;);
</span><del>-    return -1;
</del><ins>+    exit(-1);
</ins><span class="cx">   }
</span><ins>+  
+  for (int i = 1; i &lt; argc; i++) {
+    const char* fileName = argv[i];
+    if (strcmp(fileName, &quot;-f&quot;) == 0) // mozilla test driver script uses &quot;-f&quot; prefix for files
+      continue;
+    if (strcmp(fileName, &quot;-p&quot;) == 0) {
+      prettyPrint = true;
+      continue;
+    }
+    fileNames.append(fileName);
+  }
+}
</ins><span class="cx"> 
</span><ins>+int kjsmain(int argc, char** argv)
+{
</ins><span class="cx">   testIsInteger();
</span><span class="cx"> 
</span><span class="cx">   JSLock lock;
</span><ins>+  
+  bool prettyPrint = false;
+  Vector&lt;UString&gt; fileNames;
+  parseArguments(argc, argv, fileNames, prettyPrint);
+  
+  bool success = runWithScripts(fileNames, prettyPrint);
</ins><span class="cx"> 
</span><del>-  bool success = doIt(argc, argv);
-
</del><span class="cx"> #ifndef NDEBUG
</span><span class="cx">   Collector::collect();
</span><span class="cx"> #endif
</span><span class="lines">@@ -348,11 +345,11 @@
</span><span class="cx">   ASSERT(!IsInteger&lt;GlobalImp&gt;::value);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool fillBufferWithContentsOfFile(const char* fileName, Vector&lt;char&gt;&amp; buffer)
</del><ins>+static bool fillBufferWithContentsOfFile(const UString&amp; fileName, Vector&lt;char&gt;&amp; buffer)
</ins><span class="cx"> {
</span><del>-  FILE* f = fopen(fileName, &quot;r&quot;);
</del><ins>+  FILE* f = fopen(fileName.UTF8String().c_str(), &quot;r&quot;);
</ins><span class="cx">   if (!f) {
</span><del>-    fprintf(stderr, &quot;Could not open file: %s\n&quot;, fileName);
</del><ins>+    fprintf(stderr, &quot;Could not open file: %s\n&quot;, fileName.UTF8String().c_str());
</ins><span class="cx">     return false;
</span><span class="cx">   }
</span><span class="cx">   
</span></span></pre>
</div>
</div>

</body>
</html>