Bug 1549758 - Revert column-number counts to counts of code units for release-or-beta, pending perf considerations in column-number counting being fixed. r=tcampbell
authorJeff Walden <jwalden@mit.edu>
Fri, 10 May 2019 21:32:31 +0000
changeset 532297 2ae93b4399fbeb63cb3ba4884e569b56baff1916
parent 532296 5972961441c097e5b59dd9348715d31b459226c7
child 532298 9cd89ffdb9337a72ef1cab251e298596b7da96b4
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1549758
milestone68.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 1549758 - Revert column-number counts to counts of code units for release-or-beta, pending perf considerations in column-number counting being fixed. r=tcampbell Differential Revision: https://phabricator.services.mozilla.com/D30717
js/public/CompilationAndEvaluation.h
js/src/frontend/TokenStream.h
js/src/vm/CompilationAndEvaluation.cpp
--- a/js/public/CompilationAndEvaluation.h
+++ b/js/public/CompilationAndEvaluation.h
@@ -133,16 +133,34 @@ extern JS_PUBLIC_API bool Evaluate(JSCon
  * UTF-8, an error is reported.
  */
 extern JS_PUBLIC_API bool Evaluate(JSContext* cx,
                                    const ReadOnlyCompileOptions& options,
                                    SourceText<mozilla::Utf8Unit>& srcBuf,
                                    MutableHandle<Value> rval);
 
 /**
+ * Evaluate the provided UTF-8 data in the scope of the current global of |cx|,
+ * and return the completion value in |rval|.  If the data contains invalid
+ * UTF-8, an error is reported.
+ *
+ * The "DontInflate" suffix and (semantically unobservable) don't-inflate
+ * characteristic are temporary while bugs in UTF-8 compilation are ironed out.
+ * In the long term |JS::Evaluate| for UTF-8 will just never inflate, and this
+ * separate function will die.
+ *
+ * NOTE: UTF-8 compilation is currently experimental, and it's possible it has
+ *       as-yet-undiscovered bugs that the UTF-16 compilation functions do not
+ *       have.  Use only if you're willing to take a risk!
+ */
+extern JS_PUBLIC_API bool EvaluateDontInflate(
+    JSContext* cx, const ReadOnlyCompileOptions& options,
+    SourceText<mozilla::Utf8Unit>& srcBuf, 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/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -1816,17 +1816,17 @@ class TokenStart {
 
   uint32_t offset() const { return startOffset_; }
 };
 
 // Column numbers *ought* be in terms of counts of code points, but in the past
 // we counted code units.  Set this to 0 to keep returning counts of code units
 // (even for UTF-8, which is clearly wrong, but we don't ship UTF-8 yet so this
 // is fine until we can fix users that depend on code-unit counting).
-#define JS_COLUMN_DIMENSION_IS_CODE_POINTS 1
+#define JS_COLUMN_DIMENSION_IS_CODE_POINTS 0
 
 template <typename Unit, class AnyCharsAccess>
 class GeneralTokenStreamChars : public SpecializedTokenStreamCharsBase<Unit> {
   using CharsBase = TokenStreamCharsBase<Unit>;
   using SpecializedCharsBase = SpecializedTokenStreamCharsBase<Unit>;
 
   using LineToken = TokenStreamAnyChars::LineToken;
 
--- a/js/src/vm/CompilationAndEvaluation.cpp
+++ b/js/src/vm/CompilationAndEvaluation.cpp
@@ -20,17 +20,17 @@
 #include "frontend/BytecodeCompilation.h"  // frontend::CompileGlobalScript
 #include "frontend/FullParseHandler.h"     // frontend::FullParseHandler
 #include "frontend/ParseContext.h"         // frontend::UsedNameTracker
 #include "frontend/Parser.h"       // frontend::Parser, frontend::ParseGoal
 #include "js/CharacterEncoding.h"  // JS::UTF8Chars, JS::UTF8CharsToNewTwoByteCharsZ
 #include "js/RootingAPI.h"         // JS::Rooted
 #include "js/SourceText.h"         // JS::SourceText
 #include "js/TypeDecls.h"          // JS::HandleObject, JS::MutableHandleScript
-#include "js/Utility.h"            // JS::UniqueTwoByteChars
+#include "js/Utility.h"            // js::MallocArena, JS::UniqueTwoByteChars
 #include "js/Value.h"              // JS::Value
 #include "util/CompleteFile.h"     // js::FileContents, js::ReadCompleteFile
 #include "util/StringBuffer.h"     // js::StringBuffer
 #include "vm/Debugger.h"           // js::Debugger
 #include "vm/EnvironmentObject.h"  // js::CreateNonSyntacticEnvironmentChain
 #include "vm/Interpreter.h"        // js::Execute
 #include "vm/JSContext.h"          // JSContext
 
@@ -509,19 +509,21 @@ JS_PUBLIC_API bool JS::CloneAndExecuteSc
     }
 
     js::Debugger::onNewScript(cx, script);
   }
   return ExecuteScript(cx, envChain, script, rval.address());
 }
 
 template <typename Unit>
