SpiderMonkey: do not remember context. Maybe this time it won't hung.
[elinks.git] / src / ecmascript / see.c
blob1d5b29a3a7b1872e78a188e3d642a05669fc5772
1 /* The SEE ECMAScript backend. */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
11 #include "elinks.h"
13 #include <see/see.h>
15 #include "bfu/dialog.h"
16 #include "cache/cache.h"
17 #include "cookies/cookies.h"
18 #include "dialogs/menu.h"
19 #include "dialogs/status.h"
20 #include "document/html/frames.h"
21 #include "document/document.h"
22 #include "document/forms.h"
23 #include "document/view.h"
24 #include "ecmascript/ecmascript.h"
25 #include "ecmascript/see.h"
26 #include "ecmascript/see/document.h"
27 #include "ecmascript/see/form.h"
28 #include "ecmascript/see/input.h"
29 #include "ecmascript/see/location.h"
30 #include "ecmascript/see/navigator.h"
31 #include "ecmascript/see/strings.h"
32 #include "ecmascript/see/unibar.h"
33 #include "ecmascript/see/window.h"
34 #include "intl/gettext/libintl.h"
35 #include "main/select.h"
36 #include "osdep/newwin.h"
37 #include "osdep/sysname.h"
38 #include "protocol/http/http.h"
39 #include "protocol/uri.h"
40 #include "session/history.h"
41 #include "session/location.h"
42 #include "session/session.h"
43 #include "session/task.h"
44 #include "terminal/tab.h"
45 #include "terminal/terminal.h"
46 #include "util/conv.h"
47 #include "util/string.h"
48 #include "viewer/text/draw.h"
49 #include "viewer/text/form.h"
50 #include "viewer/text/link.h"
51 #include "viewer/text/vs.h"
54 /*** Global methods */
57 /* TODO? Are there any which need to be implemented? */
59 static void
60 see_init(struct module *xxx)
62 init_intern_strings();
65 static void
66 see_done(struct module *xxx)
70 void *
71 see_get_interpreter(struct ecmascript_interpreter *interpreter)
73 struct global_object *g = SEE_NEW(NULL, struct global_object);
74 struct SEE_interpreter *interp = &g->interp;
76 interpreter->backend_data = g;
77 g->max_exec_time = get_opt_int("ecmascript.max_exec_time");
78 g->exec_start = time(NULL);
79 SEE_interpreter_init(interp);
80 init_js_window_object(interpreter);
81 init_js_menubar_object(interpreter);
82 init_js_statusbar_object(interpreter);
83 init_js_navigator_object(interpreter);
84 init_js_history_object(interpreter);
85 init_js_location_object(interpreter);
86 init_js_document_object(interpreter);
87 init_js_forms_object(interpreter);
88 return interp;
91 void
92 see_put_interpreter(struct ecmascript_interpreter *interpreter)
94 interpreter->backend_data = NULL;
97 void
98 see_eval(struct ecmascript_interpreter *interpreter,
99 struct string *code, struct string *ret)
102 struct SEE_interpreter *interp = interpreter->backend_data;
103 struct global_object *g = (struct global_object *)interp;
104 struct SEE_input *input = SEE_input_elinks(interp, code->source);
105 SEE_try_context_t try_ctxt;
106 struct SEE_value result;
108 g->exec_start = time(NULL);
109 g->ret = ret;
110 SEE_TRY(interp, try_ctxt) {
111 SEE_Global_eval(interp, input, &result);
114 SEE_INPUT_CLOSE(input);
115 SEE_CAUGHT(try_ctxt);
119 unsigned char *
120 see_eval_stringback(struct ecmascript_interpreter *interpreter,
121 struct string *code)
123 struct SEE_interpreter *interp = interpreter->backend_data;
124 struct global_object *g = (struct global_object *)interp;
125 struct SEE_input *input = SEE_input_elinks(interp, code->source);
126 SEE_try_context_t try_ctxt;
127 struct SEE_value result;
128 /* 'volatile' qualifier prevents register allocation which fixes:
129 * warning: variable 'xxx' might be clobbered by 'longjmp' or 'vfork'
131 unsigned char *volatile string = NULL;
133 g->exec_start = time(NULL);
134 g->ret = NULL;
135 SEE_TRY(interp, try_ctxt) {
136 SEE_Global_eval(interp, input, &result);
137 if (SEE_VALUE_GET_TYPE(&result) != SEE_NULL)
138 string = SEE_value_to_unsigned_char(interp, &result);
141 SEE_INPUT_CLOSE(input);
142 if (SEE_CAUGHT(try_ctxt)) {
143 return NULL;
145 return string;
149 see_eval_boolback(struct ecmascript_interpreter *interpreter,
150 struct string *code)
152 struct SEE_interpreter *interp = interpreter->backend_data;
153 struct global_object *g = (struct global_object *)interp;
154 struct SEE_input *input = SEE_input_elinks(interp, code->source);
155 SEE_try_context_t try_ctxt;
156 struct SEE_value result;
157 /* 'volatile' qualifier prevents register allocation which fixes:
158 * warning: variable 'xxx' might be clobbered by 'longjmp' or 'vfork'
160 SEE_int32_t volatile res = 0;
162 g->exec_start = time(NULL);
163 g->ret = NULL;
164 SEE_TRY(interp, try_ctxt) {
165 SEE_Global_eval(interp, input, &result);
166 /* history.back() returns SEE_NULL */
167 if (SEE_VALUE_GET_TYPE(&result) == SEE_NULL)
168 res = 0;
169 else
170 res = SEE_ToInt32(interp, &result);
173 SEE_INPUT_CLOSE(input);
174 if (SEE_CAUGHT(try_ctxt)) {
175 return -1;
177 return res;
180 struct module see_module = struct_module(
181 /* name: */ "SEE",
182 /* options: */ NULL,
183 /* events: */ NULL,
184 /* submodules: */ NULL,
185 /* data: */ NULL,
186 /* init: */ see_init,
187 /* done: */ see_done