PropertyString.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #if ENABLE_TTD
  51. //Get the associated property id for this string if there is on (e.g. it is a propertystring otherwise return Js::PropertyIds::_none)
  52. virtual Js::PropertyId TryGetAssociatedPropertyId() const override { return this->propertyRecordUsageCache.GetPropertyRecord()->GetPropertyId(); }
  53. #endif
  54. public:
  55. virtual VTableValue DummyVirtualFunctionToHinderLinkerICF()
  56. {
  57. return VTableValue::VtablePropertyString;
  58. }
  59. };
  60. template <> bool VarIsImpl<PropertyString>(RecyclableObject * obj);
  61. } // namespace Js