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

Initial skeleton for SpiderMonkey scripting backend.

This commit is contained in:
Miciah Dashiel Butler Masters 2005-12-18 17:40:00 +00:00 committed by Miciah Dashiel Butler Masters
parent a96c0250c3
commit 60d40b7f50
7 changed files with 145 additions and 1 deletions

View File

@ -7,6 +7,7 @@ SUBDIRS-$(CONFIG_PERL) += perl
SUBDIRS-$(CONFIG_PYTHON) += python SUBDIRS-$(CONFIG_PYTHON) += python
SUBDIRS-$(CONFIG_RUBY) += ruby SUBDIRS-$(CONFIG_RUBY) += ruby
SUBDIRS-$(CONFIG_SEE) += see SUBDIRS-$(CONFIG_SEE) += see
SUBDIRS-$(CONFIG_ECMASCRIPT) += smjs
OBJS = scripting.o OBJS = scripting.o

View File

@ -22,11 +22,12 @@
#include "scripting/python/python.h" #include "scripting/python/python.h"
#include "scripting/ruby/ruby.h" #include "scripting/ruby/ruby.h"
#include "scripting/see/see.h" #include "scripting/see/see.h"
#include "scripting/smjs/smjs.h"
/* Error reporting. */ /* Error reporting. */
#if defined(CONFIG_RUBY) || defined(CONFIG_SEE) #if defined(CONFIG_RUBY) || defined(CONFIG_SEE) || defined(CONFIG_ECMASCRIPT)
void void
report_scripting_error(struct module *module, struct session *ses, report_scripting_error(struct module *module, struct session *ses,
unsigned char *msg) unsigned char *msg)
@ -79,6 +80,9 @@ static struct module *scripting_modules[] = {
#endif #endif
#ifdef CONFIG_SEE #ifdef CONFIG_SEE
&see_scripting_module, &see_scripting_module,
#endif
#ifdef CONFIG_ECMASCRIPT
&smjs_scripting_module,
#endif #endif
NULL, NULL,
}; };

View File

@ -0,0 +1,8 @@
top_builddir=../../..
include $(top_builddir)/Makefile.config
INCLUDES += $(SPIDERMONKEY_CFLAGS)
OBJS = smjs.o core.o
include $(top_srcdir)/Makefile.lib

84
src/scripting/smjs/core.c Normal file
View File

@ -0,0 +1,84 @@
/* ECMAScript browser scripting module */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "elinks.h"
#include "ecmascript/spidermonkey/util.h"
#include "main/module.h"
#include "scripting/scripting.h"
#include "scripting/smjs/core.h"
#include "scripting/smjs/smjs.h"
#include "util/string.h"
#define SMJS_HOOKS_FILENAME "hooks.js"
JSContext *smjs_ctx;
struct session *smjs_ses;
void
alert_smjs_error(unsigned char *msg)
{
report_scripting_error(&smjs_scripting_module,
smjs_ses, msg);
}
static void
error_reporter(JSContext *ctx, const char *message, JSErrorReport *report)
{
unsigned char *strict, *exception, *warning, *error;
struct string msg;
if (!init_string(&msg)) goto reported;
strict = JSREPORT_IS_STRICT(report->flags) ? " strict" : "";
exception = JSREPORT_IS_EXCEPTION(report->flags) ? " exception" : "";
warning = JSREPORT_IS_WARNING(report->flags) ? " warning" : "";
error = !report->flags ? " error" : "";
add_format_to_string(&msg, "A client script raised the following%s%s%s%s",
strict, exception, warning, error);
add_to_string(&msg, ":\n\n");
add_to_string(&msg, message);
if (report->linebuf && report->tokenptr) {
int pos = report->tokenptr - report->linebuf;
add_format_to_string(&msg, "\n\n%s\n.%*s^%*s.",
report->linebuf,
pos - 2, " ",
strlen(report->linebuf) - pos - 1, " ");
}
alert_smjs_error(msg.source);
done_string(&msg);
reported:
JS_ClearPendingException(ctx);
}
static JSRuntime *smjs_rt;
void
init_smjs(struct module *module)
{
smjs_rt = JS_NewRuntime(1L * 1024L * 1024L);
if (!smjs_rt) return;
smjs_ctx = JS_NewContext(smjs_rt, 8192);
if (!smjs_ctx) return;
JS_SetErrorReporter(smjs_ctx, error_reporter);
}
void
cleanup_smjs(struct module *module)
{
JS_DestroyContext(smjs_ctx);
JS_DestroyRuntime(smjs_rt);
}

18
src/scripting/smjs/core.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef EL__SCRIPTING_SMJS_CORE_H
#define EL__SCRIPTING_SMJS_CORE_H
#include "ecmascript/spidermonkey/util.h"
struct module;
struct session;
struct string;
extern JSContext *smjs_ctx;
struct session *smjs_ses;
void alert_smjs_error(unsigned char *msg);
void init_smjs(struct module *module);
void cleanup_smjs(struct module *module);
#endif

21
src/scripting/smjs/smjs.c Normal file
View File

@ -0,0 +1,21 @@
/* ECMAScript browser scripting module */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "elinks.h"
#include "main/module.h"
#include "scripting/smjs/core.h"
struct module smjs_scripting_module = struct_module(
/* name: */ "ECMAScript scripting engine",
/* options: */ NULL,
/* events: */ NULL,
/* submodules: */ NULL,
/* data: */ NULL,
/* init: */ init_smjs,
/* done: */ cleanup_smjs
);

View File

@ -0,0 +1,8 @@
#ifndef EL__SCRIPTING_SMJS_SMJS_H
#define EL__SCRIPTING_SMJS_SMJS_H
struct module;
extern struct module smjs_scripting_module;
#endif