Title: [159934] trunk/Source/_javascript_Core
Revision
159934
Author
[email protected]
Date
2013-12-02 08:38:58 -0800 (Mon, 02 Dec 2013)

Log Message

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

Patch by Brian J. Burg <[email protected]> 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.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (159933 => 159934)


--- trunk/Source/_javascript_Core/ChangeLog	2013-12-02 15:36:06 UTC (rev 159933)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-12-02 16:38:58 UTC (rev 159934)
@@ -1,3 +1,17 @@
+2013-12-02  Brian J. Burg  <[email protected]>
+
+        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ó  <[email protected]>
 
         JSC does not build if OPCODE_STATS is enabled.

Modified: trunk/Source/_javascript_Core/jsc.cpp (159933 => 159934)


--- trunk/Source/_javascript_Core/jsc.cpp	2013-12-02 15:36:06 UTC (rev 159933)
+++ trunk/Source/_javascript_Core/jsc.cpp	2013-12-02 16:38:58 UTC (rev 159934)
@@ -108,6 +108,7 @@
 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 @@
         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 @@
     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);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to