jsc: implement a native readFile function

https://bugs.webkit.org/show_bug.cgi?id=125059

Patch by Brian J. Burg <burg@cs.washington.edu> 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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159934 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2f00452d
2013-12-02 Brian J. Burg <burg@cs.washington.edu>
jsc: implement a native readFile function
https://bugs.webkit.org/show_bug.cgi?id=125059
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.
2013-12-02 László Langó <lango@inf.u-szeged.hu>
JSC does not build if OPCODE_STATS is enabled.
......
......@@ -108,6 +108,7 @@ static EncodedJSValue JSC_HOST_CALL functionDumpCallFrame(ExecState*);
static EncodedJSValue JSC_HOST_CALL functionVersion(ExecState*);
static EncodedJSValue JSC_HOST_CALL functionRun(ExecState*);
static EncodedJSValue JSC_HOST_CALL functionLoad(ExecState*);
static EncodedJSValue JSC_HOST_CALL functionReadFile(ExecState*);
static EncodedJSValue JSC_HOST_CALL functionCheckSyntax(ExecState*);
static EncodedJSValue JSC_HOST_CALL functionReadline(ExecState*);
static EncodedJSValue JSC_HOST_CALL functionPreciseTime(ExecState*);
......@@ -226,6 +227,7 @@ protected:
addFunction(vm, "version", functionVersion, 1);
addFunction(vm, "run", functionRun, 1);
addFunction(vm, "load", functionLoad, 1);
addFunction(vm, "readFile", functionReadFile, 1);
addFunction(vm, "checkSyntax", functionCheckSyntax, 1);
addFunction(vm, "jscStack", functionJSCStack, 1);
addFunction(vm, "readline", functionReadline, 0);
......@@ -421,6 +423,16 @@ EncodedJSValue JSC_HOST_CALL functionLoad(ExecState* exec)
return JSValue::encode(result);
}
EncodedJSValue JSC_HOST_CALL functionReadFile(ExecState* exec)
{
String fileName = exec->argument(0).toString(exec)->value(exec);
Vector<char> script;
if (!fillBufferWithContentsOfFile(fileName, script))
return JSValue::encode(exec->vm().throwException(exec, createError(exec, "Could not open file.")));
return JSValue::encode(jsString(exec, stringFromUTF(script.data())));
}
EncodedJSValue JSC_HOST_CALL functionCheckSyntax(ExecState* exec)
{
String fileName = exec->argument(0).toString(exec)->value(exec);
......
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