Basic framework for a modern jsc CLI
authormhahnenberg@apple.com <mhahnenberg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jan 2014 17:09:00 +0000 (17:09 +0000)
committermhahnenberg@apple.com <mhahnenberg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jan 2014 17:09:00 +0000 (17:09 +0000)
commite9b8c1e989469ba8248fbf4e61f7cc3d4dc0e41f
tree49d65daca9def737f4a6f17ea41c2fde830aba4a
parenta52a13a81f1f964b4a34e1354c45596cd50331c2
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 "privileged"
  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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@162612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
16 files changed:
Tools/ChangeLog
Tools/Scripts/build-jsc
Tools/jsc-cli/jsc-cli.xcodeproj/project.pbxproj [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/CLIInstance.h [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/CLIInstance.m [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/JSModule.h [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/JSModule.m [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/JSRunLoopThread.h [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/JSRunLoopThread.m [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/ReadEvalPrintLoop.h [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/ReadEvalPrintLoop.m [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/RunLoopThread.h [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/RunLoopThread.m [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/ScriptInputSource.h [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/ScriptInputSource.m [new file with mode: 0644]
Tools/jsc-cli/jsc-cli/main.m [new file with mode: 0644]