Molybden API
Loading...
Searching...
No Matches
js_proxy_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_OBJECT_HPP
6#define MOLYBDEN_JS_PROXY_OBJECT_HPP
7
8#include <vector>
9
10#include "molybden/js/js_return_value.hpp"
11
12namespace molybden {
13
14namespace internal {
15
16class ProxyObjectType;
17template <class T>
18class JsProxyObjectRoot;
19
20} // namespace internal
21
49class JsProxyObject : public std::enable_shared_from_this<JsProxyObject> {
50 public:
77 template <class T>
78 std::shared_ptr<T> as();
79
96 virtual JsReturnValue call(const std::string& method_name,
97 const std::vector<JsValue>& args) = 0;
98
106 virtual JsValue getProperty(const std::string& property_name) = 0;
107
117 virtual bool setProperty(const std::string& property_name,
118 const JsValue& value) = 0;
119
130 virtual bool hasMethod(const std::string& method_name) = 0;
131
141 virtual bool hasProperty(const std::string& property_name) = 0;
142
148 virtual std::string getType() = 0;
149
156 virtual std::vector<std::string> enumerateMembers() = 0;
157
158 virtual ~JsProxyObject() = default;
159
160 private:
161 virtual internal::ProxyObjectType* proxyType() = 0;
162};
163
170template <class C>
172 private:
173 // JsProxyObject
174 internal::ProxyObjectType* proxyType() final;
175};
176
177} // namespace molybden
178
179#endif // MOLYBDEN_JS_PROXY_OBJECT_HPP
A JavaScript proxy object.
Definition js_proxy_object.hpp:49
virtual std::string getType()=0
Called when the JavaScript engine requests the proxy object type name.
virtual bool hasMethod(const std::string &method_name)=0
Called when the JavaScript engine requests whether the proxy object has the method with method_name.
virtual std::vector< std::string > enumerateMembers()=0
Called when the JavaScript engine requests all the members of the proxy object.
std::shared_ptr< T > as()
Downcasts the object to the appropriate proxy type.
Definition js_proxy_object_detail.hpp:173
virtual JsValue getProperty(const std::string &property_name)=0
Called when the JavaScript proxy object property with property_name has been accessed to read.
virtual bool hasProperty(const std::string &property_name)=0
Called when the JavaScript engine requests whether the proxy object has the property with property_na...
virtual JsReturnValue call(const std::string &method_name, const std::vector< JsValue > &args)=0
Called when the JavaScript proxy object method with method_name has been called in the corresponding ...
virtual bool setProperty(const std::string &property_name, const JsValue &value)=0
Called when the JavaScript proxy object property with property_name has been accessed to write.
Derive C from JsProxyObjectImpl<C> via CRTP pattern and implement the interface of JsProxyObject.
Definition js_proxy_object.hpp:171
Represents the JS function return value.
Definition js_return_value.hpp:35
A JavaScript value.
Definition js_value.hpp:44