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 | |
30 | G_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 | |
39 | typedef struct _JSCValue JSCValue; |
40 | typedef struct _JSCValueClass JSCValueClass; |
41 | typedef struct _JSCValuePrivate JSCValuePrivate; |
42 | |
43 | typedef struct _JSCClass JSCClass; |
44 | typedef struct _JSCContext JSCContext; |
45 | |
46 | typedef 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 | |
52 | struct _JSCValue { |
53 | GObject parent; |
54 | |
55 | /*< private >*/ |
56 | JSCValuePrivate *priv; |
57 | }; |
58 | |
59 | struct _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 | |
68 | JSC_API GType |
69 | jsc_value_get_type (void); |
70 | |
71 | JSC_API JSCContext * |
72 | jsc_value_get_context (JSCValue *value); |
73 | |
74 | JSC_API JSCValue * |
75 | jsc_value_new_undefined (JSCContext *context); |
76 | |
77 | JSC_API gboolean |
78 | jsc_value_is_undefined (JSCValue *value); |
79 | |
80 | JSC_API JSCValue * |
81 | jsc_value_new_null (JSCContext *context); |
82 | |
83 | JSC_API gboolean |
84 | jsc_value_is_null (JSCValue *value); |
85 | |
86 | JSC_API JSCValue * |
87 | jsc_value_new_number (JSCContext *context, |
88 | double number); |
89 | JSC_API gboolean |
90 | jsc_value_is_number (JSCValue *value); |
91 | |
92 | JSC_API double |
93 | jsc_value_to_double (JSCValue *value); |
94 | |
95 | JSC_API gint32 |
96 | jsc_value_to_int32 (JSCValue *value); |
97 | |
98 | JSC_API JSCValue * |
99 | jsc_value_new_boolean (JSCContext *context, |
100 | gboolean value); |
101 | JSC_API gboolean |
102 | jsc_value_is_boolean (JSCValue *value); |
103 | |
104 | JSC_API gboolean |
105 | jsc_value_to_boolean (JSCValue *value); |
106 | |
107 | JSC_API JSCValue * |
108 | jsc_value_new_string (JSCContext *context, |
109 | const char *string); |
110 | |
111 | JSC_API JSCValue * |
112 | jsc_value_new_string_from_bytes (JSCContext *context, |
113 | GBytes *bytes); |
114 | |
115 | JSC_API gboolean |
116 | jsc_value_is_string (JSCValue *value); |
117 | |
118 | JSC_API char * |
119 | jsc_value_to_string (JSCValue *value); |
120 | |
121 | JSC_API GBytes * |
122 | jsc_value_to_string_as_bytes (JSCValue *value); |
123 | |
124 | JSC_API JSCValue * |
125 | jsc_value_new_array (JSCContext *context, |
126 | GType first_item_type, |
127 | ...); |
128 | |
129 | JSC_API JSCValue * |
130 | jsc_value_new_array_from_garray (JSCContext *context, |
131 | GPtrArray *array); |
132 | |
133 | JSC_API JSCValue * |
134 | jsc_value_new_array_from_strv (JSCContext *context, |
135 | const char *const *strv); |
136 | |
137 | JSC_API gboolean |
138 | jsc_value_is_array (JSCValue *value); |
139 | |
140 | JSC_API JSCValue * |
141 | jsc_value_new_object (JSCContext *context, |
142 | gpointer instance, |
143 | JSCClass *jsc_class); |
144 | |
145 | JSC_API gboolean |
146 | jsc_value_is_object (JSCValue *value); |
147 | |
148 | JSC_API gboolean |
149 | jsc_value_object_is_instance_of (JSCValue *value, |
150 | const char *name); |
151 | |
152 | JSC_API void |
153 | jsc_value_object_set_property (JSCValue *value, |
154 | const char *name, |
155 | JSCValue *property); |
156 | |
157 | JSC_API JSCValue * |
158 | jsc_value_object_get_property (JSCValue *value, |
159 | const char *name); |
160 | |
161 | JSC_API void |
162 | jsc_value_object_set_property_at_index (JSCValue *value, |
163 | guint index, |
164 | JSCValue *property); |
165 | |
166 | JSC_API JSCValue * |
167 | jsc_value_object_get_property_at_index (JSCValue *value, |
168 | guint index); |
169 | |
170 | JSC_API gboolean |
171 | jsc_value_object_has_property (JSCValue *value, |
172 | const char *name); |
173 | |
174 | JSC_API gboolean |
175 | jsc_value_object_delete_property (JSCValue *value, |
176 | const char *name); |
177 | |
178 | JSC_API gchar ** |
179 | jsc_value_object_enumerate_properties (JSCValue *value); |
180 | |
181 | JSC_API JSCValue * |
182 | jsc_value_object_invoke_method (JSCValue *value, |
183 | const char *name, |
184 | GType first_parameter_type, |
185 | ...) G_GNUC_WARN_UNUSED_RESULT; |
186 | |
187 | JSC_API JSCValue * |
188 | jsc_value_object_invoke_methodv (JSCValue *value, |
189 | const char *name, |
190 | guint n_parameters, |
191 | JSCValue **parameters) G_GNUC_WARN_UNUSED_RESULT; |
192 | |
193 | JSC_API void |
194 | jsc_value_object_define_property_data (JSCValue *value, |
195 | const char *property_name, |
196 | JSCValuePropertyFlags flags, |
197 | JSCValue *property_value); |
198 | |
199 | JSC_API void |
200 | jsc_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 | |
209 | JSC_API JSCValue * |
210 | jsc_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 | |
219 | JSC_API JSCValue * |
220 | jsc_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 | |
229 | JSC_API JSCValue * |
230 | jsc_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 | |
237 | JSC_API gboolean |
238 | jsc_value_is_function (JSCValue *value); |
239 | |
240 | JSC_API JSCValue * |
241 | jsc_value_function_call (JSCValue *value, |
242 | GType first_parameter_type, |
243 | ...) G_GNUC_WARN_UNUSED_RESULT; |
244 | |
245 | JSC_API JSCValue * |
246 | jsc_value_function_callv (JSCValue *value, |
247 | guint n_parameters, |
248 | JSCValue **parameters) G_GNUC_WARN_UNUSED_RESULT; |
249 | |
250 | JSC_API gboolean |
251 | jsc_value_is_constructor (JSCValue *value); |
252 | |
253 | JSC_API JSCValue * |
254 | jsc_value_constructor_call (JSCValue *value, |
255 | GType first_parameter_type, |
256 | ...); |
257 | |
258 | JSC_API JSCValue * |
259 | jsc_value_constructor_callv (JSCValue *value, |
260 | guint n_parameters, |
261 | JSCValue **parameters); |
262 | |
263 | G_END_DECLS |
264 | |
265 | #endif /* JSCValue_h */ |
266 | |