Commit 0e854124 authored by weinig@apple.com's avatar weinig@apple.com

Reviewed by Mark Rowe.

        http://bugs.webkit.org/show_bug.cgi?id=17529
        Add support for reading from stdin from testkjs

        * kjs/testkjs.cpp:
        (GlobalObject::GlobalObject): Add readline function to global object.
        (functionReadline): Added. Reads characters from stdin until a '\n' or
        EOF is encountered. The input is returned as a String to the caller.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@30560 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5383def0
2008-02-24 Sam Weinig <sam@webkit.org>
Reviewed by Mark Rowe.
http://bugs.webkit.org/show_bug.cgi?id=17529
Add support for reading from stdin from testkjs
* kjs/testkjs.cpp:
(GlobalObject::GlobalObject): Add readline function to global object.
(functionReadline): Added. Reads characters from stdin until a '\n' or
EOF is encountered. The input is returned as a String to the caller.
2008-02-24 Sam Weinig <sam@webkit.org>
Reviewed by Mark Rowe.
......
......@@ -62,6 +62,7 @@ static JSValue* functionGC(ExecState*, JSObject*, const List&);
static JSValue* functionVersion(ExecState*, JSObject*, const List&);
static JSValue* functionRun(ExecState*, JSObject*, const List&);
static JSValue* functionLoad(ExecState*, JSObject*, const List&);
static JSValue* functionReadline(ExecState*, JSObject*, const List&);
static JSValue* functionQuit(ExecState*, JSObject*, const List&);
class StopWatch {
......@@ -136,6 +137,7 @@ GlobalObject::GlobalObject(Vector<UString>& arguments)
putDirectFunction(new PrototypeFunction(globalExec(), functionPrototype(), 1, "version", functionVersion));
putDirectFunction(new PrototypeFunction(globalExec(), functionPrototype(), 1, "run", functionRun));
putDirectFunction(new PrototypeFunction(globalExec(), functionPrototype(), 1, "load", functionLoad));
putDirectFunction(new PrototypeFunction(globalExec(), functionPrototype(), 0, "readline", functionReadline));
JSObject* array = arrayConstructor()->construct(globalExec(), globalExec()->emptyList());
for (size_t i = 0; i < arguments.size(); ++i)
......@@ -198,6 +200,20 @@ JSValue* functionLoad(ExecState* exec, JSObject*, const List& args)
return jsUndefined();
}
JSValue* functionReadline(ExecState*, JSObject*, const List&)
{
Vector<char, 256> line;
int c;
while ((c = getchar()) != EOF) {
// FIXME: Should we also break on \r?
if (c == '\n')
break;
line.append(c);
}
line.append('\0');
return jsString(line.data());
}
JSValue* functionQuit(ExecState*, JSObject*, const List&)
{
exit(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment