mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[mujs] console.c
This commit is contained in:
parent
9a3ffecf65
commit
e0ad0c64d6
@ -1,6 +1,6 @@
|
||||
top_builddir=../../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
|
||||
OBJS = attr.o attributes.o collection.o mapa.obj
|
||||
OBJS = attr.o attributes.o collection.o console.o mapa.obj
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
86
src/ecmascript/libdom/mujs/console.c
Normal file
86
src/ecmascript/libdom/mujs/console.c
Normal file
@ -0,0 +1,86 @@
|
||||
/* The MuJS console object implementation. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/mujs.h"
|
||||
#include "ecmascript/mujs/console.h"
|
||||
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
static void
|
||||
mjs_console_log_common(js_State *J, const char *str, const char *log_filename)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
|
||||
assert(interpreter);
|
||||
|
||||
if (log_filename && get_opt_bool("ecmascript.enable_console_log", NULL) && str)
|
||||
{
|
||||
FILE *f = fopen(log_filename, "a");
|
||||
|
||||
if (f)
|
||||
{
|
||||
fprintf(f, "%s\n", str);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
js_pushundefined(J);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_console_log(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
const char *str = js_tostring(J, 1);
|
||||
|
||||
mjs_console_log_common(J, str, console_log_filename);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_console_error(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
const char *str = js_tostring(J, 1);
|
||||
|
||||
mjs_console_log_common(J, str, console_error_filename);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_console_toString(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
js_pushstring(J, "[console object]");
|
||||
}
|
||||
|
||||
int
|
||||
mjs_console_init(js_State *J)
|
||||
{
|
||||
js_newobject(J);
|
||||
{
|
||||
addmethod(J, "console.log", mjs_console_log, 1);
|
||||
addmethod(J, "console.error", mjs_console_error, 1);
|
||||
addmethod(J, "console.toString", mjs_console_toString, 0);
|
||||
}
|
||||
js_defglobal(J, "console", JS_DONTENUM);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1 +1 @@
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'mapa.cpp')
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'mapa.cpp')
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "document/refresh.h"
|
||||
#include "terminal/screen.h"
|
||||
|
||||
#ifndef CONFIG_LIBDOM
|
||||
#define DEBUG 0
|
||||
|
||||
static void
|
||||
@ -99,3 +100,4 @@ mjs_console_init(js_State *J)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -3,6 +3,14 @@
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int mjs_console_init(js_State *J);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user