1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-10-13 05:43:37 -04:00

[mujs] small success window.alert('Thu');

This commit is contained in:
Witold Filipczyk 2022-08-04 20:01:26 +02:00
parent 96d54a65da
commit 63027feabc
13 changed files with 587 additions and 24 deletions

View File

@ -278,7 +278,7 @@ reset_document(struct document *document)
#ifdef CONFIG_CSS
free_uri_list(&document->css_imports);
#endif
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
free_string_list(&document->onload_snippets);
free_uri_list(&document->ecmascript_imports);
mem_free_set(&document->text, NULL);
@ -348,7 +348,7 @@ done_document(struct document *document)
#ifdef CONFIG_CSS
free_uri_list(&document->css_imports);
#endif
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
free_string_list(&document->onload_snippets);
free_uri_list(&document->ecmascript_imports);
kill_timer(&document->timeout);

View File

@ -208,7 +208,7 @@ void
html_script(struct html_context *html_context, char *a,
char *html, char *eof, char **end)
{
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
/* TODO: <noscript> processing. Well, same considerations apply as to
* CSS property display: none processing. */
/* TODO: Charsets for external scripts. */
@ -219,7 +219,7 @@ html_script(struct html_context *html_context, char *a,
html_skip(html_context, a);
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
if (html_context->was_xml_parsed) {
return;
}
@ -1136,7 +1136,7 @@ html_noscript(struct html_context *html_context, char *a,
{
/* We shouldn't throw <noscript> away until our ECMAScript support is
* halfway decent. */
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
if (get_opt_bool("ecmascript.enable", NULL)
&& get_opt_bool("ecmascript.ignore_noscript", NULL))
html_skip(html_context, a);

View File

@ -52,7 +52,7 @@
#include "viewer/text/vs.h"
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
/** @todo XXX: This function is de facto obsolete, since we do not need to copy
* snippets around anymore (we process them in one go after the document is
* loaded; gradual processing was practically impossible because the snippets
@ -349,7 +349,7 @@ render_document(struct view_state *vs, struct document_view *doc_view,
vs->doc_view->used = 0; /* A bit risky, but... */
vs->doc_view->vs = NULL;
vs->doc_view = NULL;
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
vs->ecmascript_fragile = 1; /* And is this good? ;-) */
#endif
}
@ -403,7 +403,7 @@ render_document(struct view_state *vs, struct document_view *doc_view,
document->css_magic = get_document_css_magic(document);
#endif
}
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
if (!vs->ecmascript_fragile)
assert(vs->ecmascript);
if (!options->dump && !options->gradual_rerendering) {

View File

@ -25,6 +25,7 @@
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/mujs.h"
#include "ecmascript/mujs/window.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
@ -66,7 +67,17 @@ mujs_done(struct module *xxx)
void *
mujs_get_interpreter(struct ecmascript_interpreter *interpreter)
{
return nullptr;
assert(interpreter);
js_State *J = js_newstate(NULL, NULL, JS_STRICT);
if (!J) {
return NULL;
}
interpreter->backend_data = J;
mjs_window_init(interpreter, J);
return J;
#if 0
JSContext *ctx;
@ -120,6 +131,11 @@ mujs_get_interpreter(struct ecmascript_interpreter *interpreter)
void
mujs_put_interpreter(struct ecmascript_interpreter *interpreter)
{
assert(interpreter);
js_State *J = (js_State *)interpreter->backend_data;
js_freestate(J);
interpreter->backend_data = NULL;
#if 0
JSContext *ctx;
@ -177,6 +193,11 @@ void
mujs_eval(struct ecmascript_interpreter *interpreter,
struct string *code, struct string *ret)
{
assert(interpreter);
js_State *J = (js_State *)interpreter->backend_data;
interpreter->ret = ret;
js_dostring(J, code->source);
#if 0
JSContext *ctx;

View File

@ -0,0 +1,3 @@
#srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp',
#'input.cpp', 'localstorage.cpp', 'location.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp')
srcs += files('window.cpp')

View File

@ -0,0 +1,529 @@
/* The Quickjs window object implementation. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "bfu/dialog.h"
#include "cache/cache.h"
#include "cookies/cookies.h"
#include "dialogs/menu.h"
#include "dialogs/status.h"
#include "document/html/frames.h"
#include "document/document.h"
#include "document/forms.h"
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/mujs.h"
#include "ecmascript/mujs/window.h"
#include "ecmascript/timer.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"
#include "protocol/http/http.h"
#include "protocol/uri.h"
#include "session/history.h"
#include "session/location.h"
#include "session/session.h"
#include "session/task.h"
#include "terminal/tab.h"
#include "terminal/terminal.h"
#include "util/conv.h"
#include "util/memory.h"
#include "util/string.h"
#include "viewer/text/draw.h"
#include "viewer/text/form.h"
#include "viewer/text/link.h"
#include "viewer/text/vs.h"
#if 0
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_window_class_id;
/* @window_funcs{"open"} */
JSValue
js_window_open(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct document_view *doc_view;
struct session *ses;
const char *frame = NULL;
char *url, *url2;
struct uri *uri;
static time_t ratelimit_start;
static int ratelimit_count;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
vs = interpreter->vs;
doc_view = vs->doc_view;
ses = doc_view->session;
if (get_opt_bool("ecmascript.block_window_opening", ses)) {
#ifdef CONFIG_LEDS
set_led_value(ses->status.popup_led, 'P');
#endif
return JS_UNDEFINED;
}
if (argc < 1) return JS_UNDEFINED;
/* Ratelimit window opening. Recursive window.open() is very nice.
* We permit at most 20 tabs in 2 seconds. The ratelimiter is very
* rough but shall suffice against the usual cases. */
if (!ratelimit_start || time(NULL) - ratelimit_start > 2) {
ratelimit_start = time(NULL);
ratelimit_count = 0;
} else {
ratelimit_count++;
if (ratelimit_count > 20) {
return JS_UNDEFINED;
}
}
const char *str;
size_t len;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
url = stracpy(str);
JS_FreeCString(ctx, str);
if (!url) {
return JS_UNDEFINED;
}
trim_chars(url, ' ', 0);
url2 = join_urls(doc_view->document->uri, url);
mem_free(url);
if (!url2) {
return JS_UNDEFINED;
}
if (argc > 1) {
size_t len2;
frame = JS_ToCStringLen(ctx, &len2, argv[1]);
if (!frame) {
mem_free(url2);
return JS_EXCEPTION;
}
}
/* TODO: Support for window naming and perhaps some window features? */
uri = get_uri(url2, URI_NONE);
mem_free(url2);
if (!uri) {
if (frame) JS_FreeCString(ctx, frame);
return JS_UNDEFINED;
}
JSValue ret;
if (frame && *frame && c_strcasecmp(frame, "_blank")) {
struct delayed_open *deo = (struct delayed_open *)mem_calloc(1, sizeof(*deo));
if (deo) {
deo->ses = ses;
deo->uri = get_uri_reference(uri);
deo->target = stracpy(frame);
register_bottom_half(delayed_goto_uri_frame, deo);
ret = JS_TRUE;
goto end;
}
}
if (!get_cmd_opt_bool("no-connect")
&& !get_cmd_opt_bool("no-home")
&& !get_cmd_opt_bool("anonymous")
&& can_open_in_new(ses->tab->term)) {
open_uri_in_new_window(ses, uri, NULL, ENV_ANY,
CACHE_MODE_NORMAL, TASK_NONE);
ret = JS_TRUE;
} else {
/* When opening a new tab, we might get rerendered, losing our
* context and triggerring a disaster, so postpone that. */
struct delayed_open *deo = (struct delayed_open *)mem_calloc(1, sizeof(*deo));
if (deo) {
deo->ses = ses;
deo->uri = get_uri_reference(uri);
register_bottom_half(delayed_open, deo);
ret = JS_TRUE;
} else {
ret = JS_UNDEFINED;
}
}
end:
done_uri(uri);
if (frame) JS_FreeCString(ctx, frame);
return ret;
}
/* @window_funcs{"setTimeout"} */
JSValue
js_window_setTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
int64_t timeout = 0;
JSValueConst func;
if (argc != 2) {
return JS_UNDEFINED;
}
if (JS_ToInt64(ctx, &timeout, argv[1])) {
return JS_EXCEPTION;
}
if (timeout <= 0) {
return JS_UNDEFINED;
}
func = argv[0];
if (JS_IsFunction(ctx, func)) {
timer_id_T id = ecmascript_set_timeout2q(interpreter, JS_DupValue(ctx, func), timeout);
return JS_NewInt64(ctx, reinterpret_cast<int64_t>(id));
}
if (JS_IsString(func)) {
const char *code = JS_ToCString(ctx, func);
if (!code) {
return JS_EXCEPTION;
}
char *code2 = stracpy(code);
JS_FreeCString(ctx, code);
if (code2) {
timer_id_T id = ecmascript_set_timeout(interpreter, code2, timeout);
return JS_NewInt64(ctx, reinterpret_cast<int64_t>(id));
}
}
return JS_UNDEFINED;
}
/* @window_funcs{"clearTimeout"} */
JSValue
js_window_clearTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
if (argc != 1) {
return JS_UNDEFINED;
}
int64_t number;
if (JS_ToInt64(ctx, &number, argv[0])) {
return JS_UNDEFINED;
}
timer_id_T id = reinterpret_cast<timer_id_T>(number);
if (found_in_map_timer(id) && (id == interpreter->vs->doc_view->document->timeout)) {
kill_timer(&interpreter->vs->doc_view->document->timeout);
}
return JS_UNDEFINED;
}
static JSValue
js_window_get_property_closed(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
return JS_FALSE;
}
static JSValue
js_window_get_property_parent(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
/* XXX: It would be nice if the following worked, yes.
* The problem is that we get called at the point where
* document.frame properties are going to be mostly NULL.
* But the problem is deeper because at that time we are
* yet building scrn_frames so our parent might not be there
* yet (XXX: is this true?). The true solution will be to just
* have struct document_view *(document_view.parent). --pasky */
/* FIXME: So now we alias window.parent to window.top, which is
* INCORRECT but works for the most common cases of just two
* frames. Better something than nothing. */
return JS_UNDEFINED;
}
static JSValue
js_window_get_property_self(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JSValue r = JS_DupValue(ctx, this_val);
RETURN_JS(r);
}
static JSValue
js_window_get_property_status(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
return JS_UNDEFINED;
}
static JSValue
js_window_set_property_status(JSContext *ctx, JSValueConst this_val, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
return JS_UNDEFINED;
}
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, val);
if (!str) {
return JS_EXCEPTION;
}
char *text = stracpy(str);
JS_FreeCString(ctx, str);
mem_free_set(&vs->doc_view->session->status.window_status, text);
print_screen_status(vs->doc_view->session);
return JS_UNDEFINED;
}
static JSValue
js_window_get_property_top(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct document_view *doc_view;
struct document_view *top_view;
JSValue newjsframe;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_UNDEFINED;
}
doc_view = vs->doc_view;
top_view = doc_view->session->doc_view;
assert(top_view && top_view->vs);
if (top_view->vs->ecmascript_fragile)
ecmascript_reset_state(top_view->vs);
if (!top_view->vs->ecmascript) {
return JS_UNDEFINED;
}
newjsframe = JS_GetGlobalObject((JSContext *)top_view->vs->ecmascript->backend_data);
/* Keep this unrolled this way. Will have to check document.domain
* JS property. */
/* Note that this check is perhaps overparanoid. If top windows
* is alien but some other child window is not, we should still
* let the script walk thru. That'd mean moving the check to
* other individual properties in this switch. */
if (compare_uri(vs->uri, top_view->vs->uri, URI_HOST)) {
return newjsframe;
}
/* else */
/****X*X*X*** SECURITY VIOLATION! RED ALERT, SHIELDS UP! ***X*X*X****\
|* (Pasky was apparently looking at the Links2 JS code . ___ ^.^ *|
\* for too long.) `.(,_,)\o/ */
return JS_UNDEFINED;
}
JSValue
js_window_alert(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
assert(interpreter);
struct view_state *vs;
const char *str;
char *string;
size_t len;
vs = interpreter->vs;
if (argc != 1)
return JS_UNDEFINED;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
string = stracpy(str);
JS_FreeCString(ctx, str);
info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT,
N_("JavaScript Alert"), ALIGN_CENTER, string);
return JS_UNDEFINED;
}
static JSValue
js_window_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
return JS_NewString(ctx, "[window object]");
}
static const JSCFunctionListEntry js_window_proto_funcs[] = {
JS_CGETSET_DEF("closed", js_window_get_property_closed, nullptr),
JS_CGETSET_DEF("parent", js_window_get_property_parent, nullptr),
JS_CGETSET_DEF("self", js_window_get_property_self, nullptr),
JS_CGETSET_DEF("status", js_window_get_property_status, js_window_set_property_status),
JS_CGETSET_DEF("top", js_window_get_property_top, nullptr),
JS_CGETSET_DEF("window", js_window_get_property_self, nullptr),
JS_CFUNC_DEF("alert", 1, js_window_alert),
JS_CFUNC_DEF("clearTimeout", 1, js_window_clearTimeout),
JS_CFUNC_DEF("open", 3, js_window_open),
JS_CFUNC_DEF("setTimeout", 2, js_window_setTimeout),
JS_CFUNC_DEF("toString", 0, js_window_toString)
};
static JSClassDef js_window_class = {
"window",
};
int
js_window_init(JSContext *ctx)
{
/* create the window class */
JS_NewClassID(&js_window_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_window_class_id, &js_window_class);
JSValue global_obj = JS_GetGlobalObject(ctx);
JS_SetPropertyFunctionList(ctx, global_obj, js_window_proto_funcs, countof(js_window_proto_funcs));
JS_SetPropertyStr(ctx, global_obj, "window", global_obj);
JS_FreeValue(ctx, global_obj);
return 0;
}
#endif
static void
mjs_window_alert(js_State *J)
{
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "window");
assert(interpreter);
struct view_state *vs = interpreter->vs;
const char *str = js_tostring(J, 1);
if (str) {
char *string = stracpy(str);
info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT,
N_("JavaScript Alert"), ALIGN_CENTER, string);
}
js_pushundefined(J);
#if 0
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
assert(interpreter);
struct view_state *vs;
const char *str;
char *string;
size_t len;
vs = interpreter->vs;
if (argc != 1)
return JS_UNDEFINED;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
string = stracpy(str);
JS_FreeCString(ctx, str);
info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT,
N_("JavaScript Alert"), ALIGN_CENTER, string);
return JS_UNDEFINED;
#endif
}
int
mjs_window_init(struct ecmascript_interpreter *interpreter, js_State *J)
{
fprintf(stderr, "mjs_window_init\n");
js_getglobal(J, "Object");
js_getproperty(J, -1, "prototype"); // window.prototype.[[Prototype]] = Object.prototype
js_newuserdata(J, "window", interpreter, NULL);
js_newcfunction(J, mjs_window_alert, "window.prototype.alert", 1);
js_defproperty(J, -2, "alert", JS_DONTENUM);
// js_newcfunction(J, File_prototype_readLine, "File.prototype.readLine", 0);
// js_defproperty(J, -2, "readLine", JS_DONTENUM);
// js_newcfunction(J, File_prototype_close, "File.prototype.close", 0);
// js_defproperty(J, -2, "close", JS_DONTENUM);
//
// js_newcconstructor(J, new_File, new_File, "File", 1);
js_defglobal(J, "window", JS_DONTENUM);
return 0;
}

