1 /* The SEE ECMAScript backend. */
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? */
60 see_init(struct module
*xxx
)
62 init_intern_strings();
63 SEE_system
.periodic
= checktime
;
67 see_done(struct module
*xxx
)
72 see_get_interpreter(struct ecmascript_interpreter
*interpreter
)
74 struct global_object
*g
= SEE_NEW(NULL
, struct global_object
);
75 struct SEE_interpreter
*interp
= &g
->interp
;
77 interpreter
->backend_data
= g
;
78 g
->max_exec_time
= get_opt_int("ecmascript.max_exec_time");
79 g
->exec_start
= time(NULL
);
80 /* used by setTimeout */
81 g
->interpreter
= interpreter
;
82 SEE_interpreter_init(interp
);
83 init_js_window_object(interpreter
);
84 init_js_menubar_object(interpreter
);
85 init_js_statusbar_object(interpreter
);
86 init_js_navigator_object(interpreter
);
87 init_js_history_object(interpreter
);
88 init_js_location_object(interpreter
);
89 init_js_document_object(interpreter
);
90 init_js_forms_object(interpreter
);
95 see_put_interpreter(struct ecmascript_interpreter
*interpreter
)
97 interpreter
->backend_data
= NULL
;
101 see_eval(struct ecmascript_interpreter
*interpreter
,
102 struct string
*code
, struct string
*ret
)
105 struct SEE_interpreter
*interp
= interpreter
->backend_data
;
106 struct global_object
*g
= (struct global_object
*)interp
;
107 struct SEE_input
*input
= SEE_input_elinks(interp
, code
->source
);
108 SEE_try_context_t try_ctxt
;
109 struct SEE_value result
;
111 g
->exec_start
= time(NULL
);
113 SEE_TRY(interp
, try_ctxt
) {
114 SEE_Global_eval(interp
, input
, &result
);
117 SEE_INPUT_CLOSE(input
);
118 SEE_CAUGHT(try_ctxt
);
123 see_eval_stringback(struct ecmascript_interpreter
*interpreter
,
126 struct SEE_interpreter
*interp
= interpreter
->backend_data
;
127 struct global_object
*g
= (struct global_object
*)interp
;
128 struct SEE_input
*input
= SEE_input_elinks(interp
, code
->source
);
129 SEE_try_context_t try_ctxt
;
130 struct SEE_value result
;
131 /* 'volatile' qualifier prevents register allocation which fixes:
132 * warning: variable 'xxx' might be clobbered by 'longjmp' or 'vfork'
134 unsigned char *volatile string
= NULL
;
136 g
->exec_start
= time(NULL
);
138 SEE_TRY(interp
, try_ctxt
) {
139 SEE_Global_eval(interp
, input
, &result
);
140 if (SEE_VALUE_GET_TYPE(&result
) == SEE_STRING
)
141 string
= SEE_value_to_unsigned_char(interp
, &result
);
144 SEE_INPUT_CLOSE(input
);
145 if (SEE_CAUGHT(try_ctxt
)) {
152 see_eval_boolback(struct ecmascript_interpreter
*interpreter
,
155 struct SEE_interpreter
*interp
= interpreter
->backend_data
;
156 struct global_object
*g
= (struct global_object
*)interp
;
157 struct SEE_input
*input
= SEE_input_elinks(interp
, code
->source
);
158 SEE_try_context_t try_ctxt
;
159 struct SEE_value result
;
160 /* 'volatile' qualifier prevents register allocation which fixes:
161 * warning: variable 'xxx' might be clobbered by 'longjmp' or 'vfork'
163 SEE_int32_t
volatile res
= 0;
165 g
->exec_start
= time(NULL
);
167 SEE_TRY(interp
, try_ctxt
) {
168 SEE_Global_eval(interp
, input
, &result
);
169 /* history.back() returns SEE_NULL */
170 if (SEE_VALUE_GET_TYPE(&result
) == SEE_NULL
)
173 res
= SEE_ToInt32(interp
, &result
);
176 SEE_INPUT_CLOSE(input
);
177 if (SEE_CAUGHT(try_ctxt
)) {
183 struct module see_module
= struct_module(
187 /* submodules: */ NULL
,
189 /* init: */ see_init
,