Bug 1504893 - Implement JS::CompileDontInflate that takes JS::SourceText<Utf8Unit>& paralleling JS::Compile that takes JS::SourceText<char16_t>&. r=arai
authorJeff Walden <jwalden@mit.edu>
Mon, 05 Nov 2018 18:55:56 -0800
changeset 503832 0252a8bad879a65be1fa7e69f287090a8782eaac
parent 503831 1ba4426e7a591d0d8712dc21f8875bcdbe9b3b76
child 503833 97dadee2ab7c78513e929407ee6460b5fb6345fe
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
bugs1504893
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 1504893 - Implement JS::CompileDontInflate that takes JS::SourceText<Utf8Unit>& paralleling JS::Compile that takes JS::SourceText<char16_t>&. r=arai
js/public/CompilationAndEvaluation.h
js/src/vm/CompilationAndEvaluation.cpp
--- a/js/public/CompilationAndEvaluation.h
+++ b/js/public/CompilationAndEvaluation.h
@@ -3,16 +3,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Functions for compiling and evaluating scripts. */
 
 #ifndef js_CompilationAndEvaluation_h
 #define js_CompilationAndEvaluation_h
 
+#include "mozilla/Utf8.h" // mozilla::Utf8Unit
+
 #include <stddef.h> // size_t
 #include <stdio.h> // FILE
 
 #include "jstypes.h" // JS_PUBLIC_API
 
 #include "js/CompileOptions.h" // JS::CompileOptions, JS::ReadOnlyCompileOptions
 #include "js/RootingAPI.h" // JS::Handle, JS::MutableHandle
 #include "js/Value.h" // JS::Value and specializations of JS::*Handle-related types
@@ -152,16 +154,32 @@ EvaluateUtf8Path(JSContext* cx, const Re
 /**
  * |script| will always be set. On failure, it will be set to nullptr.
  */
 extern JS_PUBLIC_API bool
 Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
         SourceText<char16_t>& srcBuf, MutableHandle<JSScript*> script);
 
 /**
+ * Identical to |JS::Compile|, but compiles UTF-8.
+ *
+ * The "DontInflate" suffix is temporary while bugs in UTF-8 compilation are
+ * ironed out.  In the long term this function and |JS::Compile| will follow
+ * the same naming scheme.
+ *
+ * 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
+CompileDontInflate(JSContext* cx, const ReadOnlyCompileOptions& options,
+                   SourceText<mozilla::Utf8Unit>& srcBuf,
+                   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.
  */
 extern JS_PUBLIC_API bool
 CompileUtf8(JSContext* cx, const ReadOnlyCompileOptions& options,
             const char* bytes, size_t length, MutableHandle<JSScript*> script);
--- a/js/src/vm/CompilationAndEvaluation.cpp
+++ b/js/src/vm/CompilationAndEvaluation.cpp
@@ -121,16 +121,23 @@ CompileUtf8DontInflate(JSContext* cx, co
 bool
 JS::Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
             SourceText<char16_t>& srcBuf, JS::MutableHandleScript script)
 {
     return CompileSourceBuffer(cx, options, srcBuf, script);
 }
 
 bool
+JS::CompileDontInflate(JSContext* cx, const ReadOnlyCompileOptions& options,
+                       SourceText<Utf8Unit>& srcBuf, JS::MutableHandleScript script)
+{
+    return CompileSourceBuffer(cx, options, srcBuf, script);
+}
+
+bool
 JS::CompileLatin1(JSContext* cx, const ReadOnlyCompileOptions& options,
                   const char* bytes, size_t length, JS::MutableHandleScript script)
 {
     return ::CompileLatin1(cx, options, bytes, length, script);
 }
 
 bool
 JS::CompileUtf8(JSContext* cx, const ReadOnlyCompileOptions& options,