Bug 1550616 - Move ModuleBuilder into its own header so that module object-related data structures don't depend on EitherParser.h (and therefore all of parsing and tokenizing). r=tcampbell
☠☠ backed out by 464bde42a158 ☠ ☠
authorJeff Walden <jwalden@mit.edu>
Sun, 12 May 2019 01:39:15 +0000
changeset 532355 b435e9bb58cc70ce432f6f3fc837fa318d35a637
parent 532354 1b35028d64e470f26dd1fec14b331194b86fec30
child 532356 f1a3220fc10b57240e57bde4bfeba9745013dffe
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
bugs1550616
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 1550616 - Move ModuleBuilder into its own header so that module object-related data structures don't depend on EitherParser.h (and therefore all of parsing and tokenizing). r=tcampbell Differential Revision: https://phabricator.services.mozilla.com/D30578
js/src/builtin/ModuleObject.cpp
js/src/builtin/ModuleObject.h
js/src/builtin/ReflectParse.cpp
js/src/frontend/BytecodeCompiler.cpp
js/src/frontend/ModuleSharedContext.h
js/src/frontend/Parser.cpp
js/src/gc/Barrier.cpp
js/src/jit/mips32/MacroAssembler-mips32-inl.h
js/src/jit/mips64/MacroAssembler-mips64-inl.h
js/src/jit/x64/MacroAssembler-x64.h
js/src/jit/x86/MacroAssembler-x86.h
js/src/shell/js.cpp
js/src/vm/ModuleBuilder.h
js/src/vm/SelfHosting.cpp
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -15,16 +15,17 @@
 #include "frontend/SharedContext.h"
 #include "gc/FreeOp.h"
 #include "gc/Policy.h"
 #include "gc/Tracer.h"
 #include "js/PropertySpec.h"
 #include "vm/AsyncFunction.h"
 #include "vm/AsyncIteration.h"
 #include "vm/EqualityOperations.h"  // js::SameValue