-static bool Evaluate(JSContext* cx, ScopeKind scopeKind, HandleObject env,
-                     const ReadOnlyCompileOptions& optionsArg,
-                     SourceText<Unit>& srcBuf, MutableHandleValue rval) {
+static bool EvaluateSourceBuffer(JSContext* cx, ScopeKind scopeKind,
+                                 Handle<JSObject*> env,
+                                 const ReadOnlyCompileOptions& optionsArg,
+                                 SourceText<Unit>& srcBuf,
+                                 MutableHandle<Value> rval) {
   CompileOptions options(cx, optionsArg);
   MOZ_ASSERT(!cx->zone()->isAtomsZone());
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
   cx->check(env);
   MOZ_ASSERT_IF(!IsGlobalLexicalEnvironment(env),
                 scopeKind == ScopeKind::NonSyntactic);
 
@@ -535,45 +537,67 @@ static bool Evaluate(JSContext* cx, Scop
       return false;
     }
   }
 
   return Execute(cx, script, *env,
                  options.noScriptRval ? nullptr : rval.address());
 }
 
-extern JS_PUBLIC_API bool JS::Evaluate(JSContext* cx,
-                                       const ReadOnlyCompileOptions& options,
-                                       SourceText<Utf8Unit>& srcBuf,
-                                       MutableHandle<Value> rval) {
+JS_PUBLIC_API bool JS::Evaluate(JSContext* cx,
+                                const ReadOnlyCompileOptions& options,
+                                SourceText<Utf8Unit>& srcBuf,
+                                MutableHandle<Value> rval) {
   RootedObject globalLexical(cx, &cx->global()->lexicalEnvironment());
-  return ::Evaluate(cx, ScopeKind::Global, globalLexical, options, srcBuf,
-                    rval);
+
+  size_t length = srcBuf.length();
+  auto chars = UniqueTwoByteChars(
+      UTF8CharsToNewTwoByteCharsZ(cx, UTF8Chars(srcBuf.get(), length),
+                                  &length, js::MallocArena).get());
+  if (!chars) {
+    return false;
+  }
+
+  SourceText<char16_t> inflatedSrc;
+  if (!inflatedSrc.init(cx, std::move(chars), length)) {
+    return false;
+  }
+
+  return EvaluateSourceBuffer(cx, ScopeKind::Global, globalLexical, options,
+                              inflatedSrc, rval);
+}
+
+JS_PUBLIC_API bool JS::EvaluateDontInflate(
+    JSContext* cx, const ReadOnlyCompileOptions& options,
+    SourceText<Utf8Unit>& srcBuf, MutableHandle<Value> rval) {
+  RootedObject globalLexical(cx, &cx->global()->lexicalEnvironment());
+  return EvaluateSourceBuffer(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);
+  return EvaluateSourceBuffer(cx, ScopeKind::Global, globalLexical, optionsArg,
+                              srcBuf, rval);
 }
 
 JS_PUBLIC_API bool JS::Evaluate(JSContext* cx, HandleObjectVector envChain,
                                 const ReadOnlyCompileOptions& options,
                                 SourceText<char16_t>& srcBuf,
                                 MutableHandleValue rval) {
   RootedObject env(cx);
   RootedScope scope(cx);
   if (!CreateNonSyntacticEnvironmentChain(cx, envChain, &env, &scope)) {
     return false;
   }
 
-  return ::Evaluate(cx, scope->kind(), env, options, srcBuf, rval);
+  return EvaluateSourceBuffer(cx, scope->kind(), env, options, srcBuf, rval);
 }
 
 JS_PUBLIC_API bool JS::EvaluateUtf8Path(
     JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
     const char* filename, MutableHandleValue rval) {
   FileContents buffer(cx);
   {
     AutoFile file;