1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Avoided code duplication

This commit is contained in:
2006-01-27 10:08:19 +01:00
parent e8030e09fd
commit 6761b3995d
3 changed files with 100 additions and 153 deletions

View File

@ -12,6 +12,8 @@
#include "document/document.h"
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/see.h"
#include "ecmascript/spidermonkey.h"
#include "intl/gettext/libintl.h"
#include "main/module.h"
#include "protocol/uri.h"
@ -24,12 +26,6 @@
#include "viewer/text/form.h" /* <-ecmascript_reset_state() */
#include "viewer/text/vs.h"
#ifdef CONFIG_ECMASCRIPT_SEE
#include "ecmascript/see.h"
#elif defined(CONFIG_ECMASCRIPT_SMJS)
#include "ecmascript/spidermonkey.h"
#endif
/* TODO: We should have some kind of ACL for the scripts - i.e. ability to
* disallow the scripts to open new windows (or so that the windows are always
@ -66,6 +62,104 @@ static struct option_info ecmascript_options[] = {
NULL_OPTION_INFO,
};
void
ecmascript_init(struct module *module)
{
#ifdef CONFIG_ECMASCRIPT_SEE
see_init();
#else
spidermonkey_init();
#endif
}
void
ecmascript_done(struct module *module)
{
#ifdef CONFIG_ECMASCRIPT_SEE
see_done();
#else
spidermonkey_done();
#endif
}
struct ecmascript_interpreter *
ecmascript_get_interpreter(struct view_state *vs)
{
struct ecmascript_interpreter *interpreter;
assert(vs);
interpreter = mem_calloc(1, sizeof(*interpreter));
if (!interpreter)
return NULL;
interpreter->vs = vs;
init_list(interpreter->onload_snippets);
#ifdef CONFIG_ECMASCRIPT_SEE
see_get_interpreter(interpreter);
#else
spidermonkey_get_interpreter(interpreter);
#endif
return interpreter;
}
void
ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
{
assert(interpreter);
#ifdef CONFIG_ECMASCRIPT_SEE
see_put_interpreter(interpreter);
#else
spidermonkey_put_interpreter(interpreter);
#endif
free_string_list(&interpreter->onload_snippets);
interpreter->vs->ecmascript = NULL;
mem_free(interpreter);
}
void
ecmascript_eval(struct ecmascript_interpreter *interpreter,
struct string *code)
{
if (!get_ecmascript_enable())
return;
assert(interpreter);
#ifdef CONFIG_ECMASCRIPT_SEE
see_eval(interpreter, code);
#else
spidermonkey_eval(interpreter, code);
#endif
}
unsigned char *
ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter,
struct string *code)
{
if (!get_ecmascript_enable())
return NULL;
assert(interpreter);
#ifdef CONFIG_ECMASCRIPT_SEE
return see_eval_stringback(interpreter, code);
#else
return spidermonkey_eval_stringback(interpreter, code);
#endif
}
int
ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter,
struct string *code)
{
if (!get_ecmascript_enable())
return -1;
assert(interpreter);
#ifdef CONFIG_ECMASCRIPT_SEE
return see_eval_boolback(interpreter, code);
#else
return spidermonkey_eval_boolback(interpreter, code);
#endif
}
void
ecmascript_reset_state(struct view_state *vs)
{

View File

@ -56,79 +56,6 @@
/* TODO? Are there any which need to be implemented? */
/*** The ELinks interface */
void
ecmascript_init(struct module *module)
{
see_init();
}
void
ecmascript_done(struct module *module)
{
see_done();
}
struct ecmascript_interpreter *
ecmascript_get_interpreter(struct view_state *vs)
{
struct ecmascript_interpreter *interpreter;
assert(vs);
interpreter = mem_calloc(1, sizeof(*interpreter));
if (!interpreter)
return NULL;
interpreter->vs = vs;
init_list(interpreter->onload_snippets);
see_get_interpreter(interpreter);
return interpreter;
}
void
ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
{
assert(interpreter);
see_put_interpreter(interpreter);
free_string_list(&interpreter->onload_snippets);
mem_free(interpreter);
}
void
ecmascript_eval(struct ecmascript_interpreter *interpreter,
struct string *code)
{
if (!get_ecmascript_enable())
return;
assert(interpreter);
see_eval(interpreter, code);
}
unsigned char *
ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter,
struct string *code)
{
if (!get_ecmascript_enable())
return NULL;
assert(interpreter);
return see_eval_stringback(interpreter, code);
}
int
ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter,
struct string *code)
{
if (!get_ecmascript_enable())
return -1;
assert(interpreter);
return see_eval_boolback(interpreter, code);
}
void
see_init(void)
{

View File

@ -55,82 +55,8 @@
/* TODO? Are there any which need to be implemented? */
/*** The ELinks interface */
static JSRuntime *jsrt;
void
ecmascript_init(struct module *module)
{
spidermonkey_init();
}
void
ecmascript_done(struct module *module)
{
spidermonkey_done();
}
struct ecmascript_interpreter *
ecmascript_get_interpreter(struct view_state *vs)
{
struct ecmascript_interpreter *interpreter;
assert(vs);
interpreter = mem_calloc(1, sizeof(*interpreter));
if (!interpreter)
return NULL;
interpreter->vs = vs;
init_list(interpreter->onload_snippets);
spidermonkey_get_interpreter(interpreter);
return interpreter;
}
void
ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
{
assert(interpreter);
spidermonkey_put_interpreter(interpreter);
free_string_list(&interpreter->onload_snippets);
mem_free(interpreter);
}
void
ecmascript_eval(struct ecmascript_interpreter *interpreter,
struct string *code)
{
if (!get_ecmascript_enable())
return;
assert(interpreter);
spidermonkey_eval(interpreter, code);
}
unsigned char *
ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter,
struct string *code)
{
if (!get_ecmascript_enable())
return NULL;
assert(interpreter);
return spidermonkey_eval_stringback(interpreter, code);
}
int
ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter,
struct string *code)
{
if (!get_ecmascript_enable())
return -1;
assert(interpreter);
return spidermonkey_eval_boolback(interpreter, code);
}
static void
error_reporter(JSContext *ctx, const char *message, JSErrorReport *report)
{