JavascriptVariantDate.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. // Currently only used to implement Date.prototype.getVarDate
  9. // If there are other MS specific extensions that return variants,
  10. // this class could be renamed and updated to support other VT_* types,
  11. // or relevant functionality could be moved to a base class to inherit from.
  12. class JavascriptVariantDate : public RecyclableObject
  13. {
  14. private:
  15. Field(double) value; // the double form of the value of a VT_DATE variant.
  16. static JavascriptString* ConvertVariantDateToStr(
  17. double dbl,
  18. ScriptContext* scriptContext);
  19. protected:
  20. DEFINE_VTABLE_CTOR(JavascriptVariantDate, RecyclableObject);
  21. public:
  22. JavascriptVariantDate(const double val, StaticType * type) : value(val), RecyclableObject(type) { }
  23. // Used for making function calls to external objects requiring string params.
  24. JavascriptString* GetValueString(ScriptContext* scriptContext);
  25. double GetValue() { return value; }
  26. virtual BOOL Equals(Var other, BOOL* value, ScriptContext * requestContext) override;
  27. virtual PropertyQueryFlags HasPropertyQuery(Js::PropertyId propertyId, _Inout_opt_ PropertyValueInfo* info) override { return PropertyQueryFlags::Property_NotFound; };
  28. virtual PropertyQueryFlags GetPropertyQuery(Js::Var originalInstance, Js::PropertyId propertyId, Js::Var* value, Js::PropertyValueInfo* info, Js::ScriptContext* requestContext) override;
  29. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, JavascriptString* propertyNameString, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  30. virtual PropertyQueryFlags GetPropertyReferenceQuery(Js::Var originalInstance, Js::PropertyId propertyId, Js::Var* value, Js::PropertyValueInfo* info, Js::ScriptContext* requestContext) override;
  31. virtual BOOL SetProperty(Js::PropertyId propertyId, Js::Var value, Js::PropertyOperationFlags flags, Js::PropertyValueInfo* info) override;
  32. virtual BOOL SetProperty(Js::JavascriptString* propertyNameString, Js::Var value, Js::PropertyOperationFlags flags, Js::PropertyValueInfo* info) override;
  33. virtual BOOL InitProperty(Js::PropertyId propertyId, Js::Var value, PropertyOperationFlags flags = PropertyOperation_None, Js::PropertyValueInfo* info = NULL) override;
  34. virtual BOOL DeleteProperty(Js::PropertyId propertyId, Js::PropertyOperationFlags flags) override;
  35. virtual BOOL DeleteProperty(JavascriptString *propertyNameString, Js::PropertyOperationFlags flags) override;
  36. virtual PropertyQueryFlags HasItemQuery(uint32 index) override { return PropertyQueryFlags::Property_NotFound; }
  37. virtual PropertyQueryFlags GetItemReferenceQuery(Js::Var originalInstance, uint32 index, Js::Var* value, Js::ScriptContext * scriptContext) override;
  38. virtual PropertyQueryFlags GetItemQuery(Js::Var originalInstance, uint32 index, Js::Var* value, Js::ScriptContext * scriptContext) override;
  39. virtual BOOL SetItem(uint32 index, Js::Var value, Js::PropertyOperationFlags flags) override;
  40. virtual BOOL GetDiagValueString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext) override;
  41. virtual BOOL GetDiagTypeString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext) override;
  42. virtual BOOL ToPrimitive(JavascriptHint hint, Var* result, ScriptContext * requestContext) override;
  43. virtual Var GetTypeOfString(ScriptContext * requestContext) override;
  44. virtual RecyclableObject * CloneToScriptContext(ScriptContext* requestContext) override;
  45. virtual RecyclableObject* ToObject(ScriptContext* requestContext) override;
  46. };
  47. template <> inline bool VarIsImpl<JavascriptVariantDate>(RecyclableObject* obj)
  48. {
  49. return JavascriptOperators::GetTypeId(obj) == TypeIds_VariantDate;
  50. }
  51. }