2
0

ModuleNamespace.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. virtual PropertyId GetPropertyId(BigPropertyIndex index) override;
  30. virtual PropertyQueryFlags HasPropertyQuery(PropertyId propertyId, _Inout_opt_ PropertyValueInfo* info) override;
  31. virtual BOOL HasOwnProperty(PropertyId propertyId) override;
  32. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  33. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, JavascriptString* propertyNameString, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  34. virtual BOOL GetInternalProperty(Var instance, PropertyId internalPropertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  35. virtual PropertyQueryFlags GetPropertyReferenceQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  36. virtual BOOL SetProperty(PropertyId propertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override { return FALSE; }
  37. virtual BOOL SetProperty(JavascriptString* propertyNameString, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override { return FALSE; }
  38. virtual BOOL SetInternalProperty(PropertyId internalPropertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override { return FALSE; }
  39. virtual DescriptorFlags GetSetter(PropertyId propertyId, Var *setterValue, PropertyValueInfo* info, ScriptContext* requestContext) override { return DescriptorFlags::None; }
  40. virtual DescriptorFlags GetSetter(JavascriptString* propertyNameString, Var *setterValue, PropertyValueInfo* info, ScriptContext* requestContext) override { return DescriptorFlags::None; }
  41. virtual BOOL InitProperty(PropertyId propertyId, Var value, PropertyOperationFlags flags = PropertyOperation_None, PropertyValueInfo* info = nullptr) override { Assert(false); return FALSE; }
  42. virtual BOOL SetPropertyWithAttributes(PropertyId propertyId, Var value, PropertyAttributes attributes, PropertyValueInfo* info, PropertyOperationFlags flags = PropertyOperation_None, SideEffects possibleSideEffects = SideEffects_Any) override { return false; }
  43. virtual BOOL DeleteProperty(PropertyId propertyId, PropertyOperationFlags flags) override;
  44. virtual BOOL DeleteProperty(JavascriptString *propertyNameString, PropertyOperationFlags flags) override;
  45. #if ENABLE_FIXED_FIELDS
  46. virtual BOOL IsFixedProperty(PropertyId propertyId) override { return false; }
  47. #endif
  48. virtual PropertyQueryFlags HasItemQuery(uint32 index) override { return PropertyQueryFlags::Property_NotFound; }
  49. virtual BOOL HasOwnItem(uint32 index) override { return false; }
  50. virtual PropertyQueryFlags GetItemQuery(Var originalInstance, uint32 index, Var* value, ScriptContext * requestContext) override { return PropertyQueryFlags::Property_NotFound; }
  51. virtual PropertyQueryFlags GetItemReferenceQuery(Var originalInstance, uint32 index, Var* value, ScriptContext * requestContext) override { return PropertyQueryFlags::Property_NotFound; }
  52. virtual DescriptorFlags GetItemSetter(uint32 index, Var* setterValue, ScriptContext* requestContext) override { *setterValue = nullptr; return DescriptorFlags::None; }
  53. virtual BOOL SetItem(uint32 index, Var value, PropertyOperationFlags flags) override { return false; }
  54. virtual BOOL DeleteItem(uint32 index, PropertyOperationFlags flags) override { return true; }
  55. virtual BOOL GetEnumerator(JavascriptStaticEnumerator * enumerator, EnumeratorFlags flags, ScriptContext* requestContext, EnumeratorCache * enumeratorCache = nullptr);
  56. virtual BOOL SetAccessors(PropertyId propertyId, Var getter, Var setter, PropertyOperationFlags flags = PropertyOperation_None) override { return false; }
  57. _Check_return_ _Success_(return) virtual BOOL GetAccessors(PropertyId propertyId, _Outptr_result_maybenull_ Var* getter, _Outptr_result_maybenull_ Var* setter, ScriptContext* requestContext) override { return FALSE; };
  58. virtual BOOL IsWritable(PropertyId propertyId) override;
  59. virtual BOOL IsConfigurable(PropertyId propertyId) override;
  60. virtual BOOL IsEnumerable(PropertyId propertyId) override;
  61. virtual BOOL SetEnumerable(PropertyId propertyId, BOOL value) override { return false; }
  62. virtual BOOL SetWritable(PropertyId propertyId, BOOL value) override { return false; }
  63. virtual BOOL IsProtoImmutable() const { return true; }
  64. virtual BOOL SetConfigurable(PropertyId propertyId, BOOL value) override { return false; }
  65. virtual BOOL SetAttributes(PropertyId propertyId, PropertyAttributes attributes) override { return false; }
  66. virtual BOOL IsExtensible() override { return false; };
  67. virtual BOOL PreventExtensions() override { return true; }
  68. virtual BOOL Seal() override { return false; }
  69. virtual BOOL Freeze() override { return false; }
  70. virtual BOOL IsSealed() override { return true; }
  71. virtual BOOL IsFrozen() override { return true; }
  72. virtual BOOL GetDiagValueString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext) override;
  73. virtual BOOL GetDiagTypeString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext) override;
  74. virtual void RemoveFromPrototype(ScriptContext * requestContext, bool * allProtoCachesInvalidated) override { Assert(false); }
  75. virtual void AddToPrototype(ScriptContext * requestContext, bool * allProtoCachesInvalidated) override { Assert(false); }
  76. virtual void SetPrototype(RecyclableObject* newPrototype) override { Assert(false); return; }
  77. private:
  78. Field(ModuleRecordBase*) moduleRecord;
  79. Field(UnambiguousExportMap*) unambiguousNonLocalExports;
  80. Field(SimplePropertyDescriptorMap*) propertyMap; // local exports.
  81. Field(ListForListIterator*) sortedExportedNames; // sorted exported names for both local and indirect exports; excludes symbols.
  82. Field(Field(Var)*) nsSlots;
  83. void SetNSSlotsForModuleNS(Field(Var)* nsSlot) { this->nsSlots = nsSlot; }
  84. Var GetNSSlot(BigPropertyIndex propertyIndex);
  85. void AddUnambiguousNonLocalExport(PropertyId exportId, ModuleNameRecord* nonLocalExportNameRecord);
  86. UnambiguousExportMap* GetUnambiguousNonLocalExports() const { return unambiguousNonLocalExports; }
  87. // Methods used by NamespaceEnumerator;
  88. BOOL FindNextProperty(BigPropertyIndex& index, JavascriptString** propertyString, PropertyId* propertyId, PropertyAttributes* attributes, ScriptContext * requestContext) const;
  89. };
  90. template <> inline bool VarIsImpl<ModuleNamespace>(RecyclableObject* obj)
  91. {
  92. return JavascriptOperators::GetTypeId(obj) == TypeIds_ModuleNamespace;
  93. }
  94. }