PropertyString.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 PropertyString : public JavascriptString
  9. {
  10. protected:
  11. Field(PropertyRecordUsageCache) propertyRecordUsageCache;
  12. DEFINE_VTABLE_CTOR(PropertyString, JavascriptString);
  13. PropertyString(StaticType* type, const Js::PropertyRecord* propertyRecord);
  14. public:
  15. virtual void GetPropertyRecord(_Out_ PropertyRecord const** propertyRecord, bool dontLookupFromDictionary = false) override
  16. {
  17. *propertyRecord = this->propertyRecordUsageCache.GetPropertyRecord();
  18. }
  19. Js::PropertyId GetPropertyId()
  20. {
  21. return this->propertyRecordUsageCache.GetPropertyRecord()->GetPropertyId();
  22. }
  23. PolymorphicInlineCache * GetLdElemInlineCache() const;
  24. PolymorphicInlineCache * GetStElemInlineCache() const;
  25. PropertyRecordUsageCache * GetPropertyRecordUsageCache();
  26. bool TrySetPropertyFromCache(
  27. _In_ RecyclableObject *const object,
  28. _In_ Var propertyValue,
  29. _In_ ScriptContext *const requestContext,
  30. const PropertyOperationFlags propertyOperationFlags,
  31. _Inout_ PropertyValueInfo *const propertyValueInfo);
  32. template <
  33. bool OwnPropertyOnly,
  34. bool OutputExistence /*When set, propertyValue represents whether the property exists on the instance, not its actual value*/>
  35. bool TryGetPropertyFromCache(
  36. Var const instance,
  37. RecyclableObject *const object,
  38. Var *const propertyValue,
  39. ScriptContext *const requestContext,
  40. PropertyValueInfo *const propertyValueInfo)
  41. {
  42. return this->propertyRecordUsageCache.TryGetPropertyFromCache<OwnPropertyOnly, OutputExistence, false /* ReturnOperationInfo */>(instance, object, propertyValue, requestContext, propertyValueInfo, this, nullptr);
  43. }
  44. static PropertyString* New(StaticType* type, const Js::PropertyRecord* propertyRecord, Recycler *recycler);
  45. virtual void const * GetOriginalStringReference() override;
  46. virtual RecyclableObject * CloneToScriptContext(ScriptContext* requestContext) override;
  47. static uint32 GetOffsetOfLdElemInlineCache() { return offsetof(PropertyString, propertyRecordUsageCache) + PropertyRecordUsageCache::GetOffsetOfLdElemInlineCache(); }
  48. static uint32 GetOffsetOfStElemInlineCache() { return offsetof(PropertyString, propertyRecordUsageCache) + PropertyRecordUsageCache::GetOffsetOfStElemInlineCache(); }
  49. static uint32 GetOffsetOfHitRate() { return offsetof(PropertyString, propertyRecordUsageCache) + PropertyRecordUsageCache::GetOffsetOfHitRate(); }
  50. static bool Is(Var var);
  51. static bool Is(RecyclableObject * var);
  52. template <typename T> static PropertyString* TryFromVar(T var);
  53. static PropertyString* UnsafeFromVar(Var aValue);
  54. #if ENABLE_TTD
  55. //Get the associated property id for this string if there is on (e.g. it is a propertystring otherwise return Js::PropertyIds::_none)
  56. virtual Js::PropertyId TryGetAssociatedPropertyId() const override { return this->propertyRecordUsageCache.GetPropertyRecord()->GetPropertyId(); }
  57. #endif
  58. public:
  59. virtual VTableValue DummyVirtualFunctionToHinderLinkerICF()
  60. {
  61. return VTableValue::VtablePropertyString;
  62. }
  63. };
  64. // Templated so that the Is call dispatchs to different function depending
  65. // on if argument is already a RecyclableObject* or only known to be a Var
  66. //
  67. // In case it is known to be a RecyclableObject*, the Is call skips that check
  68. template <typename T> inline
  69. PropertyString * PropertyString::TryFromVar(T var)
  70. {
  71. return PropertyString::Is(var)
  72. ? reinterpret_cast<PropertyString*>(var)
  73. : nullptr;
  74. }
  75. } // namespace Js