Molybden API
Loading...
Searching...
No Matches
js_object.hpp
1// Copyright (c) 2000-2023 TeamDev Ltd. All rights reserved.
2// TeamDev PROPRIETARY and CONFIDENTIAL.
3// Use is subject to license terms.
4
5#ifndef MOLYBDEN_JS_OBJECT_HPP
6#define MOLYBDEN_JS_OBJECT_HPP
7
8#include <vector>
9
10#include "molybden/js/js_return_value.hpp"
11
12namespace molybden {
13
14class Frame;
15class JsObjectImpl;
16
26class JsObject : public std::enable_shared_from_this<JsObject> {
27 public:
28 using Private = JsObjectImpl;
29
30 explicit JsObject(std::unique_ptr<Private> impl);
31
36 std::shared_ptr<molybden::Frame> frame();
37
44 template <class T>
45 std::shared_ptr<T> as();
46
79 template <class... T>
80 JsReturnValue call(const std::string& method_name, T&&... args);
81
109 template <class T>
110 bool putProperty(const std::string& name, T&& value);
111
121 bool removeProperty(const std::string& name);
122
127 JsValue getProperty(const std::string& name);
128
133 std::vector<std::string> propertyNames();
134
139 std::vector<std::string> ownPropertyNames();
140
145 bool hasProperty(const std::string& name);
146
147 virtual ~JsObject();
148
149 protected:
150 std::unique_ptr<Private> impl_;
151
152 private:
153 bool putPropertyValue(const std::string& name, const JsValue& value);
154 JsReturnValue call(const std::string& method_name,
155 const std::vector<JsValue>& args);
156};
157
158} // namespace molybden
159
160#endif // MOLYBDEN_JS_OBJECT_HPP
A JavaScript object.
Definition js_object.hpp:26
std::vector< std::string > propertyNames()
Returns an immutable list of the names of the properties of this JavaScript object,...
JsValue getProperty(const std::string &name)
Returns the value of the JavaScript object's property with the given name.
bool hasProperty(const std::string &name)
Checks whether the JavaScript object has a property or function with the given name.
JsReturnValue call(const std::string &method_name, T &&... args)
Executes the method with the given method_name and the args in the JavaScript object.
Definition js_object_detail.hpp:23
std::shared_ptr< T > as()
Returns the shared pointer of type T to this object if it represents one, or nullptr otherwise.
Definition js_object_detail.hpp:13
bool putProperty(const std::string &name, T &&value)
Creates a new property with the given name or updates the existing one in the current JavaScript obje...
Definition js_object_detail.hpp:28
std::shared_ptr< molybden::Frame > frame()
Returns the shared pointer to the Frame instance of this JavaScript object.
bool removeProperty(const std::string &name)
Removes a property with the given name in the JavaScript object and returns true if the property was ...
std::vector< std::string > ownPropertyNames()
Returns an immutable list of the names of the properties of this JavaScript object,...
Represents the JS function return value.
Definition js_return_value.hpp:35
A JavaScript value.
Definition js_value.hpp:44