State.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /****************************************************************************
  2. Copyright (c) 2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #pragma once
  22. #include "Value.hpp"
  23. namespace se {
  24. class Object;
  25. /**
  26. * State represents an environment while a function or an accesstor is invoked from JavaScript.
  27. */
  28. class State final
  29. {
  30. public:
  31. /**
  32. * @brief Gets void* pointer of `this` object's private data.
  33. * @return A void* pointer of `this` object's private data.
  34. */
  35. void* nativeThisObject() const;
  36. /**
  37. * @brief Gets the arguments of native binding functions or accesstors.
  38. * @return The arguments of native binding functions or accesstors.
  39. */
  40. const ValueArray& args() const;
  41. /**
  42. * @brief Gets the JavaScript `this` object wrapped in se::Object.
  43. * @return The JavaScript `this` object wrapped in se::Object.
  44. */
  45. Object* thisObject();
  46. /**
  47. * @brief Gets the return value reference. Used for setting return value for a function.
  48. * @return The return value reference.
  49. */
  50. Value& rval();
  51. // Private API used in wrapper
  52. /**
  53. * @brief
  54. * @param[in]
  55. * @return
  56. */
  57. State();
  58. /**
  59. * @brief
  60. * @param[in]
  61. * @return
  62. */
  63. ~State();
  64. /**
  65. * @brief
  66. * @param[in]
  67. * @return
  68. */
  69. State(void* nativeThisObject);
  70. /**
  71. * @brief
  72. * @param[in]
  73. * @return
  74. */
  75. State(void* nativeThisObject, const ValueArray& args);
  76. /**
  77. * @brief
  78. * @param[in]
  79. * @return
  80. */
  81. State(Object* thisObject, const ValueArray& args);
  82. private:
  83. // Disable copy/move constructor, copy/move assigment
  84. State(const State&);
  85. State(State&&);
  86. State& operator=(const State&);
  87. State& operator=(State&&);
  88. void* _nativeThisObject; //weak ref
  89. Object* _thisObject; //weak ref
  90. const ValueArray* _args; //weak ref
  91. Value _retVal; //weak ref
  92. };
  93. }