ModuleNamespace.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 ModuleNamespace : public DynamicObject
  9. {
  10. public:
  11. friend class ModuleNamespaceEnumerator;
  12. typedef JsUtil::BaseDictionary<PropertyId, ModuleNameRecord, RecyclerLeafAllocator, PowerOf2SizePolicy> UnambiguousExportMap;
  13. typedef JsUtil::BaseDictionary<const PropertyRecord*, SimpleDictionaryPropertyDescriptor<BigPropertyIndex>, RecyclerNonLeafAllocator,
  14. DictionarySizePolicy<PowerOf2Policy, 1>, PropertyRecordStringHashComparer, PropertyMapKeyTraits<const PropertyRecord*>::template Entry>
  15. SimplePropertyDescriptorMap;
  16. protected:
  17. DEFINE_VTABLE_CTOR(ModuleNamespace, DynamicObject);
  18. DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(ModuleNamespace);
  19. protected:
  20. ModuleNamespace(ModuleRecordBase* moduleRecord, DynamicType * type);
  21. static ModuleNamespace* New(ModuleRecordBase* moduleRecord);
  22. public:
  23. class EntryInfo
  24. {
  25. };
  26. static ModuleNamespace* GetModuleNamespace(ModuleRecordBase* moduleRecord);
  27. void Initialize();
  28. ListForListIterator* GetSortedExportedNames() { return this->sortedExportedNames; }
  29. static bool Is(Var aValue) { return JavascriptOperators::GetTypeId(aValue) == TypeIds_ModuleNamespace; }
  30. static ModuleNamespace* FromVar(Var obj) { AssertOrFailFast(JavascriptOperators::GetTypeId(obj) == TypeIds_ModuleNamespace); return static_cast<ModuleNamespace*>(obj); }
  31. virtual PropertyId GetPropertyId(BigPropertyIndex index) override;
  32. virtual PropertyQueryFlags HasPropertyQuery(PropertyId propertyId) override;
  33. virtual BOOL HasOwnProperty(PropertyId propertyId) override;
  34. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  35. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, JavascriptString* propertyNameString, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  36. virtual BOOL GetInternalProperty(Var instance, PropertyId internalPropertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  37. virtual PropertyQueryFlags GetPropertyReferenceQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  38. virtual BOOL SetProperty(PropertyId propertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override { return FALSE; }
  39. virtual BOOL SetProperty(JavascriptString* propertyNameString, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override { return FALSE; }
  40. virtual BOOL SetInternalProperty(PropertyId internalPropertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override { return FALSE; }
  41. virtual DescriptorFlags GetSetter(PropertyId propertyId, Var *setterValue, PropertyValueInfo* info, ScriptContext* requestContext) override { return DescriptorFlags::None; }
  42. virtual DescriptorFlags GetSetter(JavascriptString* propertyNameString, Var *setterValue, PropertyValueInfo* info, ScriptContext* requestContext) override { return DescriptorFlags::None; }
  43. virtual BOOL InitProperty(PropertyId propertyId, Var value, PropertyOperationFlags flags = PropertyOperation_None, PropertyValueInfo* info = nullptr) override { Assert(false); return FALSE; }
  44. virtual BOOL SetPropertyWithAttributes(PropertyId propertyId, Var value, PropertyAttributes attributes, PropertyValueInfo* info, PropertyOperationFlags flags = PropertyOperation_None, SideEffects possibleSideEffects = SideEffects_Any) override { return false; }
  45. virtual BOOL DeleteProperty(PropertyId propertyId, PropertyOperationFlags flags) override;
  46. virtual BOOL DeleteProperty(JavascriptString *propertyNameString, PropertyOperationFlags flags) override;
  47. #if ENABLE_FIXED_FIELDS
  48. virtual BOOL IsFixedProperty(PropertyId propertyId) override { return false; }
  49. #endif
  50. virtual PropertyQueryFlags HasItemQuery(uint32 index) override { return PropertyQueryFlags::Property_NotFound; }
  51. virtual BOOL HasOwnItem(uint32 index) override { return false; }
  52. virtual PropertyQueryFlags GetItemQuery(Var originalInstance, uint32 index, Var* value, ScriptContext * requestContext) override { return PropertyQueryFlags::Property_NotFound; }
  53. virtual PropertyQueryFlags GetItemReferenceQuery(Var originalInstance, uint32 index, Var* value, ScriptContext * requestContext) override { return PropertyQueryFlags::Property_NotFound; }
  54. virtual DescriptorFlags GetItemSetter(uint32 index, Var* setterValue, ScriptContext* requestContext) override { *setterValue = nullptr; return DescriptorFlags::None; }
  55. virtual BOOL SetItem(uint32 index, Var value, PropertyOperationFlags flags) override { return false; }
  56. virtual BOOL DeleteItem(uint32 index, PropertyOperationFlags flags) override { return true; }
  57. virtual BOOL GetEnumerator(JavascriptStaticEnumerator * enumerator, EnumeratorFlags flags, ScriptContext* requestContext, EnumeratorCache * enumeratorCache = nullptr);
  58. virtual BOOL SetAccessors(PropertyId propertyId, Var getter, Var setter, PropertyOperationFlags flags = PropertyOperation_None) override { return false; }
  59. virtual BOOL GetAccessors(PropertyId propertyId, Var *getter, Var *setter, ScriptContext * requestContext) override { return false; }
  60. virtual BOOL IsWritable(PropertyId propertyId) override;
  61. virtual BOOL IsConfigurable(PropertyId propertyId) override;
  62. virtual BOOL IsEnumerable(PropertyId propertyId) override;
  63. virtual BOOL SetEnumerable(PropertyId propertyId, BOOL value) override { return false; }
  64. virtual BOOL SetWritable(PropertyId propertyId, BOOL value) override { return false; }
  65. virtual BOOL IsProtoImmutable() const { return true; }
  66. virtual BOOL SetConfigurable(PropertyId propertyId, BOOL value) override { return false; }
  67. virtual BOOL SetAttributes(PropertyId propertyId, PropertyAttributes attributes) override { return false; }
  68. virtual BOOL IsExtensible() override { return false; };
  69. virtual BOOL PreventExtensions() override { return true; }
  70. virtual BOOL Seal() override { return false; }
  71. virtual BOOL Freeze() override { return false; }
  72. virtual BOOL IsSealed() override { return true; }
  73. virtual BOOL IsFrozen() override { return true; }
  74. virtual BOOL GetDiagValueString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext) override;
  75. virtual BOOL GetDiagTypeString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext) override;
  76. virtual void RemoveFromPrototype(ScriptContext * requestContext) override { Assert(false); }
  77. virtual void AddToPrototype(ScriptContext * requestContext) override { Assert(false); }
  78. virtual void SetPrototype(RecyclableObject* newPrototype) override { Assert(false); return; }
  79. private:
  80. Field(ModuleRecordBase*) moduleRecord;
  81. Field(UnambiguousExportMap*) unambiguousNonLocalExports;
  82. Field(SimplePropertyDescriptorMap*) propertyMap; // local exports.
  83. Field(ListForListIterator*) sortedExportedNames; // sorted exported names for both local and indirect exports; excludes symbols.
  84. Field(Field(Var)*) nsSlots;
  85. void SetNSSlotsForModuleNS(Field(Var)* nsSlot) { this->nsSlots = nsSlot; }
  86. Var GetNSSlot(BigPropertyIndex propertyIndex);
  87. void AddUnambiguousNonLocalExport(PropertyId exportId, ModuleNameRecord* nonLocalExportNameRecord);
  88. UnambiguousExportMap* GetUnambiguousNonLocalExports() const { return unambiguousNonLocalExports; }
  89. // Methods used by NamespaceEnumerator;
  90. BOOL FindNextProperty(BigPropertyIndex& index, JavascriptString** propertyString, PropertyId* propertyId, PropertyAttributes* attributes, ScriptContext * requestContext) const;
  91. };
  92. }