diff --git a/src/ecmascript/ecmascript-c.cpp b/src/ecmascript/ecmascript-c.cpp index 4b4d933d..361dd547 100644 --- a/src/ecmascript/ecmascript-c.cpp +++ b/src/ecmascript/ecmascript-c.cpp @@ -11,6 +11,15 @@ #include "document/view.h" #include "ecmascript/ecmascript.h" #include "ecmascript/ecmascript-c.h" +#ifdef CONFIG_MUJS +#include "ecmascript/mujs.h" +#endif +#ifdef CONFIG_QUICKJS +#include "ecmascript/quickjs.h" +#endif +#ifdef CONFIG_ECMASCRIPT_SMJS +#include "ecmascript/spidermonkey.h" +#endif #include "intl/libintl.h" #include "protocol/uri.h" #include "session/session.h" @@ -289,3 +298,37 @@ kill_ecmascript_timeouts(struct document *document) done_string(&t->code); } } + +void +ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter) +{ + assert(interpreter); + assert(interpreter->backend_nesting == 0); + /* If the assertion fails, it is better to leak the + * interpreter than to corrupt memory. */ + if_assert_failed return; +#ifdef CONFIG_MUJS + mujs_put_interpreter(interpreter); +#elif defined(CONFIG_QUICKJS) + quickjs_put_interpreter(interpreter); +#else + spidermonkey_put_interpreter(interpreter); +#endif + free_ecmascript_string_list(&interpreter->onload_snippets); + done_string(&interpreter->code); + free_ecmascript_string_list(&interpreter->writecode); + /* Is it superfluous? */ + if (interpreter->vs->doc_view) { + struct ecmascript_timeout *t; + + foreach (t, interpreter->vs->doc_view->document->timeouts) { + kill_timer(&t->tid); + done_string(&t->code); + } + free_list(interpreter->vs->doc_view->document->timeouts); + } + interpreter->vs->ecmascript = NULL; + interpreter->vs->ecmascript_fragile = 1; + mem_free(interpreter); + --interpreter_count; +} diff --git a/src/ecmascript/ecmascript-c.h b/src/ecmascript/ecmascript-c.h index a446dfec..9313df57 100644 --- a/src/ecmascript/ecmascript-c.h +++ b/src/ecmascript/ecmascript-c.h @@ -9,11 +9,13 @@ extern "C" { struct document_options; struct document; +struct ecmascript_interpreter; struct session; struct uri; struct view_state; int ecmascript_get_interpreter_count(void); +void ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter); void toggle_ecmascript(struct session *ses); /* Takes line with the syntax javascript:. Activated when user diff --git a/src/ecmascript/ecmascript.cpp b/src/ecmascript/ecmascript.cpp index 5f906f2f..4f6fe747 100644 --- a/src/ecmascript/ecmascript.cpp +++ b/src/ecmascript/ecmascript.cpp @@ -19,6 +19,7 @@ #include "document/renderer.h" #include "document/view.h" #include "ecmascript/ecmascript.h" +#include "ecmascript/ecmascript-c.h" #include "ecmascript/libdom/parse.h" #ifdef CONFIG_MUJS #include "ecmascript/mujs.h" @@ -253,40 +254,6 @@ ecmascript_get_interpreter(struct view_state *vs) return interpreter; } -void -ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter) -{ - assert(interpreter); - assert(interpreter->backend_nesting == 0); - /* If the assertion fails, it is better to leak the - * interpreter than to corrupt memory. */ - if_assert_failed return; -#ifdef CONFIG_MUJS - mujs_put_interpreter(interpreter); -#elif defined(CONFIG_QUICKJS) - quickjs_put_interpreter(interpreter); -#else - spidermonkey_put_interpreter(interpreter); -#endif - free_ecmascript_string_list(&interpreter->onload_snippets); - done_string(&interpreter->code); - free_ecmascript_string_list(&interpreter->writecode); - /* Is it superfluous? */ - if (interpreter->vs->doc_view) { - struct ecmascript_timeout *t; - - foreach (t, interpreter->vs->doc_view->document->timeouts) { - kill_timer(&t->tid); - done_string(&t->code); - } - free_list(interpreter->vs->doc_view->document->timeouts); - } - interpreter->vs->ecmascript = NULL; - interpreter->vs->ecmascript_fragile = 1; - mem_free(interpreter); - --interpreter_count; -} - static void delayed_reload(void *data) { diff --git a/src/ecmascript/ecmascript.h b/src/ecmascript/ecmascript.h index 0c637712..ac3f7fc5 100644 --- a/src/ecmascript/ecmascript.h +++ b/src/ecmascript/ecmascript.h @@ -155,7 +155,6 @@ int ecmascript_check_url(char *url, char *frame); void ecmascript_free_urls(struct module *module); struct ecmascript_interpreter *ecmascript_get_interpreter(struct view_state*vs); -void ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter); void ecmascript_detach_form_view(struct form_view *fv); void ecmascript_detach_form_state(struct form_state *fs); diff --git a/src/viewer/text/Makefile b/src/viewer/text/Makefile index 87338810..37b6e3eb 100644 --- a/src/viewer/text/Makefile +++ b/src/viewer/text/Makefile @@ -5,6 +5,6 @@ INCLUDES += $(TRE_CFLAGS) OBJS-$(CONFIG_MARKS) += marks.o -OBJS = draw.o form.obj link.obj search.o textarea.o view.obj vs.obj +OBJS = draw.o form.obj link.obj search.o textarea.o view.obj vs.o include $(top_srcdir)/Makefile.lib diff --git a/src/viewer/text/meson.build b/src/viewer/text/meson.build index ddb20d6b..29c14b10 100644 --- a/src/viewer/text/meson.build +++ b/src/viewer/text/meson.build @@ -4,4 +4,4 @@ if conf_data.get('CONFIG_MARKS') srcs += files('marks.c') endif -srcs += files('draw.c', 'form.cpp', 'link.cpp', 'search.c', 'textarea.c', 'view.cpp', 'vs.cpp') +srcs += files('draw.c', 'form.cpp', 'link.cpp', 'search.c', 'textarea.c', 'view.cpp', 'vs.c') diff --git a/src/viewer/text/vs.cpp b/src/viewer/text/vs.c similarity index 97% rename from src/viewer/text/vs.cpp rename to src/viewer/text/vs.c index dd0c7694..18175003 100644 --- a/src/viewer/text/vs.cpp +++ b/src/viewer/text/vs.c @@ -12,7 +12,9 @@ #include "document/document.h" #include "document/view.h" -#include "ecmascript/ecmascript.h" +#ifdef CONFIG_ECMASCRIPT +#include "ecmascript/ecmascript-c.h" +#endif #include "protocol/uri.h" #ifdef CONFIG_SCRIPTING_SPIDERMONKEY # include "scripting/smjs/smjs.h" @@ -131,7 +133,7 @@ copy_vs(struct view_state *dst, struct view_state *src) struct form_state *dstfs = &dst->form_info[i]; #ifdef CONFIG_ECMASCRIPT_SMJS - dstfs->ecmascript_obj = nullptr; + dstfs->ecmascript_obj = NULL; #endif #ifdef CONFIG_QUICKJS dstfs->ecmascript_obj = JS_NULL;