BoundFunction.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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::FromVar(func)->IsBoundFunction(); }
  23. static Var NewInstance(RecyclableObject* function, CallInfo callInfo, ...);
  24. virtual JavascriptString* GetDisplayNameImpl() const override;
  25. virtual BOOL HasProperty(PropertyId propertyId) override;
  26. virtual BOOL GetProperty(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  27. virtual BOOL GetProperty(Var originalInstance, JavascriptString* propertyNameString, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) override;
  28. virtual BOOL GetPropertyReference(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 IsWritable(PropertyId propertyId) override;
  37. virtual BOOL IsConfigurable(PropertyId propertyId) override;
  38. virtual BOOL IsEnumerable(PropertyId propertyId) override;
  39. virtual BOOL HasInstance(Var instance, ScriptContext* scriptContext, IsInstInlineCache* inlineCache = NULL) override;
  40. virtual inline BOOL IsConstructor() const override;
  41. // Below functions are used by debugger to identify and emit event handler information
  42. virtual bool IsBoundFunction() const { return true; }
  43. JavascriptFunction * GetTargetFunction() const;
  44. // Below functions are used by heap enumerator
  45. uint GetArgsCountForHeapEnum() { return count;}
  46. Var* GetArgsForHeapEnum() { return boundArgs;}
  47. RecyclableObject* GetBoundThis();
  48. private:
  49. static FunctionInfo functionInfo;
  50. RecyclableObject* targetFunction;
  51. Var boundThis;
  52. uint count;
  53. Var* boundArgs;
  54. };
  55. } // namespace Js