1/*
2 * Copyright (C) 2018 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION) && !defined(WEBKIT2_COMPILATION)
21#error "Only <jsc/jsc.h> can be included directly."
22#endif
23
24#ifndef JSCValue_h
25#define JSCValue_h
26
27#include <glib-object.h>
28#include <jsc/JSCDefines.h>
29
30G_BEGIN_DECLS
31
32#define JSC_TYPE_VALUE (jsc_value_get_type())
33#define JSC_VALUE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), JSC_TYPE_VALUE, JSCValue))
34#define JSC_IS_VALUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), JSC_TYPE_VALUE))
35#define JSC_VALUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), JSC_TYPE_VALUE, JSCValueClass))
36#define JSC_IS_VALUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), JSC_TYPE_VALUE))
37#define JSC_VALUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), JSC_TYPE_VALUE, JSCValueClass))
38
39typedef struct _JSCValue JSCValue;
40typedef struct _JSCValueClass JSCValueClass;
41typedef struct _JSCValuePrivate JSCValuePrivate;
42
43typedef struct _JSCClass JSCClass;
44typedef struct _JSCContext JSCContext;
45
46typedef enum {
47 JSC_VALUE_PROPERTY_CONFIGURABLE = 1 << 0,
48 JSC_VALUE_PROPERTY_ENUMERABLE = 1 << 1,
49 JSC_VALUE_PROPERTY_WRITABLE = 1 << 2
50} JSCValuePropertyFlags;
51
52struct _JSCValue {
53 GObject parent;
54
55 /*< private >*/
56 JSCValuePrivate *priv;
57};
58
59struct _JSCValueClass {
60 GObjectClass parent_class;
61
62 void (*_jsc_reserved0) (void);
63 void (*_jsc_reserved1) (void);
64 void (*_jsc_reserved2) (void);
65 void (*_jsc_reserved3) (void);
66};
67
68JSC_API GType
69jsc_value_get_type (void);
70
71JSC_API JSCContext *
72jsc_value_get_context (JSCValue *value);
73
74JSC_API JSCValue *
75jsc_value_new_undefined (JSCContext *context);
76
77JSC_API gboolean
78jsc_value_is_undefined (JSCValue *value);
79
80JSC_API JSCValue *
81jsc_value_new_null (JSCContext *context);
82
83JSC_API gboolean
84jsc_value_is_null (JSCValue *value);
85
86JSC_API JSCValue *
87jsc_value_new_number (JSCContext *context,
88 double number);
89JSC_API gboolean
90jsc_value_is_number (JSCValue *value);
91
92JSC_API double
93jsc_value_to_double (JSCValue *value);
94
95JSC_API gint32
96jsc_value_to_int32 (JSCValue *value);
97
98JSC_API JSCValue *
99jsc_value_new_boolean (JSCContext *context,
100 gboolean value);
101JSC_API gboolean
102jsc_value_is_boolean (JSCValue *value);
103
104JSC_API gboolean
105jsc_value_to_boolean (JSCValue *value);
106
107JSC_API JSCValue *
108jsc_value_new_string (JSCContext *context,
109 const char *string);
110
111JSC_API JSCValue *
112jsc_value_new_string_from_bytes (JSCContext *context,
113 GBytes *bytes);
114
115JSC_API gboolean
116jsc_value_is_string (JSCValue *value);
117
118JSC_API char *
119jsc_value_to_string (JSCValue *value);
120
121JSC_API GBytes *
122jsc_value_to_string_as_bytes (JSCValue *value);
123
124JSC_API JSCValue *
125jsc_value_new_array (JSCContext *context,
126 GType first_item_type,
127 ...);
128
129JSC_API JSCValue *
130jsc_value_new_array_from_garray (JSCContext *context,
131 GPtrArray *array);
132
133JSC_API JSCValue *
134jsc_value_new_array_from_strv (JSCContext *context,
135 const char *const *strv);
136
137JSC_API gboolean
138jsc_value_is_array (JSCValue *value);
139
140JSC_API JSCValue *
141jsc_value_new_object (JSCContext *context,
142 gpointer instance,
143 JSCClass *jsc_class);
144
145JSC_API gboolean
146jsc_value_is_object (JSCValue *value);
147
148JSC_API gboolean
149jsc_value_object_is_instance_of (JSCValue *value,
150 const char *name);
151
152JSC_API void
153jsc_value_object_set_property (JSCValue *value,
154 const char *name,
155 JSCValue *property);
156
157JSC_API JSCValue *
158jsc_value_object_get_property (JSCValue *value,
159 const char *name);
160
161JSC_API void
162jsc_value_object_set_property_at_index (JSCValue *value,
163 guint index,
164 JSCValue *property);
165
166JSC_API JSCValue *
167jsc_value_object_get_property_at_index (JSCValue *value,
168 guint index);
169
170JSC_API gboolean
171jsc_value_object_has_property (JSCValue *value,
172 const char *name);
173
174JSC_API gboolean
175jsc_value_object_delete_property (JSCValue *value,
176 const char *name);
177
178JSC_API gchar **
179jsc_value_object_enumerate_properties (JSCValue *value);
180
181JSC_API JSCValue *
182jsc_value_object_invoke_method (JSCValue *value,
183 const char *name,
184 GType first_parameter_type,
185 ...) G_GNUC_WARN_UNUSED_RESULT;
186
187JSC_API JSCValue *
188jsc_value_object_invoke_methodv (JSCValue *value,
189 const char *name,
190 guint n_parameters,
191 JSCValue **parameters) G_GNUC_WARN_UNUSED_RESULT;
192
193JSC_API void
194jsc_value_object_define_property_data (JSCValue *value,
195 const char *property_name,
196 JSCValuePropertyFlags flags,
197 JSCValue *property_value);
198
199JSC_API void
200jsc_value_object_define_property_accessor (JSCValue *value,
201 const char *property_name,
202 JSCValuePropertyFlags flags,
203 GType property_type,
204 GCallback getter,
205 GCallback setter,
206 gpointer user_data,
207 GDestroyNotify destroy_notify);
208
209JSC_API JSCValue *
210jsc_value_new_function (JSCContext *context,
211 const char *name,
212 GCallback callback,
213 gpointer user_data,
214 GDestroyNotify destroy_notify,
215 GType return_type,
216 guint n_params,
217 ...);
218
219JSC_API JSCValue *
220jsc_value_new_functionv (JSCContext *context,
221 const char *name,
222 GCallback callback,
223 gpointer user_data,
224 GDestroyNotify destroy_notify,
225 GType return_type,
226 guint n_parameters,
227 GType *parameter_types);
228
229JSC_API JSCValue *
230jsc_value_new_function_variadic (JSCContext *context,
231 const char *name,
232 GCallback callback,
233 gpointer user_data,
234 GDestroyNotify destroy_notify,
235 GType return_type);
236
237JSC_API gboolean
238jsc_value_is_function (JSCValue *value);
239
240JSC_API JSCValue *
241jsc_value_function_call (JSCValue *value,
242 GType first_parameter_type,
243 ...) G_GNUC_WARN_UNUSED_RESULT;
244
245JSC_API JSCValue *
246jsc_value_function_callv (JSCValue *value,
247 guint n_parameters,
248 JSCValue **parameters) G_GNUC_WARN_UNUSED_RESULT;
249
250JSC_API gboolean
251jsc_value_is_constructor (JSCValue *value);
252
253JSC_API JSCValue *
254jsc_value_constructor_call (JSCValue *value,
255 GType first_parameter_type,
256 ...);
257
258JSC_API JSCValue *
259jsc_value_constructor_callv (JSCValue *value,
260 guint n_parameters,
261 JSCValue **parameters);
262
263G_END_DECLS
264
265#endif /* JSCValue_h */
266