API documentation  2.0rc1
jsobject.h
1 /****************************************************************
2  *
3  * Copyright (C) 2016-2018 Alessandro Pignotti <alessandro@leaningtech.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  ***************************************************************/
20 
21 #ifndef _CHEERP_JSOBJECT_H_65a8f9e1
22 #define _CHEERP_JSOBJECT_H_65a8f9e1
23 
24 #include <type_traits>
25 
26 namespace [[cheerp::genericjs]] client
27 {
28 
29 class String;
30 class Array;
31 
32 class Object
33 {
34 private:
35  // Make it impossible to blindly copy a browser object
36  Object(const Object&) = delete;
37 public:
38  Object();
39  // valueOf may return different types, the users should specify which one is expected
40  template<typename T>
41  T valueOf();
42  operator double() const
43  {
44  return const_cast<Object*>(this)->valueOf<double>();
45  }
46  Object* operator[](const client::String& name) const;
47  // operator[] for arbitrary assignment can't be expressed as we can't have a pointer to an arbitrary member of an object
48  // We provide the following function instead
49  void set_(const client::String& name, Object* v);
50  template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
51  void set_(const client::String& name, T v);
52  bool hasOwnProperty(const client::String& name);
53  static Array* keys(Object*) [[cheerp::static]];
54  static Array* values(Object*) [[cheerp::static]];
55 };
56 
57 }
58 
59 #endif
Definition: jsobject.h:32
Definition: types.h:171
Definition: types.h:39
Definition: clientlib.h:27