BoundFunction.h 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 BoundFunction : public JavascriptFunction
  9. {
  10. protected:
  11. DEFINE_VTABLE_CTOR(BoundFunction, JavascriptFunction);
  12. DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(BoundFunction);
  13. private:
  14. bool GetPropertyBuiltIns(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext, BOOL* result);
  15. bool SetPropertyBuiltIns(PropertyId propertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info, BOOL* result);
  16. protected:
  17. BoundFunction(DynamicType * type);
  18. BoundFunction(Arguments args, DynamicType * type);
  19. BoundFunction(RecyclableObject* targetFunction, Var boundThis, Var* args, uint argsCount, DynamicType *type);
  20. public:
  21. static BoundFunction* New(ScriptContext* scriptContext, ArgumentReader args);
  22. static bool Is(Var func){ return JavascriptFunction::Is(func) && JavascriptFunction::UnsafeFromVar(func)->IsBoundFunction(); }
  23. static Var NewInstance(RecyclableObject* function, CallInfo callInfo, ...);
  24. virtual JavascriptString* GetDisplayNameImpl() const override;
  25. virtual PropertyQueryFlags HasPropertyQuery(PropertyId propertyId) override;
  26. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  27. virtual PropertyQueryFlags GetPropertyQuery(Var originalInstance, JavascriptString* propertyNameString, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  28. virtual PropertyQueryFlags GetPropertyReferenceQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  29. virtual BOOL SetProperty(PropertyId propertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override;
  30. virtual BOOL SetProperty(JavascriptString* propertyNameString, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override;
  31. virtual BOOL GetAccessors(PropertyId propertyId, Var *getter, Var *setter, ScriptContext * requestContext) override;
  32. virtual DescriptorFlags GetSetter(PropertyId propertyId, Var *setterValue, PropertyValueInfo* info, ScriptContext* requestContext) override;
  33. virtual DescriptorFlags GetSetter(JavascriptString* propertyNameString, Var *setterValue, PropertyValueInfo* info, ScriptContext* requestContext) override;
  34. virtual BOOL InitProperty(PropertyId propertyId, Var value, PropertyOperationFlags flags = PropertyOperation_None, PropertyValueInfo* info = NULL) override;
  35. virtual BOOL DeleteProperty(PropertyId propertyId, PropertyOperationFlags flags) override;
  36. virtual BOOL DeleteProperty(JavascriptString *propertyNameString, PropertyOperationFlags flags) override;
  37. virtual BOOL IsWritable(PropertyId propertyId) override;
  38. virtual BOOL IsConfigurable(PropertyId propertyId) override;
  39. virtual BOOL IsEnumerable(PropertyId propertyId) override;
  40. virtual BOOL HasInstance(Var instance, ScriptContext* scriptContext, IsInstInlineCache* inlineCache = NULL) override;
  41. virtual inline BOOL IsConstructor() const override;
  42. // Below functions are used by debugger to identify and emit event handler information
  43. virtual bool IsBoundFunction() const { return true; }
  44. JavascriptFunction * GetTargetFunction() const;
  45. // Below functions are used by heap enumerator
  46. uint GetArgsCountForHeapEnum() { return count;}
  47. Field(Var)* GetArgsForHeapEnum() { return boundArgs;}
  48. RecyclableObject* GetBoundThis();
  49. #if ENABLE_TTD
  50. public:
  51. virtual void MarkVisitKindSpecificPtrs(TTD::SnapshotExtractor* extractor) override;
  52. virtual void ProcessCorePaths() override;
  53. virtual TTD::NSSnapObjects::SnapObjectType GetSnapTag_TTD() const override;
  54. virtual void ExtractSnapObjectDataInto(TTD::NSSnapObjects::SnapObject* objData, TTD::SlabAllocator& alloc) override;
  55. static BoundFunction* InflateBoundFunction(
  56. ScriptContext* ctx, RecyclableObject* function, Var bThis, uint32 ct, Field(Var)* args);
  57. #endif
  58. private:
  59. static FunctionInfo functionInfo;
  60. Field(RecyclableObject*) targetFunction;
  61. Field(Var) boundThis;
  62. Field(uint) count;
  63. Field(Field(Var)*) boundArgs;
  64. };
  65. } // namespace Js