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 JSCContext_h |
25 | #define JSCContext_h |
26 | |
27 | #include <glib-object.h> |
28 | #include <jsc/JSCDefines.h> |
29 | #include <jsc/JSCException.h> |
30 | #include <jsc/JSCClass.h> |
31 | #include <jsc/JSCValue.h> |
32 | #include <jsc/JSCVirtualMachine.h> |
33 | |
34 | G_BEGIN_DECLS |
35 | |
36 | #define JSC_TYPE_CONTEXT (jsc_context_get_type()) |
37 | #define JSC_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), JSC_TYPE_CONTEXT, JSCContext)) |
38 | #define JSC_IS_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), JSC_TYPE_CONTEXT)) |
39 | #define JSC_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), JSC_TYPE_CONTEXT, JSCContextClass)) |
40 | #define JSC_IS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), JSC_TYPE_CONTEXT)) |
41 | #define JSC_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), JSC_TYPE_CONTEXT, JSCContextClass)) |
42 | |
43 | typedef struct _JSCContext JSCContext; |
44 | typedef struct _JSCContextClass JSCContextClass; |
45 | typedef struct _JSCContextPrivate JSCContextPrivate; |
46 | |
47 | typedef void (* JSCExceptionHandler) (JSCContext *context, |
48 | JSCException *exception, |
49 | gpointer user_data); |
50 | |
51 | typedef enum { |
52 | JSC_CHECK_SYNTAX_MODE_SCRIPT, |
53 | JSC_CHECK_SYNTAX_MODE_MODULE |
54 | } JSCCheckSyntaxMode; |
55 | |
56 | typedef enum { |
57 | JSC_CHECK_SYNTAX_RESULT_SUCCESS, |
58 | JSC_CHECK_SYNTAX_RESULT_RECOVERABLE_ERROR, |
59 | JSC_CHECK_SYNTAX_RESULT_IRRECOVERABLE_ERROR, |
60 | JSC_CHECK_SYNTAX_RESULT_UNTERMINATED_LITERAL_ERROR, |
61 | JSC_CHECK_SYNTAX_RESULT_OUT_OF_MEMORY_ERROR, |
62 | JSC_CHECK_SYNTAX_RESULT_STACK_OVERFLOW_ERROR, |
63 | } JSCCheckSyntaxResult; |
64 | |
65 | struct _JSCContext { |
66 | GObject parent; |
67 | |
68 | /*< private >*/ |
69 | JSCContextPrivate *priv; |
70 | }; |
71 | |
72 | struct _JSCContextClass { |
73 | GObjectClass parent_class; |
74 | |
75 | void (*_jsc_reserved0) (void); |
76 | void (*_jsc_reserved1) (void); |
77 | void (*_jsc_reserved2) (void); |
78 | void (*_jsc_reserved3) (void); |
79 | }; |
80 | |
81 | JSC_API GType |
82 | jsc_context_get_type (void); |
83 | |
84 | JSC_API JSCContext * |
85 | jsc_context_new (void); |
86 | |
87 | JSC_API JSCContext * |
88 | jsc_context_new_with_virtual_machine (JSCVirtualMachine *vm); |
89 | |
90 | JSC_API JSCVirtualMachine * |
91 | jsc_context_get_virtual_machine (JSCContext *context); |
92 | |
93 | JSC_API JSCException * |
94 | jsc_context_get_exception (JSCContext *context); |
95 | |
96 | JSC_API void |
97 | jsc_context_throw (JSCContext *context, |
98 | const char *error_message); |
99 | |
100 | JSC_API void |
101 | jsc_context_throw_printf (JSCContext *context, |
102 | const char *format, |
103 | ...) G_GNUC_PRINTF (2, 3); |
104 | |
105 | JSC_API void |
106 | jsc_context_throw_with_name (JSCContext *context, |
107 | const char *error_name, |
108 | const char *error_message); |
109 | |
110 | JSC_API void |
111 | jsc_context_throw_with_name_printf (JSCContext *context, |
112 | const char *error_name, |
113 | const char *format, |
114 | ...) G_GNUC_PRINTF (3, 4); |
115 | |
116 | JSC_API void |
117 | jsc_context_throw_exception (JSCContext *context, |
118 | JSCException *exception); |
119 | |
120 | JSC_API void |
121 | jsc_context_clear_exception (JSCContext *context); |
122 | |
123 | JSC_API void |
124 | jsc_context_push_exception_handler (JSCContext *context, |
125 | JSCExceptionHandler handler, |
126 | gpointer user_data, |
127 | GDestroyNotify destroy_notify); |
128 | |
129 | JSC_API void |
130 | jsc_context_pop_exception_handler (JSCContext *context); |
131 | |
132 | JSC_API JSCContext * |
133 | jsc_context_get_current (void); |
134 | |
135 | JSC_API JSCValue * |
136 | jsc_context_evaluate (JSCContext *context, |
137 | const char *code, |
138 | gssize length) G_GNUC_WARN_UNUSED_RESULT; |
139 | |
140 | JSC_API JSCValue * |
141 | jsc_context_evaluate_with_source_uri (JSCContext *context, |
142 | const char *code, |
143 | gssize length, |
144 | const char *uri, |
145 | guint line_number) G_GNUC_WARN_UNUSED_RESULT; |
146 | |
147 | JSC_API JSCValue * |
148 | jsc_context_evaluate_in_object (JSCContext *context, |
149 | const char *code, |
150 | gssize length, |
151 | gpointer object_instance, |
152 | JSCClass *object_class, |
153 | const char *uri, |
154 | guint line_number, |
155 | JSCValue **object) G_GNUC_WARN_UNUSED_RESULT; |
156 | |
157 | JSC_API JSCCheckSyntaxResult |
158 | jsc_context_check_syntax (JSCContext *context, |
159 | const char *code, |
160 | gssize length, |
161 | JSCCheckSyntaxMode mode, |
162 | const char *uri, |
163 | unsigned line_number, |
164 | JSCException **exception); |
165 | |
166 | JSC_API JSCValue * |
167 | jsc_context_get_global_object (JSCContext *context); |
168 | |
169 | JSC_API void |
170 | jsc_context_set_value (JSCContext *context, |
171 | const char *name, |
172 | JSCValue *value); |
173 | |
174 | JSC_API JSCValue * |
175 | jsc_context_get_value (JSCContext *context, |
176 | const char *name); |
177 | |
178 | JSC_API JSCClass * |
179 | jsc_context_register_class (JSCContext *context, |
180 | const char *name, |
181 | JSCClass *parent_class, |
182 | JSCClassVTable *vtable, |
183 | GDestroyNotify destroy_notify); |
184 | |
185 | G_END_DECLS |
186 | |
187 | #endif /* JSCContext_h */ |
188 | |