<!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" />
<title>[162612] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/162612">162612</a></dd>
<dt>Author</dt> <dd>mhahnenberg@apple.com</dd>
<dt>Date</dt> <dd>2014-01-23 09:09:00 -0800 (Thu, 23 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Basic framework for a modern jsc CLI
https://bugs.webkit.org/show_bug.cgi?id=127435

Reviewed by Geoffrey Garen.

The most basic components of a modern jsc command line interface consist of the following:

- A simple REPL to enter commands and receive results
- The ability to define a module (which consists of various internal methods as well as a
  set of externally visible methods)
- The ability to load other modules at runtime
- The ability to interact with the underlying platform to perform various &quot;privileged&quot;
  functions (e.g. opening files, printing to the stdout, etc.)

The basic architecture will look something like the following:
- If the tool is run in REPL mode (i.e. no command line arguments), it will start the REPL
  on the main thread and start a secondary thread with a run loop to handle various inputs
  from the REPL thread.
- If the tool is given a script to run, it will evaluate that script (and any scripts that
  it might transitively load) within the run loop on the secondary thread while the main
  thread blocks until it has completed.

* Scripts/build-jsc:
* jsc-cli: Added.
* jsc-cli/jsc-cli: Added.
* jsc-cli/jsc-cli.xcodeproj: Added.
* jsc-cli/jsc-cli.xcodeproj/project.pbxproj: Added.
* jsc-cli/jsc-cli/CLIInstance.h: Added.
* jsc-cli/jsc-cli/CLIInstance.m: Added.
(-[CLIInstance init]):
(-[CLIInstance loadFile:]):
(-[CLIInstance run]):
* jsc-cli/jsc-cli/JSModule.h: Added.
* jsc-cli/jsc-cli/JSModule.m: Added.
(coreModules):
(isCoreModule):
(classForModule):
(coreModuleFullPath):
(resolveModuleAsFile):
(resolveModuleAsDirectory):
(nodeModulePaths):
(resolveAsNodeModule):
(+[JSModule resolve:atPath:]):
(globalModuleCache):
(isCached):
(cachedModule):
(cacheModule):
(+[JSModule require:atPath:]):
(+[JSModule require:atPath:inContext:]):
(-[JSModule platformObjectInContext:]):
(-[JSModule initWithId:filename:context:]):
(-[JSModule dealloc]):
(-[JSModule didStartLoading]):
(-[JSModule didFinishLoading]):
(-[JSModule require:]):
(-[JSModule exports]):
* jsc-cli/jsc-cli/JSRunLoopThread.h: Added.
* jsc-cli/jsc-cli/JSRunLoopThread.m: Added.
(jsThreadMain):
(+[JSRunLoopThread threadMain]):
(-[JSRunLoopThread initWithFiles:andContext:]):
(-[JSRunLoopThread startRunLoop]):
(-[JSRunLoopThread start]):
(-[JSRunLoopThread join]):
(-[JSRunLoopThread didReceiveInput:]):
(-[JSRunLoopThread performCallback:withError:]):
(-[JSRunLoopThread performCallback:withArguments:]):
(-[JSRunLoopThread didFinishRunLoopInitialization]):
* jsc-cli/jsc-cli/ReadEvalPrintLoop.h: Added.
* jsc-cli/jsc-cli/ReadEvalPrintLoop.m: Added.
(-[ReadEvalPrintLoop initWithJSThread:]):
(prompt):
(escapeStringForOutput):
(-[ReadEvalPrintLoop processNextInput]):
(-[ReadEvalPrintLoop run]):
* jsc-cli/jsc-cli/RunLoopThread.h: Added.
* jsc-cli/jsc-cli/RunLoopThread.m: Added.
(+[RunLoopThread threadMain]):
(-[RunLoopThread init]):
(-[RunLoopThread dealloc]):
(-[RunLoopThread didFinishRunLoopInitialization]):
(-[RunLoopThread start]):
(-[RunLoopThread join]):
* jsc-cli/jsc-cli/ScriptInputSource.h: Added.
* jsc-cli/jsc-cli/ScriptInputSource.m: Added.
(scriptInputSourceScheduleRoutine):
(scriptInputSourcePerformRoutine):
(scriptInputSourceCancelRoutine):
(-[ScriptInputSource initWithContext:]):
(-[ScriptInputSource dealloc]):
(-[ScriptInputSource addToCurrentRunLoop]):
(-[ScriptInputSource removeFromRemoteRunLoop]):
(-[ScriptInputSource didReceiveScript:]):
(-[ScriptInputSource didReceiveSignal]):
(-[ScriptInputSource runScriptRemotely:]):
(-[ScriptInputSource finishAsyncCallback:withResult:]):
* jsc-cli/jsc-cli/main.m: Added.
(main):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptsbuildjsc">trunk/Tools/Scripts/build-jsc</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/Tools/jsc-cli/</li>
<li>trunk/Tools/jsc-cli/jsc-cli/</li>
<li><a href="#trunkToolsjscclijsccliCLIInstanceh">trunk/Tools/jsc-cli/jsc-cli/CLIInstance.h</a></li>
<li><a href="#trunkToolsjscclijsccliCLIInstancem">trunk/Tools/jsc-cli/jsc-cli/CLIInstance.m</a></li>
<li><a href="#trunkToolsjscclijsccliJSModuleh">trunk/Tools/jsc-cli/jsc-cli/JSModule.h</a></li>
<li><a href="#trunkToolsjscclijsccliJSModulem">trunk/Tools/jsc-cli/jsc-cli/JSModule.m</a></li>
<li><a href="#trunkToolsjscclijsccliJSRunLoopThreadh">trunk/Tools/jsc-cli/jsc-cli/JSRunLoopThread.h</a></li>
<li><a href="#trunkToolsjscclijsccliJSRunLoopThreadm">trunk/Tools/jsc-cli/jsc-cli/JSRunLoopThread.m</a></li>
<li><a href="#trunkToolsjscclijsccliReadEvalPrintLooph">trunk/Tools/jsc-cli/jsc-cli/ReadEvalPrintLoop.h</a></li>
<li><a href="#trunkToolsjscclijsccliReadEvalPrintLoopm">trunk/Tools/jsc-cli/jsc-cli/ReadEvalPrintLoop.m</a></li>
<li><a href="#trunkToolsjscclijsccliRunLoopThreadh">trunk/Tools/jsc-cli/jsc-cli/RunLoopThread.h</a></li>
<li><a href="#trunkToolsjscclijsccliRunLoopThreadm">trunk/Tools/jsc-cli/jsc-cli/RunLoopThread.m</a></li>
<li><a href="#trunkToolsjscclijsccliScriptInputSourceh">trunk/Tools/jsc-cli/jsc-cli/ScriptInputSource.h</a></li>
<li><a href="#trunkToolsjscclijsccliScriptInputSourcem">trunk/Tools/jsc-cli/jsc-cli/ScriptInputSource.m</a></li>
<li><a href="#trunkToolsjscclijscclimainm">trunk/Tools/jsc-cli/jsc-cli/main.m</a></li>
<li>trunk/Tools/jsc-cli/jsc-cli.xcodeproj/</li>
<li><a href="#trunkToolsjscclijscclixcodeprojprojectpbxproj">trunk/Tools/jsc-cli/jsc-cli.xcodeproj/project.pbxproj</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (162611 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2014-01-23 17:05:16 UTC (rev 162611)
+++ trunk/Tools/ChangeLog        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -1,3 +1,104 @@
</span><ins>+2014-01-23  Mark Hahnenberg  &lt;mhahnenberg@apple.com&gt;
+
+        Basic framework for a modern jsc CLI
+        https://bugs.webkit.org/show_bug.cgi?id=127435
+
+        Reviewed by Geoffrey Garen.
+
+        The most basic components of a modern jsc command line interface consist of the following:
+
+        - A simple REPL to enter commands and receive results
+        - The ability to define a module (which consists of various internal methods as well as a 
+          set of externally visible methods)
+        - The ability to load other modules at runtime
+        - The ability to interact with the underlying platform to perform various &quot;privileged&quot; 
+          functions (e.g. opening files, printing to the stdout, etc.)
+        
+        The basic architecture will look something like the following:
+        - If the tool is run in REPL mode (i.e. no command line arguments), it will start the REPL 
+          on the main thread and start a secondary thread with a run loop to handle various inputs 
+          from the REPL thread.
+        - If the tool is given a script to run, it will evaluate that script (and any scripts that 
+          it might transitively load) within the run loop on the secondary thread while the main 
+          thread blocks until it has completed.
+
+        * Scripts/build-jsc:
+        * jsc-cli: Added.
+        * jsc-cli/jsc-cli: Added.
+        * jsc-cli/jsc-cli.xcodeproj: Added.
+        * jsc-cli/jsc-cli.xcodeproj/project.pbxproj: Added.
+        * jsc-cli/jsc-cli/CLIInstance.h: Added.
+        * jsc-cli/jsc-cli/CLIInstance.m: Added.
+        (-[CLIInstance init]):
+        (-[CLIInstance loadFile:]):
+        (-[CLIInstance run]):
+        * jsc-cli/jsc-cli/JSModule.h: Added.
+        * jsc-cli/jsc-cli/JSModule.m: Added.
+        (coreModules):
+        (isCoreModule):
+        (classForModule):
+        (coreModuleFullPath):
+        (resolveModuleAsFile):
+        (resolveModuleAsDirectory):
+        (nodeModulePaths):
+        (resolveAsNodeModule):
+        (+[JSModule resolve:atPath:]):
+        (globalModuleCache):
+        (isCached):
+        (cachedModule):
+        (cacheModule):
+        (+[JSModule require:atPath:]):
+        (+[JSModule require:atPath:inContext:]):
+        (-[JSModule platformObjectInContext:]):
+        (-[JSModule initWithId:filename:context:]):
+        (-[JSModule dealloc]):
+        (-[JSModule didStartLoading]):
+        (-[JSModule didFinishLoading]):
+        (-[JSModule require:]):
+        (-[JSModule exports]):
+        * jsc-cli/jsc-cli/JSRunLoopThread.h: Added.
+        * jsc-cli/jsc-cli/JSRunLoopThread.m: Added.
+        (jsThreadMain):
+        (+[JSRunLoopThread threadMain]):
+        (-[JSRunLoopThread initWithFiles:andContext:]):
+        (-[JSRunLoopThread startRunLoop]):
+        (-[JSRunLoopThread start]):
+        (-[JSRunLoopThread join]):
+        (-[JSRunLoopThread didReceiveInput:]):
+        (-[JSRunLoopThread performCallback:withError:]):
+        (-[JSRunLoopThread performCallback:withArguments:]):
+        (-[JSRunLoopThread didFinishRunLoopInitialization]):
+        * jsc-cli/jsc-cli/ReadEvalPrintLoop.h: Added.
+        * jsc-cli/jsc-cli/ReadEvalPrintLoop.m: Added.
+        (-[ReadEvalPrintLoop initWithJSThread:]):
+        (prompt):
+        (escapeStringForOutput):
+        (-[ReadEvalPrintLoop processNextInput]):
+        (-[ReadEvalPrintLoop run]):
+        * jsc-cli/jsc-cli/RunLoopThread.h: Added.
+        * jsc-cli/jsc-cli/RunLoopThread.m: Added.
+        (+[RunLoopThread threadMain]):
+        (-[RunLoopThread init]):
+        (-[RunLoopThread dealloc]):
+        (-[RunLoopThread didFinishRunLoopInitialization]):
+        (-[RunLoopThread start]):
+        (-[RunLoopThread join]):
+        * jsc-cli/jsc-cli/ScriptInputSource.h: Added.
+        * jsc-cli/jsc-cli/ScriptInputSource.m: Added.
+        (scriptInputSourceScheduleRoutine):
+        (scriptInputSourcePerformRoutine):
+        (scriptInputSourceCancelRoutine):
+        (-[ScriptInputSource initWithContext:]):
+        (-[ScriptInputSource dealloc]):
+        (-[ScriptInputSource addToCurrentRunLoop]):
+        (-[ScriptInputSource removeFromRemoteRunLoop]):
+        (-[ScriptInputSource didReceiveScript:]):
+        (-[ScriptInputSource didReceiveSignal]):
+        (-[ScriptInputSource runScriptRemotely:]):
+        (-[ScriptInputSource finishAsyncCallback:withResult:]):
+        * jsc-cli/jsc-cli/main.m: Added.
+        (main):
+
</ins><span class="cx"> 2014-01-23  László Langó  &lt;llango.u-szeged@partner.samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove a FIXME comment that is already fixed.
</span></span></pre></div>
<a id="trunkToolsScriptsbuildjsc"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/build-jsc (162611 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/build-jsc        2014-01-23 17:05:16 UTC (rev 162611)
+++ trunk/Tools/Scripts/build-jsc        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -118,3 +118,4 @@
</span><span class="cx"> 
</span><span class="cx"> buildMyProject(&quot;Source/WTF&quot;, &quot;WTF&quot;);
</span><span class="cx"> buildMyProject(&quot;Source/JavaScriptCore&quot;, &quot;JavaScriptCore&quot;);
</span><ins>+buildMyProject(&quot;Tools/jsc-cli&quot;, &quot;jsc-cli&quot;);
</ins></span></pre></div>
<a id="trunkToolsjscclijsccliCLIInstanceh"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/CLIInstance.h (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/CLIInstance.h                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/CLIInstance.h        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,38 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &lt;Foundation/Foundation.h&gt;
+
+#ifndef CLIInstance_h
+#define CLIInstance_h
+
+@interface CLIInstance : NSObject
+
+-(void)loadFile:(NSString *)path;
+-(void)run;
+
+@end
+
+#endif // CLInstance_h
</ins></span></pre></div>
<a id="trunkToolsjscclijsccliCLIInstancem"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/CLIInstance.m (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/CLIInstance.m                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/CLIInstance.m        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,84 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;CLIInstance.h&quot;
+
+#import &lt;JavaScriptCore/JavaScriptCore.h&gt;
+
+#import &quot;JSModule.h&quot;
+#import &quot;JSRunLoopThread.h&quot;
+#import &quot;CLIInstance.h&quot;
+#import &quot;ReadEvalPrintLoop.h&quot;
+
+@implementation CLIInstance {
+    JSModule *_moduleLoader;
+    NSString *_baseFile;
+    JSContext *_context;
+    
+    JSRunLoopThread *_jsThread;
+}
+
+- (id)init
+{
+    self = [super init];
+    if (!self)
+        return nil;
+    
+    _baseFile = nil;
+    _moduleLoader = [[JSModule alloc] init];
+    _context = [[JSContext alloc] init];
+    
+    _context[@&quot;require&quot;] = ^(NSString *arg) {
+        JSModule *module = [JSModule require:arg atPath:[[NSFileManager defaultManager] currentDirectoryPath]];
+        if (!module) {
+            [[JSContext currentContext] evaluateScript:@&quot;throw 'not found'&quot;];
+            return [JSValue valueWithUndefinedInContext:[JSContext currentContext]];
+        }
+        return module.exports;
+    };
+    
+    _jsThread = [[JSRunLoopThread alloc] initWithFiles:@[] andContext:_context];
+    
+    return self;
+}
+
+- (void)loadFile:(NSString *)path
+{
+    _baseFile = path;
+}
+
+- (void)run
+{
+    [_jsThread start];
+    
+    if (!_baseFile) {
+        ReadEvalPrintLoop *repl = [[ReadEvalPrintLoop alloc] initWithJSThread:_jsThread];
+        [repl run];
+    }
+
+    [_jsThread join];
+}
+
+@end
</ins></span></pre></div>
<a id="trunkToolsjscclijsccliJSModuleh"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/JSModule.h (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/JSModule.h                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/JSModule.h        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,49 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &lt;Foundation/Foundation.h&gt;
+
+#ifndef JSModule_h
+#define JSModule_h
+
+@class JSContext;
+@class JSValue;
+
+@interface JSModule : NSObject
+
+@property (readonly) JSValue *exports;
+
++ (JSModule *)require:(NSString *)module atPath:(NSString *)path inContext:(JSContext *)context;
++ (JSModule *)require:(NSString *)module atPath:(NSString *)path;
++ (NSString *)resolve:(NSString *)module atPath:(NSString *)path;
+
+- (JSModule *)require:(NSString *)module;
+
+- (JSValue *)platformObjectInContext:(JSContext *)context;
+
+@end
+
+#endif // JSModule_h
+
</ins></span></pre></div>
<a id="trunkToolsjscclijsccliJSModulem"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/JSModule.m (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/JSModule.m                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/JSModule.m        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,297 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;JSModule.h&quot;
+#import &lt;JavaScriptCore/JavaScriptCore.h&gt;
+
+@implementation JSModule {
+    JSManagedValue *_exports;
+    NSString *_id;
+    NSString *_filename;
+    bool _loaded;
+    __weak JSModule *_parent;
+    NSMutableArray *_children;
+}
+
+// TODO: Get lib in the right place. Right now we copy it to the build results directory.
+static NSDictionary *coreModules()
+{
+    static NSDictionary *modules = 0;
+    if (!modules) {
+        // Put location of built-in modules here.
+        modules = @{
+            //@&quot;util&quot;: [libDir stringByAppendingPathComponent:@&quot;util.js&quot;],
+        };
+    }
+    return modules;
+}
+
+static bool isCoreModule(NSString *moduleName)
+{
+    return !![coreModules() objectForKey:moduleName];
+}
+
+static Class classForModule(NSString *moduleName)
+{
+    static NSDictionary *moduleClasses = 0;
+    if (!moduleClasses) {
+        // Put classes for built-in modules here.
+        moduleClasses = @{
+            //@&quot;util&quot;: [JSUtilModule class],
+        };
+    }
+    
+    if (isCoreModule(moduleName))
+        return [moduleClasses objectForKey:moduleName];
+    return [JSModule class];
+}
+
+static NSString *coreModuleFullPath(NSString *moduleName)
+{
+    assert(isCoreModule(moduleName));
+    return [coreModules() objectForKey:moduleName];
+}
+
+static NSString *resolveModuleAsFile(NSString *modulePath)
+{
+    if ([[NSFileManager defaultManager] fileExistsAtPath:modulePath])
+        return modulePath;
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:[modulePath stringByAppendingPathExtension:@&quot;js&quot;]])
+        return [modulePath stringByAppendingPathExtension:@&quot;js&quot;];
+    
+    return nil;
+}
+
+static NSString *resolveModuleAsDirectory(NSString *modulePath)
+{
+    if ([[NSFileManager defaultManager] fileExistsAtPath:[modulePath stringByAppendingPathComponent:@&quot;package.json&quot;]]) {
+        NSString *path = [modulePath stringByAppendingString:@&quot;package.json&quot;];
+        NSString *fileContents = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
+        JSContext *tempContext = [[JSContext alloc] init];
+        NSString *script = [NSString stringWithFormat:@&quot;JSON.parse(%@)&quot;, fileContents];
+        JSValue *result = [tempContext evaluateScript:script];
+        if (![result[@&quot;main&quot;] isUndefined])
+            return resolveModuleAsFile([result[@&quot;main&quot;] toString]);
+    }
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:[modulePath stringByAppendingPathComponent:@&quot;index.js&quot;]])
+        return [modulePath stringByAppendingPathComponent:@&quot;index.js&quot;];
+    
+    return nil;
+}
+
+static NSArray *nodeModulePaths(NSString *start)
+{
+    NSArray *parts = [start pathComponents];
+    NSUInteger root = [parts indexOfObject:@&quot;node_modules&quot;];
+    if (root == NSNotFound)
+        root = 0;
+    
+    NSUInteger i = [parts count] - 1;
+    NSMutableArray *dirs = [[NSMutableArray alloc] init];
+    while (i &gt; root) {
+        NSString *component = [parts objectAtIndex:i];
+        if ([component isEqualToString:@&quot;node_modules&quot;]) {
+            i -= 1;
+            continue;
+        }
+        [dirs addObject:[NSString pathWithComponents:[parts subarrayWithRange:NSMakeRange(0, i)]]];
+        i -= 1;
+    }
+    
+    return dirs;
+}
+
+static NSString *resolveAsNodeModule(NSString *moduleName, NSString* start)
+{
+    NSArray *dirs = nodeModulePaths(start);
+    for (NSUInteger i = 0; i &lt; [dirs count]; i++) {
+        NSString *dir = [dirs objectAtIndex:i];
+        NSString *result = resolveModuleAsFile([NSString stringWithFormat:@&quot;%@/%@&quot;, dir, moduleName]);
+        if (result)
+            return result;
+        
+        result = resolveModuleAsDirectory([NSString stringWithFormat:@&quot;%@/%@&quot;, dir, moduleName]);
+        if (result)
+            return result;
+    }
+    return nil;
+}
+
++ (NSString *)resolve:(NSString *)module atPath:(NSString *)path
+{
+    if (isCoreModule(module))
+        return coreModuleFullPath(module);
+    
+    NSString *result;
+    if ([module hasPrefix:@&quot;./&quot;] || [module hasPrefix:@&quot;/&quot;] || [module hasPrefix:@&quot;../&quot;]) {
+        result = resolveModuleAsFile([NSString stringWithFormat:@&quot;%@/%@&quot;, path, module]);
+        
+        if (result)
+            return result;
+        
+        result = resolveModuleAsDirectory([NSString stringWithFormat:@&quot;%@/%@&quot;, path, module]);
+        if (result)
+            return result;
+    }
+    
+    return resolveAsNodeModule(module, [path stringByDeletingLastPathComponent]);
+}
+
+static NSMapTable *globalModuleCache()
+{
+    static NSMapTable *moduleCache = nil;
+    if (!moduleCache)
+        moduleCache = [NSMapTable strongToStrongObjectsMapTable];
+    return moduleCache;
+}
+
+static bool isCached(NSString *fullModulePath)
+{
+    return !![globalModuleCache() objectForKey:fullModulePath];
+}
+
+static JSModule *cachedModule(NSString *fullModulePath)
+{
+    assert(isCached(fullModulePath));
+    return [globalModuleCache() objectForKey:fullModulePath];
+}
+
+static void cacheModule(NSString *fullModulePath, JSModule *module)
+{
+    assert(!isCached(fullModulePath));
+    [globalModuleCache() setObject:module forKey:fullModulePath];
+}
+
+static JSModule *currentLoadingModule = nil;
+
++ (JSModule *)require:(NSString *)module atPath:(NSString *)path
+{
+    return [JSModule require:module atPath:path inContext:[JSContext currentContext]];
+}
+
++ (JSModule *)require:(NSString *)module atPath:(NSString *)path inContext:(JSContext *)context
+{
+    assert(context);
+    NSString *fullModulePath = [JSModule resolve:module atPath:path];
+    
+    if (!fullModulePath)
+        return nil;
+    
+    if (isCached(fullModulePath))
+        return cachedModule(fullModulePath);
+    
+    Class moduleClass = classForModule(module);
+    JSModule *newModule = [[moduleClass alloc] initWithId:fullModulePath filename:fullModulePath context:context];
+    cacheModule(fullModulePath, newModule);
+    
+    NSString *script = [NSString stringWithContentsOfFile:fullModulePath encoding:NSUTF8StringEncoding error:nil];
+    
+    [newModule didStartLoading];
+    
+    JSValue *savedExports = context[@&quot;exports&quot;];
+    context[@&quot;exports&quot;] = [newModule exports];
+
+    JSValue *savedModule = context[@&quot;module&quot;];
+    context[@&quot;module&quot;] = newModule;
+    context[@&quot;module&quot;][@&quot;exports&quot;] = [newModule exports];
+    
+    JSValue *savedPlatformObject = context[@&quot;platform&quot;];
+    context[@&quot;platform&quot;] = [newModule platformObjectInContext:context];
+    
+    // Load the module.
+    [context evaluateScript:script];
+    
+    [context.virtualMachine removeManagedReference:newModule-&gt;_exports withOwner:self];
+    newModule-&gt;_exports = [JSManagedValue managedValueWithValue:context[@&quot;module&quot;][@&quot;exports&quot;]];
+    [context.virtualMachine addManagedReference:newModule-&gt;_exports withOwner:self];
+    
+    context[@&quot;platform&quot;] = savedPlatformObject;
+    context[@&quot;module&quot;] = savedModule;
+    context[@&quot;exports&quot;] = savedExports;
+
+    [newModule didFinishLoading];
+
+    return newModule;
+}
+
+- (JSValue *)platformObjectInContext:(JSContext *)context
+{
+    // Override this method in subclasses of JSModule to return a platform object
+    // with whatever functionality required to implement that module.
+    return [JSValue valueWithUndefinedInContext:context];
+}
+
+- (id)initWithId:(NSString *)myId filename:(NSString *)filename context:(JSContext *)context
+{
+    self = [super init];
+    if (!self)
+        return nil;
+    
+    _exports = [JSManagedValue managedValueWithValue:[JSValue valueWithNewObjectInContext:context]];
+    [context.virtualMachine addManagedReference:_exports withOwner:self];
+    _id = myId;
+    _filename = filename;
+    _loaded = false;
+    _parent = nil;
+    _children = [[NSMutableArray alloc] init];
+    
+    return self;
+}
+
+- (void)dealloc
+{
+    JSValue *exports = [_exports value];
+    if (exports)
+        [exports.context.virtualMachine removeManagedReference:_exports withOwner:self];
+}
+
+- (void)didStartLoading
+{
+    _parent = currentLoadingModule;
+    if (currentLoadingModule)
+        [currentLoadingModule-&gt;_children addObject:self];
+    currentLoadingModule = self;
+}
+
+- (void)didFinishLoading
+{
+    _loaded = true;
+    currentLoadingModule = _parent;
+}
+
+- (JSModule *)require:(NSString *)module
+{
+    // TODO
+    return nil;
+}
+
+- (JSValue *)exports
+{
+    return [_exports value];
+}
+
+@end
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkToolsjscclijsccliJSRunLoopThreadh"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/JSRunLoopThread.h (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/JSRunLoopThread.h                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/JSRunLoopThread.h        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,52 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &lt;Foundation/Foundation.h&gt;
+#import &quot;RunLoopThread.h&quot;
+
+#ifndef JSRunLoopThread_h
+#define JSRunLoopThread_h
+
+@class JSContext;
+@class JSValue;
+
+@interface JSRunLoopThread : RunLoopThread
+
++ (ThreadMainType)threadMain;
+
+@property dispatch_queue_t asyncQueue;
+
+- (id)initWithFiles:(NSArray *)files andContext:(JSContext *)context;
+- (void)start;
+- (void)join;
+- (JSValue *)didReceiveInput:(NSString *)input;
+- (void)performCallback:(JSValue *)callback withError:(NSString *)errorMessage;
+- (void)performCallback:(JSValue *)callback withArguments:(NSArray *)arguments;
+- (void)didFinishRunLoopInitialization;
+
+@end
+
+#endif // JSRunLoopThread_h
+
</ins></span></pre></div>
<a id="trunkToolsjscclijsccliJSRunLoopThreadm"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/JSRunLoopThread.m (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/JSRunLoopThread.m                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/JSRunLoopThread.m        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,116 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &lt;JavaScriptCore/JavaScriptCore.h&gt;
+#import &quot;JSRunLoopThread.h&quot;
+#import &quot;ScriptInputSource.h&quot;
+#import &lt;pthread.h&gt;
+
+@implementation JSRunLoopThread {
+    NSArray *m_filesToRun;
+    CFRunLoopRef m_runLoop;
+    ScriptInputSource *m_scriptSource;
+    JSContext *m_context;
+    dispatch_queue_t m_asyncQueue;
+}
+
+static void* jsThreadMain(void* context)
+{
+    JSRunLoopThread *thread = (__bridge JSRunLoopThread *)(context);
+    [thread startRunLoop];
+    return 0;
+}
+
++ (ThreadMainType)threadMain
+{
+    return jsThreadMain;
+}
+
+- (id)initWithFiles:(NSArray *)files andContext:(JSContext *)context
+{
+    self = [super init];
+    if (!self)
+        return nil;
+    
+    m_filesToRun = files;
+    m_context = context;
+    m_scriptSource = [[ScriptInputSource alloc] initWithContext:context];
+    m_asyncQueue = dispatch_queue_create(&quot;node.jsc async queue&quot;, DISPATCH_QUEUE_CONCURRENT);
+    
+    return self;
+}
+
+- (void)startRunLoop
+{
+    m_runLoop = CFRunLoopGetCurrent();
+    [m_scriptSource addToCurrentRunLoop];
+    
+    [self didFinishRunLoopInitialization];
+    
+    CFRunLoopRun();
+}
+
+- (void)start
+{
+    [super start];
+    
+    if (![m_filesToRun count])
+        return;
+    
+    for (NSString *file in m_filesToRun) {
+        NSString *script = [NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil];
+        [m_scriptSource runScriptRemotely:script];
+    }
+}
+
+- (void)join
+{
+    [m_scriptSource removeFromRemoteRunLoop];
+    CFRunLoopStop(m_runLoop);
+    
+    [super join];
+}
+
+- (JSValue *)didReceiveInput:(NSString *)input
+{
+    return [m_scriptSource runScriptRemotely:input];
+}
+
+- (void)performCallback:(JSValue *)callback withError:(NSString *)errorMessage
+{
+}
+
+- (void)performCallback:(JSValue *)callback withArguments:(NSArray *)arguments
+{
+}
+
+- (void)didFinishRunLoopInitialization
+{
+    NSMutableDictionary *threadStorage = [[NSThread currentThread] threadDictionary];
+    [threadStorage setObject:self forKey:@&quot;currentJSThread&quot;];    
+    [super didFinishRunLoopInitialization];
+}
+
+@end
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkToolsjscclijsccliReadEvalPrintLooph"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/ReadEvalPrintLoop.h (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/ReadEvalPrintLoop.h                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/ReadEvalPrintLoop.h        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,42 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &lt;Foundation/Foundation.h&gt;
+
+#ifndef ReadEvalPrintLoop_h
+#define ReadEvalPrintLoop_h
+
+@class JSRunLoopThread;
+
+@interface ReadEvalPrintLoop : NSObject
+
+- (id)initWithJSThread:(JSRunLoopThread *)instance;
+
+- (void)run;
+
+@end
+
+#endif // ReadEvalPrintLoop_h
+
</ins></span></pre></div>
<a id="trunkToolsjscclijsccliReadEvalPrintLoopm"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/ReadEvalPrintLoop.m (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/ReadEvalPrintLoop.m                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/ReadEvalPrintLoop.m        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,105 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;ReadEvalPrintLoop.h&quot;
+
+#import &lt;JavaScriptCore/JavaScriptCore.h&gt;
+#import &lt;histedit.h&gt;
+
+#import &quot;JSRunLoopThread.h&quot;
+
+@implementation ReadEvalPrintLoop {
+    JSRunLoopThread* _jsThread;
+    EditLine* _editLine;
+    History* _history;
+    HistEvent _histEvent;
+}
+
+- (id)initWithJSThread:(JSRunLoopThread *)jsThread
+{
+    self = [super init];
+    if (!self)
+        return nil;
+    
+    _jsThread = jsThread;
+    
+    return self;
+}
+
+static const char* prompt(EditLine* editLine)
+{
+    return &quot;&gt;&gt; &quot;;
+}
+
+static NSString *escapeStringForOutput(NSString *input)
+{
+    return [input stringByReplacingOccurrencesOfString:@&quot;\n&quot; withString:@&quot;\\n&quot;];
+}
+
+- (bool)processNextInput
+{
+    int count;
+    char* line = (char *)el_gets(_editLine, &amp;count);
+    if (!count)
+        return false;
+        
+    line[count - 1] = 0;
+        
+    NSString *inputString = [[NSString alloc] initWithCString:line encoding:NSUTF8StringEncoding];
+        
+    JSValue *result = [_jsThread didReceiveInput:inputString];
+    if ([result isString]) {
+        printf(&quot;=&gt; '%s'\n\n&quot;, [escapeStringForOutput([result toString]) UTF8String]);
+    } else {
+        printf(&quot;=&gt; %s\n\n&quot;, [[result toString] UTF8String]);
+    }
+        
+    if (count)
+        history(_history, &amp;_histEvent, H_ENTER, line);
+    
+    return true;
+}
+
+- (void)run
+{    
+    _editLine = el_init(&quot;node.jsc&quot;, stdin, stdout, stderr);
+    el_set(_editLine, EL_PROMPT, &amp;prompt);
+    
+    _history = history_init();
+    history(_history, &amp;_histEvent, H_SETSIZE, 1000);
+    el_set(_editLine, EL_HIST, history, _history);
+    
+    while (true) {
+        @autoreleasepool {
+            if (![self processNextInput])
+                break;
+        }
+    }
+        
+    history_end(_history);
+    el_end(_editLine);
+}
+
+@end
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkToolsjscclijsccliRunLoopThreadh"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/RunLoopThread.h (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/RunLoopThread.h                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/RunLoopThread.h        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,43 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &lt;Foundation/Foundation.h&gt;
+
+#ifndef RunLoopThread_h
+#define RunLoopThread_h
+
+@interface RunLoopThread : NSObject
+
+typedef void* (*ThreadMainType)(void*);
++ (ThreadMainType)threadMain;
+
+- (void)didFinishRunLoopInitialization;
+- (void)start;
+- (void)join;
+
+@end
+
+#endif // RunLoopThread_h
+
</ins></span></pre></div>
<a id="trunkToolsjscclijsccliRunLoopThreadm"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/RunLoopThread.m (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/RunLoopThread.m                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/RunLoopThread.m        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,85 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;RunLoopThread.h&quot;
+#import &lt;pthread.h&gt;
+
+@implementation RunLoopThread {
+    pthread_t m_thread;
+    pthread_mutex_t m_lock;
+    pthread_cond_t m_condition;
+    bool m_loopInitialized;
+}
+
++ (ThreadMainType)threadMain
+{
+    return 0;
+}
+
+- (id)init
+{
+    self = [super init];
+    if (!self)
+        return nil;
+    
+    m_loopInitialized = false;
+        
+    pthread_mutex_init(&amp;m_lock, NULL);
+    pthread_cond_init(&amp;m_condition, NULL);
+    
+    return self;
+}
+
+- (void)dealloc
+{
+    pthread_mutex_destroy(&amp;m_lock);
+    pthread_cond_destroy(&amp;m_condition);
+}
+
+- (void)didFinishRunLoopInitialization
+{
+    pthread_mutex_lock(&amp;m_lock);
+    m_loopInitialized = true;
+    pthread_cond_signal(&amp;m_condition);
+    pthread_mutex_unlock(&amp;m_lock);
+}
+
+- (void)start
+{
+    pthread_create(&amp;m_thread, NULL, [[self class] threadMain], (__bridge void *)(self));
+    
+    pthread_mutex_lock(&amp;m_lock);
+    while (!m_loopInitialized)
+        pthread_cond_wait(&amp;m_condition, &amp;m_lock);
+    pthread_mutex_unlock(&amp;m_lock);
+}
+
+- (void)join
+{
+    void* result;
+    pthread_join(m_thread, &amp;result);
+}
+
+@end
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkToolsjscclijsccliScriptInputSourceh"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/ScriptInputSource.h (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/ScriptInputSource.h                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/ScriptInputSource.h        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &lt;Foundation/Foundation.h&gt;
+
+#ifndef ScriptInputSource_h
+#define ScriptInputSource_h
+
+@class JSContext;
+@class JSValue;
+
+@interface ScriptInputSource : NSObject
+
+- (id)initWithContext:(JSContext *)context;
+- (void)addToCurrentRunLoop;
+- (void)removeFromRemoteRunLoop;
+- (JSValue *)runScriptRemotely:(NSString *)script;
+- (void)finishAsyncCallback:(JSValue *)callback withResult:(int)result;
+- (void)didReceiveSignal;
+
+@end
+
+#endif // ScriptInputSource_h
+
</ins></span></pre></div>
<a id="trunkToolsjscclijsccliScriptInputSourcem"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/ScriptInputSource.m (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/ScriptInputSource.m                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/ScriptInputSource.m        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,168 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;ScriptInputSource.h&quot;
+
+#import &lt;JavaScriptCore/JavaScriptCore.h&gt;
+#import &lt;pthread.h&gt;
+
+void scriptInputSourceScheduleRoutine (void *info, CFRunLoopRef runLoop, CFStringRef mode)
+{
+}
+
+void scriptInputSourcePerformRoutine (void *info)
+{
+    ScriptInputSource*  source = (__bridge ScriptInputSource *)info;
+    [source didReceiveSignal];
+}
+
+void scriptInputSourceCancelRoutine (void *info, CFRunLoopRef runLoop, CFStringRef mode)
+{
+}
+
+@implementation ScriptInputSource {
+    CFRunLoopSourceRef m_source;
+    CFRunLoopRef m_runLoop;
+    NSMutableArray *m_inputQueue;
+    pthread_mutex_t m_inputLock;
+    
+    NSMutableArray *m_outputQueue;
+    pthread_mutex_t m_outputLock;
+    pthread_cond_t m_outputCondition;
+    
+    JSContext *m_context;
+}
+
+- (id)initWithContext:(JSContext *)context
+{
+    self = [super init];
+    if (!self)
+        return nil;
+    
+    CFRunLoopSourceContext sourceContext = {
+        0,
+        (__bridge void *)(self),
+        NULL, NULL, NULL, NULL, NULL,
+        scriptInputSourceScheduleRoutine,
+        scriptInputSourceCancelRoutine,
+        scriptInputSourcePerformRoutine
+    };
+    m_source = CFRunLoopSourceCreate(NULL, 0, &amp;sourceContext);
+    
+    m_inputQueue = [NSMutableArray array];
+    m_outputQueue = [NSMutableArray array];
+    
+    m_context = context;
+    pthread_mutex_init(&amp;m_inputLock, NULL);
+    pthread_mutex_init(&amp;m_outputLock, NULL);
+    pthread_cond_init(&amp;m_outputCondition, NULL);
+    
+    return self;
+}
+
+- (void)dealloc
+{
+    pthread_mutex_destroy(&amp;m_inputLock);
+    pthread_mutex_destroy(&amp;m_outputLock);
+    pthread_cond_destroy(&amp;m_outputCondition);
+}
+
+- (void)addToCurrentRunLoop
+{
+    m_runLoop = CFRunLoopGetCurrent();
+    CFRunLoopAddSource(m_runLoop, m_source, kCFRunLoopDefaultMode);
+}
+
+- (void)removeFromRemoteRunLoop
+{
+    CFRunLoopRemoveSource(m_runLoop, m_source, kCFRunLoopDefaultMode);
+}
+
+- (void)didReceiveScript:(NSString *)script
+{
+    JSValue *result = [m_context evaluateScript:script];
+    
+    if (m_context.exception) {
+        result = m_context.exception;
+        m_context.exception = nil;
+    }
+    
+    pthread_mutex_lock(&amp;m_outputLock);
+    [m_outputQueue addObject:result];
+    pthread_cond_signal(&amp;m_outputCondition);
+    pthread_mutex_unlock(&amp;m_outputLock);
+}
+
+- (void)didReceiveSignal
+{
+    pthread_mutex_lock(&amp;m_inputLock);
+    while ([m_inputQueue count]) {
+        NSString *nextScript = [m_inputQueue objectAtIndex:0];
+        [m_inputQueue removeObjectAtIndex:0];
+        pthread_mutex_unlock(&amp;m_inputLock);
+        
+        [self didReceiveScript:nextScript];
+        
+        pthread_mutex_lock(&amp;m_inputLock);
+    }
+    pthread_mutex_unlock(&amp;m_inputLock);
+}
+
+- (JSValue *)runScriptRemotely:(NSString *)script
+{
+    pthread_mutex_lock(&amp;m_inputLock);
+    [m_inputQueue addObject:script];
+    pthread_mutex_unlock(&amp;m_inputLock);
+    
+    CFRunLoopSourceSignal(m_source);
+    CFRunLoopWakeUp(m_runLoop);
+    
+    pthread_mutex_lock(&amp;m_outputLock);
+    while (![m_outputQueue count])
+        pthread_cond_wait(&amp;m_outputCondition, &amp;m_outputLock);
+    JSValue *result = [m_outputQueue objectAtIndex:0];
+    [m_outputQueue removeObjectAtIndex:0];
+    pthread_mutex_unlock(&amp;m_outputLock);
+    
+    return result;
+}
+
+- (void)finishAsyncCallback:(JSValue *)callback withResult:(int)result
+{
+    pthread_mutex_lock(&amp;m_inputLock);
+    [m_inputQueue addObject:^{
+        if (result) {
+            [callback callWithArguments:@[]];
+            return;
+        }
+        [callback callWithArguments:@[]];
+    }];
+    pthread_mutex_unlock(&amp;m_inputLock);
+    
+    CFRunLoopSourceSignal(m_source);
+    CFRunLoopWakeUp(m_runLoop);
+}
+
+@end
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkToolsjscclijscclimainm"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli/main.m (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli/main.m                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli/main.m        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,43 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &lt;Foundation/Foundation.h&gt;
+
+#import &quot;CLIInstance.h&quot;
+
+int main(int argc, const char * argv[])
+{
+    @autoreleasepool {
+        CLIInstance *instance = [[CLIInstance alloc] init];
+        
+        // TODO: Add real arguments handling.
+        if (argc &gt; 1)
+            [instance loadFile:[NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding]];
+            
+        [instance run];
+    }
+    return 0;
+}
+
</ins></span></pre></div>
<a id="trunkToolsjscclijscclixcodeprojprojectpbxproj"></a>
<div class="addfile"><h4>Added: trunk/Tools/jsc-cli/jsc-cli.xcodeproj/project.pbxproj (0 => 162612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/jsc-cli/jsc-cli.xcodeproj/project.pbxproj                                (rev 0)
+++ trunk/Tools/jsc-cli/jsc-cli.xcodeproj/project.pbxproj        2014-01-23 17:09:00 UTC (rev 162612)
</span><span class="lines">@@ -0,0 +1,308 @@
</span><ins>+// !$*UTF8*$!
+{
+        archiveVersion = 1;
+        classes = {
+        };
+        objectVersion = 46;
+        objects = {
+
+/* Begin PBXBuildFile section */
+                C246590518902ACE0029092E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C246590418902ACE0029092E /* Foundation.framework */; };
+                C246590818902ACE0029092E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C246590718902ACE0029092E /* main.m */; };
+                C246591418902B910029092E /* CLIInstance.m in Sources */ = {isa = PBXBuildFile; fileRef = C246591318902B910029092E /* CLIInstance.m */; };
+                C246591718902C420029092E /* JSModule.m in Sources */ = {isa = PBXBuildFile; fileRef = C246591618902C420029092E /* JSModule.m */; };
+                C246591A18902CCC0029092E /* JSRunLoopThread.m in Sources */ = {isa = PBXBuildFile; fileRef = C246591918902CCC0029092E /* JSRunLoopThread.m */; };
+                C246591D18902D100029092E /* RunLoopThread.m in Sources */ = {isa = PBXBuildFile; fileRef = C246591C18902D100029092E /* RunLoopThread.m */; };
+                C246592018902E150029092E /* ReadEvalPrintLoop.m in Sources */ = {isa = PBXBuildFile; fileRef = C246591F18902E150029092E /* ReadEvalPrintLoop.m */; };
+                C246592318902EA40029092E /* ScriptInputSource.m in Sources */ = {isa = PBXBuildFile; fileRef = C246592218902EA40029092E /* ScriptInputSource.m */; };
+                C246592C18905FC10029092E /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C246592B18905FC10029092E /* JavaScriptCore.framework */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+                C24658FF18902ACE0029092E /* Copy Files */ = {
+                        isa = PBXCopyFilesBuildPhase;
+                        buildActionMask = 2147483647;
+                        dstPath = /usr/share/man/man1/;
+                        dstSubfolderSpec = 0;
+                        files = (
+                        );
+                        name = &quot;Copy Files&quot;;
+                        runOnlyForDeploymentPostprocessing = 1;
+                };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+                C246590118902ACE0029092E /* jsc-cli */ = {isa = PBXFileReference; explicitFileType = &quot;compiled.mach-o.executable&quot;; includeInIndex = 0; path = &quot;jsc-cli&quot;; sourceTree = BUILT_PRODUCTS_DIR; };
+                C246590418902ACE0029092E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+                C246590718902ACE0029092E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246591218902B910029092E /* CLIInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CLIInstance.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246591318902B910029092E /* CLIInstance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CLIInstance.m; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246591518902C420029092E /* JSModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSModule.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246591618902C420029092E /* JSModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSModule.m; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246591818902CCC0029092E /* JSRunLoopThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRunLoopThread.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246591918902CCC0029092E /* JSRunLoopThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSRunLoopThread.m; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246591B18902D100029092E /* RunLoopThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RunLoopThread.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246591C18902D100029092E /* RunLoopThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RunLoopThread.m; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246591E18902E150029092E /* ReadEvalPrintLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadEvalPrintLoop.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246591F18902E150029092E /* ReadEvalPrintLoop.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReadEvalPrintLoop.m; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246592118902EA40029092E /* ScriptInputSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptInputSource.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246592218902EA40029092E /* ScriptInputSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScriptInputSource.m; sourceTree = &quot;&lt;group&gt;&quot;; };
+                C246592B18905FC10029092E /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = JavaScriptCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+                C24658FE18902ACE0029092E /* Frameworks */ = {
+                        isa = PBXFrameworksBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                C246592C18905FC10029092E /* JavaScriptCore.framework in Frameworks */,
+                                C246590518902ACE0029092E /* Foundation.framework in Frameworks */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+                C24658F818902ACE0029092E = {
+                        isa = PBXGroup;
+                        children = (
+                                C246590618902ACE0029092E /* jsc-cli */,
+                                C246590318902ACE0029092E /* Frameworks */,
+                                C246590218902ACE0029092E /* Products */,
+                        );
+                        sourceTree = &quot;&lt;group&gt;&quot;;
+                };
+                C246590218902ACE0029092E /* Products */ = {
+                        isa = PBXGroup;
+                        children = (
+                                C246590118902ACE0029092E /* jsc-cli */,
+                        );
+                        name = Products;
+                        sourceTree = &quot;&lt;group&gt;&quot;;
+                };
+                C246590318902ACE0029092E /* Frameworks */ = {
+                        isa = PBXGroup;
+                        children = (
+                                C246592B18905FC10029092E /* JavaScriptCore.framework */,
+                                C246590418902ACE0029092E /* Foundation.framework */,
+                        );
+                        name = Frameworks;
+                        sourceTree = &quot;&lt;group&gt;&quot;;
+                };
+                C246590618902ACE0029092E /* jsc-cli */ = {
+                        isa = PBXGroup;
+                        children = (
+                                C246590718902ACE0029092E /* main.m */,
+                                C246591218902B910029092E /* CLIInstance.h */,
+                                C246591318902B910029092E /* CLIInstance.m */,
+                                C246591518902C420029092E /* JSModule.h */,
+                                C246591618902C420029092E /* JSModule.m */,
+                                C246591818902CCC0029092E /* JSRunLoopThread.h */,
+                                C246591918902CCC0029092E /* JSRunLoopThread.m */,
+                                C246591B18902D100029092E /* RunLoopThread.h */,
+                                C246591C18902D100029092E /* RunLoopThread.m */,
+                                C246591E18902E150029092E /* ReadEvalPrintLoop.h */,
+                                C246591F18902E150029092E /* ReadEvalPrintLoop.m */,
+                                C246592118902EA40029092E /* ScriptInputSource.h */,
+                                C246592218902EA40029092E /* ScriptInputSource.m */,
+                        );
+                        path = &quot;jsc-cli&quot;;
+                        sourceTree = &quot;&lt;group&gt;&quot;;
+                };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+                C246590018902ACE0029092E /* jsc-cli */ = {
+                        isa = PBXNativeTarget;
+                        buildConfigurationList = C246590F18902ACE0029092E /* Build configuration list for PBXNativeTarget &quot;jsc-cli&quot; */;
+                        buildPhases = (
+                                C24658FD18902ACE0029092E /* Sources */,
+                                C24658FE18902ACE0029092E /* Frameworks */,
+                                C24658FF18902ACE0029092E /* Copy Files */,
+                        );
+                        buildRules = (
+                        );
+                        dependencies = (
+                        );
+                        name = &quot;jsc-cli&quot;;
+                        productName = &quot;jsc-cli&quot;;
+                        productReference = C246590118902ACE0029092E /* jsc-cli */;
+                        productType = &quot;com.apple.product-type.tool&quot;;
+                };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+                C24658F918902ACE0029092E /* Project object */ = {
+                        isa = PBXProject;
+                        attributes = {
+                                LastUpgradeCheck = 0500;
+                                ORGANIZATIONNAME = &quot;Mark Hahnenberg&quot;;
+                        };
+                        buildConfigurationList = C24658FC18902ACE0029092E /* Build configuration list for PBXProject &quot;jsc-cli&quot; */;
+                        compatibilityVersion = &quot;Xcode 3.2&quot;;
+                        developmentRegion = English;
+                        hasScannedForEncodings = 0;
+                        knownRegions = (
+                                en,
+                        );
+                        mainGroup = C24658F818902ACE0029092E;
+                        productRefGroup = C246590218902ACE0029092E /* Products */;
+                        projectDirPath = &quot;&quot;;
+                        projectRoot = &quot;&quot;;
+                        targets = (
+                                C246590018902ACE0029092E /* jsc-cli */,
+                        );
+                };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+                C24658FD18902ACE0029092E /* Sources */ = {
+                        isa = PBXSourcesBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                                C246591A18902CCC0029092E /* JSRunLoopThread.m in Sources */,
+                                C246592018902E150029092E /* ReadEvalPrintLoop.m in Sources */,
+                                C246592318902EA40029092E /* ScriptInputSource.m in Sources */,
+                                C246590818902ACE0029092E /* main.m in Sources */,
+                                C246591418902B910029092E /* CLIInstance.m in Sources */,
+                                C246591D18902D100029092E /* RunLoopThread.m in Sources */,
+                                C246591718902C420029092E /* JSModule.m in Sources */,
+                        );
+                        runOnlyForDeploymentPostprocessing = 0;
+                };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+                C246590D18902ACE0029092E /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ALWAYS_SEARCH_USER_PATHS = NO;
+                                CLANG_CXX_LANGUAGE_STANDARD = &quot;gnu++0x&quot;;
+                                CLANG_CXX_LIBRARY = &quot;libc++&quot;;
+                                CLANG_ENABLE_OBJC_ARC = YES;
+                                CLANG_WARN_BOOL_CONVERSION = YES;
+                                CLANG_WARN_CONSTANT_CONVERSION = YES;
+                                CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+                                CLANG_WARN_EMPTY_BODY = YES;
+                                CLANG_WARN_ENUM_CONVERSION = YES;
+                                CLANG_WARN_INT_CONVERSION = YES;
+                                CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+                                CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+                                COPY_PHASE_STRIP = NO;
+                                GCC_C_LANGUAGE_STANDARD = gnu99;
+                                GCC_DYNAMIC_NO_PIC = NO;
+                                GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+                                GCC_OPTIMIZATION_LEVEL = 0;
+                                GCC_PREPROCESSOR_DEFINITIONS = (
+                                        &quot;DEBUG=1&quot;,
+                                        &quot;$(inherited)&quot;,
+                                );
+                                GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+                                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                                GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+                                GCC_WARN_UNDECLARED_SELECTOR = YES;
+                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
+                                GCC_WARN_UNUSED_FUNCTION = YES;
+                                GCC_WARN_UNUSED_VARIABLE = YES;
+                                MACOSX_DEPLOYMENT_TARGET = 10.9;
+                                ONLY_ACTIVE_ARCH = YES;
+                                SDKROOT = macosx;
+                        };
+                        name = Debug;
+                };
+                C246590E18902ACE0029092E /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ALWAYS_SEARCH_USER_PATHS = NO;
+                                CLANG_CXX_LANGUAGE_STANDARD = &quot;gnu++0x&quot;;
+                                CLANG_CXX_LIBRARY = &quot;libc++&quot;;
+                                CLANG_ENABLE_OBJC_ARC = YES;
+                                CLANG_WARN_BOOL_CONVERSION = YES;
+                                CLANG_WARN_CONSTANT_CONVERSION = YES;
+                                CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+                                CLANG_WARN_EMPTY_BODY = YES;
+                                CLANG_WARN_ENUM_CONVERSION = YES;
+                                CLANG_WARN_INT_CONVERSION = YES;
+                                CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+                                CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+                                COPY_PHASE_STRIP = YES;
+                                DEBUG_INFORMATION_FORMAT = &quot;dwarf-with-dsym&quot;;
+                                ENABLE_NS_ASSERTIONS = NO;
+                                GCC_C_LANGUAGE_STANDARD = gnu99;
+                                GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+                                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                                GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+                                GCC_WARN_UNDECLARED_SELECTOR = YES;
+                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
+                                GCC_WARN_UNUSED_FUNCTION = YES;
+                                GCC_WARN_UNUSED_VARIABLE = YES;
+                                MACOSX_DEPLOYMENT_TARGET = 10.9;
+                                SDKROOT = macosx;
+                        };
+                        name = Release;
+                };
+                C246591018902ACE0029092E /* Debug */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ALWAYS_SEARCH_USER_PATHS = YES;
+                                DEBUG_INFORMATION_FORMAT = &quot;dwarf-with-dsym&quot;;
+                                FRAMEWORK_SEARCH_PATHS = &quot;$(inherited)&quot;;
+                                GCC_PRECOMPILE_PREFIX_HEADER = YES;
+                                GCC_PREFIX_HEADER = &quot;&quot;;
+                                LD_RUNPATH_SEARCH_PATHS = &quot;\&quot;@loader_path/.\&quot;&quot;;
+                                LINKER_DISPLAYS_MANGLED_NAMES = YES;
+                                OTHER_CFLAGS = (
+                                        &quot;-iframework&quot;,
+                                        &quot;$(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/&quot;,
+                                );
+                                OTHER_LDFLAGS = &quot;-ledit&quot;;
+                                PRODUCT_NAME = &quot;$(TARGET_NAME)&quot;;
+                                SDKROOT = macosx.internal;
+                        };
+                        name = Debug;
+                };
+                C246591118902ACE0029092E /* Release */ = {
+                        isa = XCBuildConfiguration;
+                        buildSettings = {
+                                ALWAYS_SEARCH_USER_PATHS = YES;
+                                DEBUG_INFORMATION_FORMAT = &quot;dwarf-with-dsym&quot;;
+                                FRAMEWORK_SEARCH_PATHS = &quot;$(inherited)&quot;;
+                                GCC_PRECOMPILE_PREFIX_HEADER = YES;
+                                GCC_PREFIX_HEADER = &quot;&quot;;
+                                LD_RUNPATH_SEARCH_PATHS = &quot;\&quot;@loader_path/.\&quot;&quot;;
+                                LINKER_DISPLAYS_MANGLED_NAMES = YES;
+                                OTHER_CFLAGS = (
+                                        &quot;-iframework&quot;,
+                                        &quot;$(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/&quot;,
+                                );
+                                OTHER_LDFLAGS = &quot;-ledit&quot;;
+                                PRODUCT_NAME = &quot;$(TARGET_NAME)&quot;;
+                                SDKROOT = macosx.internal;
+                        };
+                        name = Release;
+                };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+                C24658FC18902ACE0029092E /* Build configuration list for PBXProject &quot;jsc-cli&quot; */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                C246590D18902ACE0029092E /* Debug */,
+                                C246590E18902ACE0029092E /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+                C246590F18902ACE0029092E /* Build configuration list for PBXNativeTarget &quot;jsc-cli&quot; */ = {
+                        isa = XCConfigurationList;
+                        buildConfigurations = (
+                                C246591018902ACE0029092E /* Debug */,
+                                C246591118902ACE0029092E /* Release */,
+                        );
+                        defaultConfigurationIsVisible = 0;
+                        defaultConfigurationName = Release;
+                };
+/* End XCConfigurationList section */
+        };
+        rootObject = C24658F918902ACE0029092E /* Project object */;
+}
</ins></span></pre>
</div>
</div>

</body>
</html>