Bug 1552979 - Add ParseModule and CompileModule overloads for UTF-8. r=arai
authorJeff Walden <jwalden@mit.edu>
Mon, 20 May 2019 02:49:20 -0700
changeset 475405 cb71e51f8cadbe76fe68739fb022e6f91233ded4
parent 475404 3ce85949f2e16fa924f40aaa8e8b69df918dcd1b
child 475406 6fac68354ef48e8945ccf506a5602aadddd5a3b9
push id36061
push usercbrindusan@mozilla.com
push dateFri, 24 May 2019 21:49:59 +0000
treeherdermozilla-central@5d3e1ea77693 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1552979
milestone69.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 1552979 - Add ParseModule and CompileModule overloads for UTF-8. r=arai Differential Revision: https://phabricator.services.mozilla.com/D31895
js/src/frontend/BytecodeCompiler.cpp
js/src/frontend/BytecodeCompiler.h
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -4,17 +4,17 @@
  * 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/. */
 
 #include "frontend/BytecodeCompiler.h"
 
 #include "mozilla/Attributes.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Maybe.h"
-#include "mozilla/Utf8.h"
+#include "mozilla/Utf8.h"  // mozilla::Utf8Unit
 
 #include "builtin/ModuleObject.h"
 #if defined(JS_BUILD_BINAST)
 #  include "frontend/BinASTParser.h"
 #endif  // JS_BUILD_BINAST
 #include "frontend/BytecodeCompilation.h"
 #include "frontend/BytecodeEmitter.h"
 #include "frontend/EitherParser.h"
@@ -816,33 +816,40 @@ static ModuleObject* InternalParseModule
   options.maybeMakeStrictMode(
       true);  // ES6 10.2.1 Module code is always strict mode code.
   options.setIsRunOnce(true);
   options.allowHTMLComments = false;
 
   ModuleInfo info(cx, options);
   AutoInitializeSourceObject autoSSO(info, sourceObjectOut);
 
-  ModuleCompiler<char16_t> compiler(srcBuf);
+  ModuleCompiler<Unit> compiler(srcBuf);
   ModuleObject* module = compiler.compile(info);
   if (!module) {
     return nullptr;
   }
 
   assertException.reset();
   return module;
 }
 
 ModuleObject* frontend::ParseModule(JSContext* cx,
                                     const ReadOnlyCompileOptions& optionsInput,
                                     SourceText<char16_t>& srcBuf,
                                     ScriptSourceObject** sourceObjectOut) {
   return InternalParseModule(cx, optionsInput, srcBuf, sourceObjectOut);
 }
 
+ModuleObject* frontend::ParseModule(JSContext* cx,
+                                    const ReadOnlyCompileOptions& optionsInput,
+                                    SourceText<Utf8Unit>& srcBuf,
+                                    ScriptSourceObject** sourceObjectOut) {
+  return InternalParseModule(cx, optionsInput, srcBuf, sourceObjectOut);
+}
+
 template <typename Unit>
 static ModuleObject* CreateModule(JSContext* cx,
                                   const JS::ReadOnlyCompileOptions& options,
                                   SourceText<Unit>& srcBuf) {
   AutoAssertReportedException assertException(cx);
 
   if (!GlobalObject::ensureModulePrototypesCreated(cx, cx->global())) {
     return nullptr;
@@ -864,16 +871,22 @@ static ModuleObject* CreateModule(JSCont
 }
 
 ModuleObject* frontend::CompileModule(JSContext* cx,
                                       const JS::ReadOnlyCompileOptions& options,
                                       SourceText<char16_t>& srcBuf) {
   return CreateModule(cx, options, srcBuf);
 }
 
+ModuleObject* frontend::CompileModule(JSContext* cx,
+                                      const JS::ReadOnlyCompileOptions& options,
+                                      SourceText<Utf8Unit>& srcBuf) {
+  return CreateModule(cx, options, srcBuf);
+}
+
 // When leaving this scope, the given function should either:
 //   * be linked to a fully compiled script
 //   * remain linking to a lazy script
 class MOZ_STACK_CLASS AutoAssertFunctionDelazificationCompletion {
 #ifdef DEBUG
   RootedFunction fun_;
 #endif
 
--- a/js/src/frontend/BytecodeCompiler.h
+++ b/js/src/frontend/BytecodeCompiler.h
@@ -3,16 +3,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #ifndef frontend_BytecodeCompiler_h
 #define frontend_BytecodeCompiler_h
 
 #include "mozilla/Maybe.h"
+#include "mozilla/Utf8.h"  // mozilla::Utf8Unit
 
 #include "NamespaceImports.h"
 
 #include "js/CompileOptions.h"
 #include "js/SourceText.h"
 #include "vm/Scope.h"
 #include "vm/TraceLogging.h"
 
@@ -119,23 +120,30 @@ MOZ_MUST_USE bool CompileLazyBinASTFunct
                                             const uint8_t* buf, size_t length);
 
 #endif  // JS_BUILD_BINAST
 
 // Compile a module of the given source using the given options.
 ModuleObject* CompileModule(JSContext* cx,
                             const JS::ReadOnlyCompileOptions& options,
                             JS::SourceText<char16_t>& srcBuf);
+ModuleObject* CompileModule(JSContext* cx,
+                            const JS::ReadOnlyCompileOptions& options,
+                            JS::SourceText<mozilla::Utf8Unit>& srcBuf);
 
 // Parse a module of the given source.  This is an internal API; if you want to
 // compile a module as a user, use CompileModule above.
 ModuleObject* ParseModule(JSContext* cx,
                           const JS::ReadOnlyCompileOptions& options,
                           JS::SourceText<char16_t>& srcBuf,
                           ScriptSourceObject** sourceObjectOut);
+ModuleObject* ParseModule(JSContext* cx,
+                          const JS::ReadOnlyCompileOptions& options,
+                          JS::SourceText<mozilla::Utf8Unit>& srcBuf,
+                          ScriptSourceObject** sourceObjectOut);
 
 //
 // Compile a single function. The source in srcBuf must match the ECMA-262
 // FunctionExpression production.
 //
 // If nonzero, parameterListEnd is the offset within srcBuf where the parameter
 // list is expected to end. During parsing, if we find that it ends anywhere
 // else, it's a SyntaxError. This is used to implement the Function constructor;