ES5Array.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. namespace Js
  6. {
  7. class ES5ArrayType : public DynamicType
  8. {
  9. friend class ES5Array;
  10. protected:
  11. ES5ArrayType(DynamicType * type);
  12. };
  13. }
  14. AUTO_REGISTER_RECYCLER_OBJECT_DUMPER(Js::ES5ArrayType, &Js::RecyclableObject::DumpObjectFunction);
  15. namespace Js
  16. {
  17. //
  18. // ES5Array supports attribute/getter/setter for index property names.
  19. //
  20. // This implementation depends on v-table swapping so that a normal JavascriptArray instance can be
  21. // converted to an ES5Array at runtime when ES5 attribute/getter/setter support is needed. As a result,
  22. // this class can't add any new fields to JavascriptArray. The extra index attribute/getter/setter info
  23. // are maintained in the private ES5ArrayTypeHandler.
  24. //
  25. // ES5Array does not reimplement Array.prototype methods. It depends on JavascriptArray implementations
  26. // to go through generic object route as ES5Array has a new TypeId and is treated as an object.
  27. //
  28. class ES5Array : public JavascriptArray
  29. {
  30. protected:
  31. DEFINE_VTABLE_CTOR(ES5Array, JavascriptArray);
  32. DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(ES5Array);
  33. private:
  34. bool GetPropertyBuiltIns(PropertyId propertyId, Var* value, BOOL* result);
  35. bool SetPropertyBuiltIns(PropertyId propertyId, Var value, PropertyOperationFlags flags, BOOL* result);
  36. bool GetSetterBuiltIns(PropertyId propertyId, PropertyValueInfo* info, DescriptorFlags* result);
  37. public:
  38. static uint32 ToLengthValue(Var value, ScriptContext* scriptContext);
  39. bool IsLengthWritable() const;
  40. virtual DynamicType* DuplicateType() override;
  41. // Enumerate
  42. BOOL IsValidDescriptorToken(void * descriptorValidationToken) const;
  43. uint32 GetNextDescriptor(uint32 key, IndexPropertyDescriptor** descriptor, void ** descriptorValidationToken);
  44. BOOL GetDescriptor(uint32 index, Js::IndexPropertyDescriptor **ppDescriptor);
  45. //
  46. // To skip JavascriptArray overrides
  47. //
  48. virtual PropertyQueryFlags HasPropertyQuery(PropertyId propertyId, _Inout_opt_ PropertyValueInfo* info) override;
  49. virtual BOOL IsWritable(PropertyId propertyId) override;
  50. virtual BOOL SetEnumerable(PropertyId propertyId, BOOL value) override;
  51. virtual BOOL SetWritable(PropertyId propertyId, BOOL value) override;
  52. virtual BOOL SetConfigurable(PropertyId propertyId, BOOL value) override;
  53. virtual BOOL SetAttributes(PropertyId propertyId, PropertyAttributes attributes) override;
  54. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  55. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, JavascriptString* propertyNameString, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  56. virtual PropertyQueryFlags GetPropertyReferenceQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  57. virtual BOOL SetProperty(PropertyId propertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override;
  58. virtual BOOL SetProperty(JavascriptString* propertyNameString, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override;
  59. virtual BOOL SetPropertyWithAttributes(PropertyId propertyId, Var value, PropertyAttributes attributes, PropertyValueInfo* info, PropertyOperationFlags flags = PropertyOperation_None, SideEffects possibleSideEffects = SideEffects_Any) override;
  60. virtual PropertyQueryFlags HasItemQuery(uint32 index) override;
  61. virtual PropertyQueryFlags GetItemQuery(Var originalInstance, uint32 index, Var* value, ScriptContext * requestContext) override;
  62. virtual PropertyQueryFlags GetItemReferenceQuery(Var originalInstance, uint32 index, Var* value, ScriptContext * requestContext) override;
  63. virtual BOOL SetItem(uint32 index, Var value, PropertyOperationFlags flags) override;
  64. virtual BOOL DeleteItem(uint32 index, PropertyOperationFlags flags) override;
  65. virtual DescriptorFlags GetSetter(PropertyId propertyId, Var *setterValue, PropertyValueInfo* info, ScriptContext* requestContext) override;
  66. virtual DescriptorFlags GetSetter(JavascriptString* propertyNameString, Var *setterValue, PropertyValueInfo* info, ScriptContext* requestContext) override;
  67. virtual DescriptorFlags GetItemSetter(uint32 index, Var* setterValue, ScriptContext* requestContext) override;
  68. virtual BOOL SetAccessors(PropertyId propertyId, Var getter, Var setter, PropertyOperationFlags flags) override;
  69. virtual BOOL PreventExtensions() override;
  70. virtual BOOL Seal() override;
  71. virtual BOOL Freeze() override;
  72. virtual BOOL GetEnumerator(JavascriptStaticEnumerator * enumerator, EnumeratorFlags flags, ScriptContext* requestContext, EnumeratorCache * enumeratorCache = nullptr) override;
  73. // objectArray support
  74. virtual BOOL SetItemWithAttributes(uint32 index, Var value, PropertyAttributes attributes) override;
  75. virtual BOOL SetItemAttributes(uint32 index, PropertyAttributes attributes) override;
  76. virtual BOOL SetItemAccessors(uint32 index, Var getter, Var setter) override;
  77. virtual BOOL IsObjectArrayFrozen() override;
  78. virtual JavascriptEnumerator * GetIndexEnumerator(EnumeratorFlags flags, ScriptContext* requestContext) override;
  79. // for SCA
  80. virtual BOOL IsItemEnumerable(uint32 index) override;
  81. #if ENABLE_TTD
  82. public:
  83. virtual void MarkVisitKindSpecificPtrs(TTD::SnapshotExtractor* extractor) override;
  84. virtual TTD::NSSnapObjects::SnapObjectType GetSnapTag_TTD() const override;
  85. virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override;
  86. #endif
  87. };
  88. template <> inline bool VarIsImpl<ES5Array>(RecyclableObject* instance)
  89. {
  90. return JavascriptOperators::GetTypeId(instance) == TypeIds_ES5Array;
  91. }
  92. }
  93. AUTO_REGISTER_RECYCLER_OBJECT_DUMPER(Js::ES5Array, &Js::RecyclableObject::DumpObjectFunction);