View File

@ -0,0 +1,10 @@
#ifndef EL__ECMASCRIPT_MUJS_WINDOW_H
#define EL__ECMASCRIPT_MUJS_WINDOW_H
#include <mujs.h>
struct ecmascript_interpreter;
int mjs_window_init(struct ecmascript_interpreter *interpreter, js_State *J);
#endif

View File

@ -33,7 +33,7 @@
#include "util/memory.h"
#include "util/time.h"
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
#include "ecmascript/timer.h"
#endif
@ -106,7 +106,7 @@ check_timers(timeval_T *last_time)
break;
del_from_list(timer);
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
del_from_map_timer(timer);
#endif
/* At this point, *@timer is to be considered invalid
@ -192,7 +192,7 @@ install_timer(timer_id_T *id, milliseconds_T delay, void (*func)(void *), void *
add_at_pos(timer->prev, new_timer);
}
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
add_to_map_timer(new_timer);
#endif
}
@ -206,7 +206,7 @@ kill_timer(timer_id_T *id)
if (*id == TIMER_ID_UNDEF) return;
timer = *id;
del_from_list(timer);
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
del_from_map_timer(timer);
#endif

View File

@ -223,7 +223,7 @@ generic_external_protocol_handler(struct session *ses, struct uri *uri)
switch (uri->protocol) {
case PROTOCOL_JAVASCRIPT:
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
ecmascript_protocol_handler(ses, uri);
return;
#else

View File

@ -672,7 +672,7 @@ do_action(struct session *ses, main_action_T action_id, int verbose)
break;
case ACT_MAIN_TOGGLE_ECMASCRIPT:
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_QUICKJS)
toggle_ecmascript(ses);
#endif
break;

View File

@ -254,7 +254,7 @@ find_form_state(struct document_view *doc_view, struct el_form_control *fc)
if (n >= vs->form_info_len) {
int nn = n + 1;
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
const struct form_state *const old_form_info = vs->form_info;
#endif
@ -263,7 +263,7 @@ find_form_state(struct document_view *doc_view, struct el_form_control *fc)
vs->form_info = fs;
vs->form_info_len = nn;
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
/* TODO: Standard C does not allow this comparison;
* if the memory to which old_form_info pointed has
* been freed, then the value of the pointer itself is
@ -355,7 +355,7 @@ find_form_by_form_view(struct document *document, struct form_view *fv)
void
done_form_state(struct form_state *fs)
{
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
ecmascript_detach_form_state(fs);
#endif
mem_free_if(fs->value);
@ -367,7 +367,7 @@ done_form_state(struct form_state *fs)
void
done_form_view(struct form_view *fv)
{
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
ecmascript_detach_form_view(fv);
#endif
mem_free(fv);

View File

@ -52,7 +52,7 @@
static int
current_link_evhook(struct document_view *doc_view, enum script_event_hook_type type)
{
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
struct link *link;
struct script_event_hook *evhook;
@ -916,7 +916,7 @@ call_onsubmit_and_submit(struct session *ses, struct document_view *doc_view,
assert(fc->form); /* regardless of whether there is a FORM element */
if_assert_failed return 0;
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
/* If the form has multiple submit buttons, this does not
* explicitly tell the ECMAScript code which of them was
* pressed. W3C DOM Level 3 doesn't seem to include such a

View File

@ -38,7 +38,7 @@ init_vs(struct view_state *vs, struct uri *uri, int plain)
vs->plain = plain;
vs->uri = uri ? get_uri_reference(uri) : NULL;
vs->did_fragment = !uri->fragmentlen;
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
/* If we ever get to render this vs, give it an interpreter. */
vs->ecmascript_fragile = 1;
#endif
@ -67,7 +67,7 @@ destroy_vs(struct view_state *vs, int blast_ecmascript)
}
if (vs->uri) done_uri(vs->uri);
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
if (blast_ecmascript && vs->ecmascript)
ecmascript_put_interpreter(vs->ecmascript);
#endif
@ -87,7 +87,7 @@ copy_vs(struct view_state *dst, struct view_state *src)
/* We do not copy ecmascript stuff around since it's specific for
* a single location, offsprings (followups and so) nedd their own. */
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
dst->ecmascript = NULL;
/* If we ever get to render this vs, give it an interpreter. */
dst->ecmascript_fragile = 1;