Changeset 30560 in webkit


Ignore:
Timestamp:
Feb 24, 2008 11:11:40 PM (16 years ago)
Author:
weinig@apple.com
Message:

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.
Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r30555 r30560  
     12008-02-24  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Mark Rowe.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=17529
     6        Add support for reading from stdin from testkjs
     7
     8        * kjs/testkjs.cpp:
     9        (GlobalObject::GlobalObject): Add readline function to global object.
     10        (functionReadline): Added. Reads characters from stdin until a '\n' or
     11        EOF is encountered. The input is returned as a String to the caller.
     12
    1132008-02-24  Sam Weinig  <sam@webkit.org>
    214
  • trunk/JavaScriptCore/kjs/testkjs.cpp

    r30555 r30560  
    6363static JSValue* functionRun(ExecState*, JSObject*, const List&);
    6464static JSValue* functionLoad(ExecState*, JSObject*, const List&);
     65static JSValue* functionReadline(ExecState*, JSObject*, const List&);
    6566static JSValue* functionQuit(ExecState*, JSObject*, const List&);
    6667
     
    137138    putDirectFunction(new PrototypeFunction(globalExec(), functionPrototype(), 1, "run", functionRun));
    138139    putDirectFunction(new PrototypeFunction(globalExec(), functionPrototype(), 1, "load", functionLoad));
     140    putDirectFunction(new PrototypeFunction(globalExec(), functionPrototype(), 0, "readline", functionReadline));
    139141
    140142    JSObject* array = arrayConstructor()->construct(globalExec(), globalExec()->emptyList());
     
    197199
    198200    return jsUndefined();
     201}
     202
     203JSValue* functionReadline(ExecState*, JSObject*, const List&)
     204{
     205    Vector<char, 256> line;
     206    int c;
     207    while ((c = getchar()) != EOF) {
     208        // FIXME: Should we also break on \r?
     209        if (c == '\n')
     210            break;
     211        line.append(c);
     212    }
     213    line.append('\0');
     214    return jsString(line.data());
    199215}
    200216
Note: See TracChangeset for help on using the changeset viewer.