ModuleRecordBase.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace Js
  7. {
  8. class ModuleRecordBase;
  9. class ModuleNamespace;
  10. typedef SList<PropertyId> ExportedNames;
  11. typedef SList<ModuleRecordBase*> ExportModuleRecordList;
  12. struct ModuleNameRecord
  13. {
  14. ModuleNameRecord(const ModuleNameRecord& other)
  15. :module(other.module), bindingName(other.bindingName)
  16. {}
  17. ModuleNameRecord(ModuleRecordBase* module, PropertyId bindingName)
  18. :module(module), bindingName(bindingName)
  19. {}
  20. ModuleNameRecord() {}
  21. Field(ModuleRecordBase*) module;
  22. Field(PropertyId) bindingName;
  23. };
  24. typedef SList<ModuleNameRecord> ResolveSet;
  25. // ModuleRecord need to keep rootFunction etc. alive.
  26. class ModuleRecordBase : public FinalizableObject
  27. {
  28. public:
  29. static const uint32 ModuleMagicNumber;
  30. ModuleRecordBase(JavascriptLibrary* library) :
  31. namespaceObject(nullptr), wasEvaluated(false),
  32. javascriptLibrary(library), magicNumber(ModuleMagicNumber){};
  33. bool WasEvaluated() { return wasEvaluated; }
  34. void SetWasEvaluated() { Assert(!wasEvaluated); wasEvaluated = true; }
  35. JavascriptLibrary* GetRealm() { return javascriptLibrary; } // TODO: do we need to provide this method ?
  36. virtual ModuleNamespace* GetNamespace() { return namespaceObject; }
  37. virtual void SetNamespace(ModuleNamespace* moduleNamespace) { namespaceObject = moduleNamespace; }
  38. virtual ExportedNames* GetExportedNames(ExportModuleRecordList* exportStarSet) = 0;
  39. // return false when "ambiguous".
  40. // otherwise nullptr means "null" where we have circular reference/cannot resolve.
  41. virtual bool ResolveExport(PropertyId exportName, ResolveSet* resolveSet, ModuleNameRecord** exportRecord) = 0;
  42. virtual bool ModuleDeclarationInstantiation() = 0;
  43. virtual void GenerateRootFunction() = 0;
  44. virtual Var ModuleEvaluation() = 0;
  45. virtual bool IsSourceTextModuleRecord() { return false; }
  46. protected:
  47. Field(uint32) magicNumber;
  48. Field(ModuleNamespace*) namespaceObject;
  49. Field(bool) wasEvaluated;
  50. Field(JavascriptLibrary*) javascriptLibrary;
  51. };
  52. }