Molybden API
Loading...
Searching...
No Matches
js_proxy_function_object.hpp
1// Copyright (c) 2000-2024 TeamDev. All rights reserved.
2// TeamDev PROPRIETARY and CONFIDENTIAL.
3// Use is subject to license terms
4
5#ifndef MOLYBDEN_JS_PROXY_FUNCTION_HPP
6#define MOLYBDEN_JS_PROXY_FUNCTION_HPP
7
8#include <functional>
9
10#include "molybden/js/js_accessible.hpp"
11
12namespace molybden {
13namespace internal {
14
15// Non-template base class is required for the internal runtime type
16// identification during conversion.
17class JsProxyFunctionObjectBase
18 : public JsAccessible<JsProxyFunctionObjectBase> {
19 public:
20 static constexpr char kInvokeMethodName[] = "Invoke";
21};
22
23template <class R, class... T>
24class JsProxyFunctionObject : public JsProxyFunctionObjectBase {
25 public:
26 explicit JsProxyFunctionObject(std::function<R(T...)> function)
27 : callback_(std::move(function)) {}
28
29 R Invoke(T... args) { return callback_(args...); }
30
31 private:
32 std::function<R(T...)> callback_;
33
34 private:
35 JS_ACCESSIBLE_METHOD(Invoke);
36};
37
38} // namespace internal
39} // namespace molybden
40
41#endif // MOLYBDEN_JS_PROXY_FUNCTION_HPP