Changeset 159934 in webkit


Ignore:
Timestamp:
Dec 2, 2013 8:38:58 AM (10 years ago)
Author:
commit-queue@webkit.org
Message:

jsc: implement a native readFile function
https://bugs.webkit.org/show_bug.cgi?id=125059

Patch by Brian J. Burg <Brian Burg> on 2013-12-02
Reviewed by Filip Pizlo.

This adds a native readFile() function to jsc, used to slurp
an entire file into a JavaScript string.

  • jsc.cpp:

(GlobalObject::finishCreation): Add readFile() to globals.
(functionReadFile): Added.

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r159933 r159934  
     12013-12-02  Brian J. Burg  <burg@cs.washington.edu>
     2
     3        jsc: implement a native readFile function
     4        https://bugs.webkit.org/show_bug.cgi?id=125059
     5
     6        Reviewed by Filip Pizlo.
     7
     8        This adds a native readFile() function to jsc, used to slurp
     9        an entire file into a JavaScript string.
     10
     11        * jsc.cpp:
     12        (GlobalObject::finishCreation): Add readFile() to globals.
     13        (functionReadFile): Added.
     14
    1152013-12-02  László Langó  <lango@inf.u-szeged.hu>
    216
  • trunk/Source/JavaScriptCore/jsc.cpp

    r159064 r159934  
    109109static EncodedJSValue JSC_HOST_CALL functionRun(ExecState*);
    110110static EncodedJSValue JSC_HOST_CALL functionLoad(ExecState*);
     111static EncodedJSValue JSC_HOST_CALL functionReadFile(ExecState*);
    111112static EncodedJSValue JSC_HOST_CALL functionCheckSyntax(ExecState*);
    112113static EncodedJSValue JSC_HOST_CALL functionReadline(ExecState*);
     
    227228        addFunction(vm, "run", functionRun, 1);
    228229        addFunction(vm, "load", functionLoad, 1);
     230        addFunction(vm, "readFile", functionReadFile, 1);
    229231        addFunction(vm, "checkSyntax", functionCheckSyntax, 1);
    230232        addFunction(vm, "jscStack", functionJSCStack, 1);
     
    420422        exec->vm().throwException(exec, evaluationException);
    421423    return JSValue::encode(result);
     424}
     425
     426EncodedJSValue JSC_HOST_CALL functionReadFile(ExecState* exec)
     427{
     428    String fileName = exec->argument(0).toString(exec)->value(exec);
     429    Vector<char> script;
     430    if (!fillBufferWithContentsOfFile(fileName, script))
     431        return JSValue::encode(exec->vm().throwException(exec, createError(exec, "Could not open file.")));
     432
     433    return JSValue::encode(jsString(exec, stringFromUTF(script.data())));
    422434}
    423435
Note: See TracChangeset for help on using the changeset viewer.