+#include "vm/ModuleBuilder.h"       // js::ModuleBuilder
 #include "vm/SelfHosting.h"
 
 #include "vm/JSObject-inl.h"
 #include "vm/JSScript-inl.h"
 
 using namespace js;
 
 static_assert(MODULE_STATUS_UNINSTANTIATED < MODULE_STATUS_INSTANTIATING &&
--- a/js/src/builtin/ModuleObject.h
+++ b/js/src/builtin/ModuleObject.h
@@ -7,36 +7,29 @@
 #ifndef builtin_ModuleObject_h
 #define builtin_ModuleObject_h
 
 #include "mozilla/Maybe.h"
 
 #include "jsapi.h"
 
 #include "builtin/SelfHostingDefines.h"
-#include "frontend/EitherParser.h"
 #include "gc/Zone.h"
 #include "js/GCVector.h"
 #include "js/Id.h"
 #include "js/UniquePtr.h"
 #include "vm/JSAtom.h"
 #include "vm/NativeObject.h"
 #include "vm/ProxyObject.h"
 
 namespace js {
 
 class ModuleEnvironmentObject;
 class ModuleObject;
 
-namespace frontend {
-class BinaryNode;
-class ListNode;
-class ParseNode;
-} /* namespace frontend */
-
 typedef Rooted<ModuleObject*> RootedModuleObject;
 typedef Handle<ModuleObject*> HandleModuleObject;
 typedef Rooted<ModuleEnvironmentObject*> RootedModuleEnvironmentObject;
 typedef Handle<ModuleEnvironmentObject*> HandleModuleEnvironmentObject;
 
 class ImportEntryObject : public NativeObject {
  public:
   enum {
@@ -326,86 +319,16 @@ class ModuleObject : public NativeObject
 
   static void trace(JSTracer* trc, JSObject* obj);
   static void finalize(js::FreeOp* fop, JSObject* obj);
 
   bool hasImportBindings() const;
   FunctionDeclarationVector* functionDeclarations();
 };
 
-// Process a module's parse tree to collate the import and export data used when
-// creating a ModuleObject.
-class MOZ_STACK_CLASS ModuleBuilder {
-  explicit ModuleBuilder(JSContext* cx, HandleModuleObject module,
-                         const frontend::EitherParser& eitherParser);
-
- public:
-  template <class Parser>
-  explicit ModuleBuilder(JSContext* cx, HandleModuleObject module,
-                         Parser* parser)
-      : ModuleBuilder(cx, module, frontend::EitherParser(parser)) {}
-
-  bool processImport(frontend::BinaryNode* importNode);
-  bool processExport(frontend::ParseNode* exportNode);
-  bool processExportFrom(frontend::BinaryNode* exportNode);
-
-  bool hasExportedName(JSAtom* name) const;
-
-  using ExportEntryVector = GCVector<ExportEntryObject*>;
-  const ExportEntryVector& localExportEntries() const {
-    return localExportEntries_;
-  }
-
-  bool buildTables();
-  bool initModule();
-
- private:
-  using RequestedModuleVector = GCVector<RequestedModuleObject*>;
-  using AtomSet = JS::GCHashSet<JSAtom*>;
-  using ImportEntryMap = GCHashMap<JSAtom*, ImportEntryObject*>;
-  using RootedExportEntryVector = JS::Rooted<ExportEntryVector>;
-  using RootedRequestedModuleVector = JS::Rooted<RequestedModuleVector>;
-  using RootedAtomSet = JS::Rooted<AtomSet>;
-  using RootedImportEntryMap = JS::Rooted<ImportEntryMap>;
-
-  JSContext* cx_;
-  RootedModuleObject module_;
-  frontend::EitherParser eitherParser_;
-  RootedAtomSet requestedModuleSpecifiers_;
-  RootedRequestedModuleVector requestedModules_;
-  RootedImportEntryMap importEntries_;
-  RootedExportEntryVector exportEntries_;
-  RootedAtomSet exportNames_;
-  RootedExportEntryVector localExportEntries_;
-  RootedExportEntryVector indirectExportEntries_;
-  RootedExportEntryVector starExportEntries_;
-
-  ImportEntryObject* importEntryFor(JSAtom* localName) const;
-
-  bool processExportBinding(frontend::ParseNode* pn);
-  bool processExportArrayBinding(frontend::ListNode* array);
-  bool processExportObjectBinding(frontend::ListNode* obj);
-
-  bool appendImportEntryObject(HandleImportEntryObject importEntry);
-
-  bool appendExportEntry(HandleAtom exportName, HandleAtom localName,
-                         frontend::ParseNode* node = nullptr);
-  bool appendExportFromEntry(HandleAtom exportName, HandleAtom moduleRequest,
-                             HandleAtom importName, frontend::ParseNode* node);
-  bool appendExportEntryObject(HandleExportEntryObject exportEntry);
-
-  bool maybeAppendRequestedModule(HandleAtom specifier,
-                                  frontend::ParseNode* node);
-
-  template <typename T>
-  ArrayObject* createArray(const JS::Rooted<GCVector<T>>& vector);
-  template <typename K, typename V>
-  ArrayObject* createArray(const JS::Rooted<GCHashMap<K, V>>& map);
-};
-
 JSObject* GetOrCreateModuleMetaObject(JSContext* cx, HandleObject module);
 
 JSObject* CallModuleResolveHook(JSContext* cx, HandleValue referencingPrivate,
                                 HandleString specifier);
 
 JSObject* StartDynamicModuleImport(JSContext* cx, HandleScript script,
                                    HandleValue specifier);
 
--- a/js/src/builtin/ReflectParse.cpp
+++ b/js/src/builtin/ReflectParse.cpp
@@ -19,16 +19,17 @@
 #include "frontend/ModuleSharedContext.h"
 #include "frontend/ParseNode.h"
 #include "frontend/Parser.h"
 #include "js/CharacterEncoding.h"
 #include "js/StableStringChars.h"
 #include "vm/BigIntType.h"
 #include "vm/JSAtom.h"
 #include "vm/JSObject.h"
+#include "vm/ModuleBuilder.h"  // js::ModuleBuilder
 #include "vm/RegExpObject.h"
 
 #include "vm/JSObject-inl.h"
 
 using namespace js;
 using namespace js::frontend;
 
 using JS::AutoStableStringChars;
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -21,16 +21,17 @@
 #include "frontend/ErrorReporter.h"
 #include "frontend/FoldConstants.h"
 #include "frontend/ModuleSharedContext.h"
 #include "frontend/Parser.h"
 #include "js/SourceText.h"
 #include "vm/GlobalObject.h"
 #include "vm/JSContext.h"
 #include "vm/JSScript.h"
+#include "vm/ModuleBuilder.h"  // js::ModuleBuilder
 #include "vm/TraceLogging.h"
 #include "wasm/AsmJS.h"
 
 #include "vm/EnvironmentObject-inl.h"
 #include "vm/GeckoProfiler-inl.h"
 #include "vm/JSContext-inl.h"
 
 using namespace js;
--- a/js/src/frontend/ModuleSharedContext.h
+++ b/js/src/frontend/ModuleSharedContext.h
@@ -5,22 +5,25 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef frontend_ModuleSharedContext_h
 #define frontend_ModuleSharedContext_h
 
 #include "mozilla/Assertions.h"  // MOZ_ASSERT
 #include "mozilla/Attributes.h"  // MOZ_STACK_CLASS
 
-#include "builtin/ModuleObject.h"    // js::Module{Builder,Object}
+#include "builtin/ModuleObject.h"    // js::ModuleObject
 #include "frontend/SharedContext.h"  // js::frontend::SharedContext
 #include "js/RootingAPI.h"           // JS::Handle, JS::Rooted
 #include "vm/Scope.h"                // js::{Module,}Scope
 
 namespace js {
+
+class ModuleBuilder;
+
 namespace frontend {
 
 class MOZ_STACK_CLASS ModuleSharedContext : public SharedContext {
   JS::Rooted<ModuleObject*> module_;
   JS::Rooted<Scope*> enclosingScope_;
 
  public:
   JS::Rooted<ModuleScope::Data*> bindings;
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -43,16 +43,17 @@
 #include "frontend/TokenStream.h"
 #include "irregexp/RegExpParser.h"
 #include "js/RegExpFlags.h"  // JS::RegExpFlags
 #include "vm/BytecodeUtil.h"
 #include "vm/JSAtom.h"
 #include "vm/JSContext.h"
 #include "vm/JSFunction.h"
 #include "vm/JSScript.h"
+#include "vm/ModuleBuilder.h"  // js::ModuleBuilder
 #include "vm/RegExpObject.h"
 #include "vm/StringType.h"
 #include "wasm/AsmJS.h"
 
 #include "frontend/ParseContext-inl.h"
 #include "frontend/SharedContext-inl.h"
 #include "vm/EnvironmentObject-inl.h"
 
--- a/js/src/gc/Barrier.cpp
+++ b/js/src/gc/Barrier.cpp
@@ -6,16 +6,17 @@
 
 #include "gc/Barrier.h"
 
 #include "builtin/TypedObject.h"
 #include "gc/Policy.h"
 #include "gc/Zone.h"
 #include "js/HashTable.h"
 #include "js/Value.h"
+#include "vm/BigIntType.h"  // JS::BigInt
 #include "vm/EnvironmentObject.h"
 #include "vm/JSObject.h"
 #include "vm/Realm.h"
 #include "vm/SharedArrayObject.h"
 #include "vm/SymbolType.h"
 #include "wasm/WasmJS.h"
 
 #include "gc/Zone-inl.h"
--- a/js/src/jit/mips32/MacroAssembler-mips32-inl.h
+++ b/js/src/jit/mips32/MacroAssembler-mips32-inl.h
@@ -4,16 +4,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/. */
 
 #ifndef jit_mips32_MacroAssembler_mips32_inl_h
 #define jit_mips32_MacroAssembler_mips32_inl_h
 
 #include "jit/mips32/MacroAssembler-mips32.h"
 
+#include "vm/BigIntType.h"  // JS::BigInt
+
 #include "jit/mips-shared/MacroAssembler-mips-shared-inl.h"
 
 namespace js {
 namespace jit {
 
 //{{{ check_macroassembler_style
 
 void MacroAssembler::move64(Register64 src, Register64 dest) {
--- a/js/src/jit/mips64/MacroAssembler-mips64-inl.h
+++ b/js/src/jit/mips64/MacroAssembler-mips64-inl.h
@@ -4,16 +4,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/. */
 
 #ifndef jit_mips64_MacroAssembler_mips64_inl_h
 #define jit_mips64_MacroAssembler_mips64_inl_h
 
 #include "jit/mips64/MacroAssembler-mips64.h"
 
+#include "vm/BigIntType.h"  // JS::BigInt
+
 #include "jit/mips-shared/MacroAssembler-mips-shared-inl.h"
 
 namespace js {
 namespace jit {
 
 //{{{ check_macroassembler_style
 
 void MacroAssembler::move64(Register64 src, Register64 dest) {
--- a/js/src/jit/x64/MacroAssembler-x64.h
+++ b/js/src/jit/x64/MacroAssembler-x64.h
@@ -6,16 +6,17 @@
 
 #ifndef jit_x64_MacroAssembler_x64_h
 #define jit_x64_MacroAssembler_x64_h
 
 #include "jit/JitFrames.h"
 #include "jit/MoveResolver.h"
 #include "jit/x86-shared/MacroAssembler-x86-shared.h"
 #include "js/HeapAPI.h"
+#include "vm/BigIntType.h"  // JS::BigInt
 
 namespace js {
 namespace jit {
 
 struct ImmShiftedTag : public ImmWord {
   explicit ImmShiftedTag(JSValueShiftedTag shtag) : ImmWord((uintptr_t)shtag) {}
 
   explicit ImmShiftedTag(JSValueType type)
--- a/js/src/jit/x86/MacroAssembler-x86.h
+++ b/js/src/jit/x86/MacroAssembler-x86.h
@@ -6,16 +6,17 @@
 
 #ifndef jit_x86_MacroAssembler_x86_h
 #define jit_x86_MacroAssembler_x86_h
 
 #include "jit/JitFrames.h"
 #include "jit/MoveResolver.h"
 #include "jit/x86-shared/MacroAssembler-x86-shared.h"
 #include "js/HeapAPI.h"
+#include "vm/BigIntType.h"  // JS::BigInt
 #include "vm/Realm.h"
 
 namespace js {
 namespace jit {
 
 // See documentation for ScratchTagScope and ScratchTagScopeRelease in
 // MacroAssembler-x64.h.
 
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -123,16 +123,17 @@
 #include "vm/Compression.h"
 #include "vm/Debugger.h"
 #include "vm/HelperThreads.h"
 #include "vm/JSAtom.h"
 #include "vm/JSContext.h"
 #include "vm/JSFunction.h"
 #include "vm/JSObject.h"
 #include "vm/JSScript.h"
+#include "vm/ModuleBuilder.h"  // js::ModuleBuilder
 #include "vm/Monitor.h"
 #include "vm/MutexIDs.h"
 #include "vm/Printer.h"
 #include "vm/Shape.h"
 #include "vm/SharedArrayObject.h"
 #include "vm/Time.h"
 #include "vm/TypedArrayObject.h"
 #include "vm/WrapperObject.h"
copy from js/src/builtin/ModuleObject.h
copy to js/src/vm/ModuleBuilder.h
--- a/js/src/builtin/ModuleObject.h
+++ b/js/src/vm/ModuleBuilder.h
@@ -1,350 +1,48 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * vim: set ts=8 sts=2 et sw=2 tw=80:
  * 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 builtin_ModuleObject_h
-#define builtin_ModuleObject_h
+#ifndef vm_ModuleBuilder_h
+#define vm_ModuleBuilder_h
 
-#include "mozilla/Maybe.h"
-
-#include "jsapi.h"
+#include "mozilla/Attributes.h"  // MOZ_STACK_CLASS
 
-#include "builtin/SelfHostingDefines.h"
-#include "frontend/EitherParser.h"
-#include "gc/Zone.h"
-#include "js/GCVector.h"
-#include "js/Id.h"
-#include "js/UniquePtr.h"
-#include "vm/JSAtom.h"
-#include "vm/NativeObject.h"
-#include "vm/ProxyObject.h"
+#include "builtin/ModuleObject.h"  // js::{{Im,Ex}portEntry,Requested{Module,}}Object
+#include "frontend/EitherParser.h"  // js::frontend::EitherParser
+#include "js/GCHashTable.h"         // JS::GCHash{Map,Set}
+#include "js/GCVector.h"            // JS::GCVector
+#include "js/RootingAPI.h"          // JS::{Handle,Rooted}
+#include "vm/AtomsTable.h"          // js::AtomSet
+
+struct JSContext;
+class JSAtom;
 
 namespace js {
 
-class ModuleEnvironmentObject;
-class ModuleObject;
+namespace frontend {
 
-namespace frontend {
 class BinaryNode;
 class ListNode;
 class ParseNode;
-} /* namespace frontend */
 
-typedef Rooted<ModuleObject*> RootedModuleObject;
-typedef Handle<ModuleObject*> HandleModuleObject;
-typedef Rooted<ModuleEnvironmentObject*> RootedModuleEnvironmentObject;
-typedef Handle<ModuleEnvironmentObject*> HandleModuleEnvironmentObject;
-
-class ImportEntryObject : public NativeObject {
- public:
-  enum {
-    ModuleRequestSlot = 0,
-    ImportNameSlot,
-    LocalNameSlot,
-    LineNumberSlot,
-    ColumnNumberSlot,
-    SlotCount
-  };
-
-  static const Class class_;
-  static bool isInstance(HandleValue value);
-  static ImportEntryObject* create(JSContext* cx, HandleAtom moduleRequest,
-                                   HandleAtom importName, HandleAtom localName,
-                                   uint32_t lineNumber, uint32_t columnNumber);
-  JSAtom* moduleRequest() const;
-  JSAtom* importName() const;
-  JSAtom* localName() const;
-  uint32_t lineNumber() const;
-  uint32_t columnNumber() const;
-};
-
-typedef Rooted<ImportEntryObject*> RootedImportEntryObject;
-typedef Handle<ImportEntryObject*> HandleImportEntryObject;
-
-class ExportEntryObject : public NativeObject {
- public:
-  enum {
-    ExportNameSlot = 0,
-    ModuleRequestSlot,
-    ImportNameSlot,
-    LocalNameSlot,
-    LineNumberSlot,
-    ColumnNumberSlot,
-    SlotCount
-  };
-
-  static const Class class_;
-  static bool isInstance(HandleValue value);
-  static ExportEntryObject* create(JSContext* cx, HandleAtom maybeExportName,
-                                   HandleAtom maybeModuleRequest,
-                                   HandleAtom maybeImportName,
-                                   HandleAtom maybeLocalName,
-                                   uint32_t lineNumber, uint32_t columnNumber);
-  JSAtom* exportName() const;
-  JSAtom* moduleRequest() const;
-  JSAtom* importName() const;
-  JSAtom* localName() const;
-  uint32_t lineNumber() const;
-  uint32_t columnNumber() const;
-};
-
-typedef Rooted<ExportEntryObject*> RootedExportEntryObject;
-typedef Handle<ExportEntryObject*> HandleExportEntryObject;
-
-class RequestedModuleObject : public NativeObject {
- public:
-  enum { ModuleSpecifierSlot = 0, LineNumberSlot, ColumnNumberSlot, SlotCount };
-
-  static const Class class_;
-  static bool isInstance(HandleValue value);
-  static RequestedModuleObject* create(JSContext* cx,
-                                       HandleAtom moduleSpecifier,
-                                       uint32_t lineNumber,
-                                       uint32_t columnNumber);
-  JSAtom* moduleSpecifier() const;
-  uint32_t lineNumber() const;
-  uint32_t columnNumber() const;
-};
-
-typedef Rooted<RequestedModuleObject*> RootedRequestedModuleObject;
-typedef Handle<RequestedModuleObject*> HandleRequestedModuleObject;
-
-class IndirectBindingMap {
- public:
-  void trace(JSTracer* trc);
-
-  bool put(JSContext* cx, HandleId name,
-           HandleModuleEnvironmentObject environment, HandleId localName);
-
-  size_t count() const { return map_ ? map_->count() : 0; }
-
-  bool has(jsid name) const { return map_ ? map_->has(name) : false; }
-
-  bool lookup(jsid name, ModuleEnvironmentObject** envOut,
-              Shape** shapeOut) const;
-
-  template <typename Func>
-  void forEachExportedName(Func func) const {
-    if (!map_) {
-      return;
-    }
-
-    for (auto r = map_->all(); !r.empty(); r.popFront()) {
-      func(r.front().key());
-    }
-  }
-
- private:
-  struct Binding {
-    Binding(ModuleEnvironmentObject* environment, Shape* shape);
-    HeapPtr<ModuleEnvironmentObject*> environment;
-    HeapPtr<Shape*> shape;
-  };
-
-  typedef HashMap<jsid, Binding, DefaultHasher<jsid>, ZoneAllocPolicy> Map;
-
-  mozilla::Maybe<Map> map_;
-};
-
-class ModuleNamespaceObject : public ProxyObject {
- public:
-  enum ModuleNamespaceSlot { ExportsSlot = 0, BindingsSlot };
-
-  static bool isInstance(HandleValue value);
-  static ModuleNamespaceObject* create(JSContext* cx, HandleModuleObject module,
-                                       HandleObject exports,
-                                       UniquePtr<IndirectBindingMap> bindings);
-
-  ModuleObject& module();
-  JSObject& exports();
-  IndirectBindingMap& bindings();
-
-  bool addBinding(JSContext* cx, HandleAtom exportedName,
-                  HandleModuleObject targetModule, HandleAtom localName);
-
- private:
-  struct ProxyHandler : public BaseProxyHandler {
-    ProxyHandler();
-
-    bool getOwnPropertyDescriptor(
-        JSContext* cx, HandleObject proxy, HandleId id,
-        MutableHandle<PropertyDescriptor> desc) const override;
-    bool defineProperty(JSContext* cx, HandleObject proxy, HandleId id,
-                        Handle<PropertyDescriptor> desc,
-                        ObjectOpResult& result) const override;
-    bool ownPropertyKeys(JSContext* cx, HandleObject proxy,
-                         MutableHandleIdVector props) const override;
-    bool delete_(JSContext* cx, HandleObject proxy, HandleId id,
-                 ObjectOpResult& result) const override;
-    bool getPrototype(JSContext* cx, HandleObject proxy,
-                      MutableHandleObject protop) const override;
-    bool setPrototype(JSContext* cx, HandleObject proxy, HandleObject proto,
-                      ObjectOpResult& result) const override;
-    bool getPrototypeIfOrdinary(JSContext* cx, HandleObject proxy,
-                                bool* isOrdinary,
-                                MutableHandleObject protop) const override;
-    bool setImmutablePrototype(JSContext* cx, HandleObject proxy,
-                               bool* succeeded) const override;
-
-    bool preventExtensions(JSContext* cx, HandleObject proxy,
-                           ObjectOpResult& result) const override;
-    bool isExtensible(JSContext* cx, HandleObject proxy,
-                      bool* extensible) const override;
-    bool has(JSContext* cx, HandleObject proxy, HandleId id,
-             bool* bp) const override;
-    bool get(JSContext* cx, HandleObject proxy, HandleValue receiver,
-             HandleId id, MutableHandleValue vp) const override;
-    bool set(JSContext* cx, HandleObject proxy, HandleId id, HandleValue v,
-             HandleValue receiver, ObjectOpResult& result) const override;
-
-    void trace(JSTracer* trc, JSObject* proxy) const override;
-    void finalize(JSFreeOp* fop, JSObject* proxy) const override;
-
-    static const char family;
-  };
-
- public:
-  static const ProxyHandler proxyHandler;
-};
-
-typedef Rooted<ModuleNamespaceObject*> RootedModuleNamespaceObject;
-typedef Handle<ModuleNamespaceObject*> HandleModuleNamespaceObject;
-
-struct FunctionDeclaration {
-  FunctionDeclaration(HandleAtom name, HandleFunction fun);
-  void trace(JSTracer* trc);
-
-  HeapPtr<JSAtom*> name;
-  HeapPtr<JSFunction*> fun;
-};
-
-using FunctionDeclarationVector =
-    GCVector<FunctionDeclaration, 0, ZoneAllocPolicy>;
-
-// Possible values for ModuleStatus are defined in SelfHostingDefines.h.
-using ModuleStatus = int32_t;
-
-class ModuleObject : public NativeObject {
- public:
-  enum ModuleSlot {
-    ScriptSlot = 0,
-    EnvironmentSlot,
-    NamespaceSlot,
-    StatusSlot,
-    EvaluationErrorSlot,
-    MetaObjectSlot,
-    ScriptSourceObjectSlot,
-    RequestedModulesSlot,
-    ImportEntriesSlot,
-    LocalExportEntriesSlot,
-    IndirectExportEntriesSlot,
-    StarExportEntriesSlot,
-    ImportBindingsSlot,
-    FunctionDeclarationsSlot,
-    DFSIndexSlot,
-    DFSAncestorIndexSlot,
-    SlotCount
-  };
-
-  static_assert(EnvironmentSlot == MODULE_OBJECT_ENVIRONMENT_SLOT,
-                "EnvironmentSlot must match self-hosting define");
-  static_assert(StatusSlot == MODULE_OBJECT_STATUS_SLOT,
-                "StatusSlot must match self-hosting define");
-  static_assert(EvaluationErrorSlot == MODULE_OBJECT_EVALUATION_ERROR_SLOT,
-                "EvaluationErrorSlot must match self-hosting define");
-  static_assert(DFSIndexSlot == MODULE_OBJECT_DFS_INDEX_SLOT,
-                "DFSIndexSlot must match self-hosting define");
-  static_assert(DFSAncestorIndexSlot == MODULE_OBJECT_DFS_ANCESTOR_INDEX_SLOT,
-                "DFSAncestorIndexSlot must match self-hosting define");
-
-  static const Class class_;
-
-  static bool isInstance(HandleValue value);
-
-  static ModuleObject* create(JSContext* cx);
-  void init(HandleScript script);
-  void setInitialEnvironment(
-      Handle<ModuleEnvironmentObject*> initialEnvironment);
-  void initImportExportData(HandleArrayObject requestedModules,
-                            HandleArrayObject importEntries,
-                            HandleArrayObject localExportEntries,
-                            HandleArrayObject indiretExportEntries,
-                            HandleArrayObject starExportEntries);
-  static bool Freeze(JSContext* cx, HandleModuleObject self);
-#ifdef DEBUG
-  static bool AssertFrozen(JSContext* cx, HandleModuleObject self);
-#endif
-  void fixEnvironmentsAfterRealmMerge();
-
-  JSScript* maybeScript() const;
-  JSScript* script() const;
-  Scope* enclosingScope() const;
-  ModuleEnvironmentObject& initialEnvironment() const;
-  ModuleEnvironmentObject* environment() const;
-  ModuleNamespaceObject* namespace_();
-  ModuleStatus status() const;
-  bool hadEvaluationError() const;
-  Value evaluationError() const;
-  JSObject* metaObject() const;
-  ScriptSourceObject* scriptSourceObject() const;
-  ArrayObject& requestedModules() const;
-  ArrayObject& importEntries() const;
-  ArrayObject& localExportEntries() const;
-  ArrayObject& indirectExportEntries() const;
-  ArrayObject& starExportEntries() const;
-  IndirectBindingMap& importBindings();
-
-  static bool Instantiate(JSContext* cx, HandleModuleObject self);
-  static bool Evaluate(JSContext* cx, HandleModuleObject self);
-
-  static ModuleNamespaceObject* GetOrCreateModuleNamespace(
-      JSContext* cx, HandleModuleObject self);
-
-  void setMetaObject(JSObject* obj);
-
-  // For BytecodeEmitter.
-  bool noteFunctionDeclaration(JSContext* cx, HandleAtom name,
-                               HandleFunction fun);
-
-  // For intrinsic_InstantiateModuleFunctionDeclarations.
-  static bool instantiateFunctionDeclarations(JSContext* cx,
-                                              HandleModuleObject self);
-
-  // For intrinsic_ExecuteModule.
-  static bool execute(JSContext* cx, HandleModuleObject self,
-                      MutableHandleValue rval);
-
-  // For intrinsic_NewModuleNamespace.
-  static ModuleNamespaceObject* createNamespace(JSContext* cx,
-                                                HandleModuleObject self,
-                                                HandleObject exports);
-
- private:
-  static const ClassOps classOps_;
-
-  static void trace(JSTracer* trc, JSObject* obj);
-  static void finalize(js::FreeOp* fop, JSObject* obj);
-
-  bool hasImportBindings() const;
-  FunctionDeclarationVector* functionDeclarations();
-};
+}  // namespace frontend
 
 // Process a module's parse tree to collate the import and export data used when
 // creating a ModuleObject.
 class MOZ_STACK_CLASS ModuleBuilder {
-  explicit ModuleBuilder(JSContext* cx, HandleModuleObject module,
+  explicit ModuleBuilder(JSContext* cx, JS::Handle<ModuleObject*> module,
                          const frontend::EitherParser& eitherParser);
 
  public:
   template <class Parser>
-  explicit ModuleBuilder(JSContext* cx, HandleModuleObject module,
+  explicit ModuleBuilder(JSContext* cx, JS::Handle<ModuleObject*> module,
                          Parser* parser)
       : ModuleBuilder(cx, module, frontend::EitherParser(parser)) {}
 
   bool processImport(frontend::BinaryNode* importNode);
   bool processExport(frontend::ParseNode* exportNode);
   bool processExportFrom(frontend::BinaryNode* exportNode);
 
   bool hasExportedName(JSAtom* name) const;
@@ -353,71 +51,59 @@ class MOZ_STACK_CLASS ModuleBuilder {
   const ExportEntryVector& localExportEntries() const {
     return localExportEntries_;
   }
 
   bool buildTables();
   bool initModule();
 
  private:
-  using RequestedModuleVector = GCVector<RequestedModuleObject*>;
+  using RequestedModuleVector = JS::GCVector<RequestedModuleObject*>;
   using AtomSet = JS::GCHashSet<JSAtom*>;
-  using ImportEntryMap = GCHashMap<JSAtom*, ImportEntryObject*>;
+  using ImportEntryMap = JS::GCHashMap<JSAtom*, ImportEntryObject*>;
   using RootedExportEntryVector = JS::Rooted<ExportEntryVector>;
   using RootedRequestedModuleVector = JS::Rooted<RequestedModuleVector>;
   using RootedAtomSet = JS::Rooted<AtomSet>;
   using RootedImportEntryMap = JS::Rooted<ImportEntryMap>;
 
   JSContext* cx_;
-  RootedModuleObject module_;
+  JS::Rooted<ModuleObject*> module_;
   frontend::EitherParser eitherParser_;
   RootedAtomSet requestedModuleSpecifiers_;
   RootedRequestedModuleVector requestedModules_;
   RootedImportEntryMap importEntries_;
   RootedExportEntryVector exportEntries_;
   RootedAtomSet exportNames_;
   RootedExportEntryVector localExportEntries_;
   RootedExportEntryVector indirectExportEntries_;
   RootedExportEntryVector starExportEntries_;
 
   ImportEntryObject* importEntryFor(JSAtom* localName) const;
 
   bool processExportBinding(frontend::ParseNode* pn);
   bool processExportArrayBinding(frontend::ListNode* array);
   bool processExportObjectBinding(frontend::ListNode* obj);
 
-  bool appendImportEntryObject(HandleImportEntryObject importEntry);
+  bool appendImportEntryObject(JS::Handle<ImportEntryObject*> importEntry);
 
-  bool appendExportEntry(HandleAtom exportName, HandleAtom localName,
+  bool appendExportEntry(JS::Handle<JSAtom*> exportName,
+                         JS::Handle<JSAtom*> localName,
                          frontend::ParseNode* node = nullptr);
-  bool appendExportFromEntry(HandleAtom exportName, HandleAtom moduleRequest,
-                             HandleAtom importName, frontend::ParseNode* node);
-  bool appendExportEntryObject(HandleExportEntryObject exportEntry);
 
-  bool maybeAppendRequestedModule(HandleAtom specifier,
+  bool appendExportFromEntry(JS::Handle<JSAtom*> exportName,
+                             JS::Handle<JSAtom*> moduleRequest,
+                             JS::Handle<JSAtom*> importName,
+                             frontend::ParseNode* node);
+
+  bool appendExportEntryObject(JS::Handle<ExportEntryObject*> exportEntry);
+
+  bool maybeAppendRequestedModule(JS::Handle<JSAtom*> specifier,
                                   frontend::ParseNode* node);
 
   template <typename T>
-  ArrayObject* createArray(const JS::Rooted<GCVector<T>>& vector);
+  ArrayObject* createArray(const JS::Rooted<JS::GCVector<T>>& vector);
   template <typename K, typename V>
-  ArrayObject* createArray(const JS::Rooted<GCHashMap<K, V>>& map);
+  ArrayObject* createArray(const JS::Rooted<JS::GCHashMap<K, V>>& map);
 };
 
-JSObject* GetOrCreateModuleMetaObject(JSContext* cx, HandleObject module);
-
-JSObject* CallModuleResolveHook(JSContext* cx, HandleValue referencingPrivate,
-                                HandleString specifier);
-
-JSObject* StartDynamicModuleImport(JSContext* cx, HandleScript script,
-                                   HandleValue specifier);
-
-bool FinishDynamicModuleImport(JSContext* cx, HandleValue referencingPrivate,
-                               HandleString specifier, HandleObject promise);
-
 }  // namespace js
 
-template <>
-inline bool JSObject::is<js::ModuleNamespaceObject>() const {
-  return js::IsDerivedProxyObject(this,
-                                  &js::ModuleNamespaceObject::proxyHandler);
-}
-
-#endif /* builtin_ModuleObject_h */
+#endif  // vm_ModuleBuilder_h
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -31,16 +31,17 @@
 #include "builtin/ModuleObject.h"
 #include "builtin/Object.h"
 #include "builtin/Promise.h"
 #include "builtin/Reflect.h"
 #include "builtin/RegExp.h"
 #include "builtin/SelfHostingDefines.h"
 #include "builtin/TypedObject.h"
 #include "builtin/WeakMapObject.h"
+#include "frontend/BytecodeCompiler.h"  // js::frontend::CreateScriptSourceObject
 #include "gc/Marking.h"
 #include "gc/Policy.h"
 #include "jit/AtomicOperations.h"
 #include "jit/InlinableNatives.h"
 #include "js/CharacterEncoding.h"
 #include "js/CompilationAndEvaluation.h"
 #include "js/Date.h"
 #include "js/PropertySpec.h"