Bug 1504463 - Implement JS::CompileUtf8DontDeflate that accepts const char*/size_t and compiles it as UTF-8 of uncertain validity without first inflating to UTF-16. r=arai
authorJeff Walden <jwalden@mit.edu>
Mon, 05 Nov 2018 18:55:55 -0800
changeset 502958 642babeab993dd1729a27cb2c29237738001e737
parent 502957 528ff344571beb8d01175198b0db64b68ca4a948
child 502959 720a8da29394634661a0049777f0fcbcf666421c
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1504463
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1504463 - Implement JS::CompileUtf8DontDeflate that accepts const char*/size_t and compiles it as UTF-8 of uncertain validity without first inflating to UTF-16. r=arai
js/public/CompilationAndEvaluation.h
js/src/vm/CompilationAndEvaluation.cpp
--- a/js/public/CompilationAndEvaluation.h
+++ b/js/public/CompilationAndEvaluation.h
@@ -162,16 +162,30 @@ Compile(JSContext* cx, const ReadOnlyCom
  *
  * |script| is always set to the compiled script or to null in case of error.
  */
 extern JS_PUBLIC_API(bool)
 CompileUtf8(JSContext* cx, const ReadOnlyCompileOptions& options,
             const char* bytes, size_t length, MutableHandle<JSScript*> script);
 
 /**
+ * Compile the provided UTF-8 data into a script.  If the data contains invalid
+ * UTF-8, an error is reported.
+ *
+ * |script| is always set to the compiled script or to null in case of error.
+ *
+ * NOTE: This function DOES NOT INFLATE the UTF-8 bytes to UTF-16 before
+ *       compiling them.  UTF-8 compilation is currently experimental and has
+ *       known bugs.  Use only if you're willing to tolerate unspecified bugs!
+ */
+extern JS_PUBLIC_API(bool)
+CompileUtf8DontInflate(JSContext* cx, const ReadOnlyCompileOptions& options,
+                       const char* bytes, size_t length, MutableHandle<JSScript*> script);
+
+/**
  * Compile the provided Latin-1 data (i.e. each byte directly corresponds to
  * the same Unicode code point) into a script.
  *
  * This function may eventually be removed, such that *only* bytes containing
  * UTF-8 source text may be directly compiled.  Avoid using it if you can.
  *
  * |script| is always set to the compiled script or to null in case of error.
  */
--- a/js/src/vm/CompilationAndEvaluation.cpp
+++ b/js/src/vm/CompilationAndEvaluation.cpp
@@ -135,16 +135,23 @@ JS::CompileLatin1(JSContext* cx, const R
 bool
 JS::CompileUtf8(JSContext* cx, const ReadOnlyCompileOptions& options,
                 const char* bytes, size_t length, JS::MutableHandleScript script)
 {
     return ::CompileUtf8(cx, options, bytes, length, script);
 }
 
 bool
+JS::CompileUtf8DontInflate(JSContext* cx, const ReadOnlyCompileOptions& options,
+                           const char* bytes, size_t length, JS::MutableHandleScript script)
+{
+    return ::CompileUtf8DontInflate(cx, options, bytes, length, script);
+}
+
+bool
 JS::CompileUtf8File(JSContext* cx, const ReadOnlyCompileOptions& options,
                     FILE* file, JS::MutableHandleScript script)
 {
     FileContents buffer(cx);
     if (!ReadCompleteFile(cx, file, buffer)) {
         return false;
     }