ES5Array.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 bool Is(Var instance);
  39. static ES5Array* FromVar(Var instance);
  40. static ES5Array* UnsafeFromVar(Var instance);
  41. static uint32 ToLengthValue(Var value, ScriptContext* scriptContext);
  42. bool IsLengthWritable() const;
  43. virtual DynamicType* DuplicateType() override;
  44. // Enumerate
  45. BOOL IsValidDescriptorToken(void * descriptorValidationToken) const;
  46. uint32 GetNextDescriptor(uint32 key, IndexPropertyDescriptor** descriptor, void ** descriptorValidationToken);
  47. BOOL GetDescriptor(uint32 index, Js::IndexPropertyDescriptor **ppDescriptor);
  48. //
  49. // To skip JavascriptArray overrides
  50. //
  51. virtual PropertyQueryFlags HasPropertyQuery(PropertyId propertyId, _Inout_opt_ PropertyValueInfo* info) override;
  52. virtual BOOL IsWritable(PropertyId propertyId) override;
  53. virtual BOOL SetEnumerable(PropertyId propertyId, BOOL value) override;
  54. virtual BOOL SetWritable(PropertyId propertyId, BOOL value) override;
  55. virtual BOOL SetConfigurable(PropertyId propertyId, BOOL value) override;
  56. virtual BOOL SetAttributes(PropertyId propertyId, PropertyAttributes attributes) override;
  57. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  58. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, JavascriptString* propertyNameString, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  59. virtual PropertyQueryFlags GetPropertyReferenceQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  60. virtual BOOL SetProperty(PropertyId propertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override;
  61. virtual BOOL SetProperty(JavascriptString* propertyNameString, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override;
  62. virtual BOOL SetPropertyWithAttributes(PropertyId propertyId, Var value, PropertyAttributes attributes, PropertyValueInfo* info, PropertyOperationFlags flags = PropertyOperation_None, SideEffects possibleSideEffects = SideEffects_Any) override;
  63. virtual PropertyQueryFlags HasItemQuery(uint32 index) override;
  64. virtual PropertyQueryFlags GetItemQuery(Var originalInstance, uint32 index, Var* value, ScriptContext * requestContext) override;
  65. virtual PropertyQueryFlags GetItemReferenceQuery(Var originalInstance, uint32 index, Var* value, ScriptContext * requestContext) override;
  66. virtual BOOL SetItem(uint32 index, Var value, PropertyOperationFlags flags) override;
  67. virtual BOOL DeleteItem(uint32 index, PropertyOperationFlags flags) override;
  68. virtual DescriptorFlags GetSetter(PropertyId propertyId, Var *setterValue, PropertyValueInfo* info, ScriptContext* requestContext) override;
  69. virtual DescriptorFlags GetSetter(JavascriptString* propertyNameString, Var *setterValue, PropertyValueInfo* info, ScriptContext* requestContext) override;
  70. virtual DescriptorFlags GetItemSetter(uint32 index, Var* setterValue, ScriptContext* requestContext) override;
  71. virtual BOOL SetAccessors(PropertyId propertyId, Var getter, Var setter, PropertyOperationFlags flags) override;
  72. virtual BOOL PreventExtensions() override;
  73. virtual BOOL Seal() override;
  74. virtual BOOL Freeze() override;
  75. virtual BOOL GetEnumerator(JavascriptStaticEnumerator * enumerator, EnumeratorFlags flags, ScriptContext* requestContext, EnumeratorCache * enumeratorCache = nullptr) override;
  76. // objectArray support
  77. virtual BOOL SetItemWithAttributes(uint32 index, Var value, PropertyAttributes attributes) override;
  78. virtual BOOL SetItemAttributes(uint32 index, PropertyAttributes attributes) override;
  79. virtual BOOL SetItemAccessors(uint32 index, Var getter, Var setter) override;
  80. virtual BOOL IsObjectArrayFrozen() override;
  81. virtual JavascriptEnumerator * GetIndexEnumerator(EnumeratorFlags flags, ScriptContext* requestContext) override;
  82. // for SCA
  83. virtual BOOL IsItemEnumerable(uint32 index) override;
  84. #if ENABLE_TTD
  85. public:
  86. virtual void MarkVisitKindSpecificPtrs(TTD::SnapshotExtractor* extractor) override;
  87. virtual TTD::NSSnapObjects::SnapObjectType GetSnapTag_TTD() const override;
  88. virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override;
  89. #endif
  90. };
  91. }
  92. AUTO_REGISTER_RECYCLER_OBJECT_DUMPER(Js::ES5Array, &Js::RecyclableObject::DumpObjectFunction);