Bug 1520878 - Process '-e foo' arguments to the JS shell as UTF-8, not Latin-1, in order to remove JS::EvaluateLatin1, the last public Latin-1-consuming compilation API in SpiderMonkey. r=jandem
authorJeff Walden <jwalden@mit.edu>
Mon, 14 Jan 2019 23:01:14 -0500
changeset 515384 b120777f7b7dae54e15b87a860323490e9f92a96
parent 515383 0f49f3cc157d5e51e93f2efe602b91147cdd6e87
child 515385 042dff78509e5facd5d889805bb8d928a18df21a
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1520878
milestone66.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 1520878 - Process '-e foo' arguments to the JS shell as UTF-8, not Latin-1, in order to remove JS::EvaluateLatin1, the last public Latin-1-consuming compilation API in SpiderMonkey. r=jandem
js/public/CompilationAndEvaluation.h
js/src/shell/js.cpp
js/src/vm/CompilationAndEvaluation.cpp
--- a/js/public/CompilationAndEvaluation.h
+++ b/js/public/CompilationAndEvaluation.h
@@ -136,29 +136,16 @@ extern JS_PUBLIC_API bool Evaluate(JSCon
  * UTF-8, an error is reported.
  */
 extern JS_PUBLIC_API bool EvaluateUtf8(JSContext* cx,
                                        const ReadOnlyCompileOptions& options,
                                        const char* bytes, size_t length,
                                        MutableHandle<Value> rval);
 
 /**
- * Evaluate the provided Latin-1 data (i.e. each byte directly corresponds to
- * the same Unicode code point) in the scope of the current global of |cx|, and
- * return the completion value in |rval|.
- *
- * 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.
- */
-extern JS_PUBLIC_API bool EvaluateLatin1(JSContext* cx,
-                                         const ReadOnlyCompileOptions& options,
-                                         const char* bytes, size_t length,
-                                         MutableHandle<Value> rval);
-
-/**
  * Evaluate the UTF-8 contents of the file at the given path, and return the
  * completion value in |rval|.  (The path itself is in the system encoding, not
  * [necessarily] UTF-8.)  If the contents contain any malformed UTF-8, an error
  * is reported.
  */
 extern JS_PUBLIC_API bool EvaluateUtf8Path(
     JSContext* cx, const ReadOnlyCompileOptions& options, const char* filename,
     MutableHandle<Value> rval);
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -9958,20 +9958,18 @@ static MOZ_MUST_USE bool ProcessArgs(JSC
 
     if (ccArgno < fpArgno && ccArgno < ufpArgno && ccArgno < mpArgno &&
         ccArgno < baArgno) {
       const char* code = codeChunks.front();
 
       JS::CompileOptions opts(cx);
       opts.setFileAndLine("-e", 1);
 
-      // This might be upgradable to UTF-8, but for now keep assuming the
-      // worst.
       RootedValue rval(cx);
-      if (!JS::EvaluateLatin1(cx, opts, code, strlen(code), &rval)) {
+      if (!JS::EvaluateUtf8(cx, opts, code, strlen(code), &rval)) {
         return false;
       }
 
       codeChunks.popFront();
       if (sc->quitting) {
         break;
       }
 
--- a/js/src/vm/CompilationAndEvaluation.cpp
+++ b/js/src/vm/CompilationAndEvaluation.cpp
@@ -569,34 +569,16 @@ extern JS_PUBLIC_API bool JS::EvaluateUt
     return false;
   }
 
   RootedObject globalLexical(cx, &cx->global()->lexicalEnvironment());
   return ::Evaluate(cx, ScopeKind::Global, globalLexical, options, srcBuf,
                     rval);
 }
 
-extern JS_PUBLIC_API bool JS::EvaluateLatin1(
-    JSContext* cx, const ReadOnlyCompileOptions& options, const char* bytes,
-    size_t length, MutableHandle<Value> rval) {
-  auto chars = UniqueTwoByteChars(InflateString(cx, bytes, length));
-  if (!chars) {
-    return false;
-  }
-
-  SourceText<char16_t> srcBuf;
-  if (!srcBuf.init(cx, std::move(chars), length)) {
-    return false;
-  }
-
-  RootedObject globalLexical(cx, &cx->global()->lexicalEnvironment());
-  return ::Evaluate(cx, ScopeKind::Global, globalLexical, options, srcBuf,
-                    rval);
-}
-
 JS_PUBLIC_API bool JS::Evaluate(JSContext* cx,
                                 const ReadOnlyCompileOptions& optionsArg,
                                 SourceText<char16_t>& srcBuf,
                                 MutableHandleValue rval) {
   RootedObject globalLexical(cx, &cx->global()->lexicalEnvironment());
   return ::Evaluate(cx, ScopeKind::Global, globalLexical, optionsArg, srcBuf,
                     rval);
 }