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

[mujs] console

This commit is contained in:
Witold Filipczyk 2022-08-07 17:00:53 +02:00
parent 5f18359a6f
commit 8b4726a072
4 changed files with 121 additions and 1 deletions

View File

@ -25,6 +25,7 @@
#include "document/view.h" #include "document/view.h"
#include "ecmascript/ecmascript.h" #include "ecmascript/ecmascript.h"
#include "ecmascript/mujs.h" #include "ecmascript/mujs.h"
#include "ecmascript/mujs/console.h"
#include "ecmascript/mujs/history.h" #include "ecmascript/mujs/history.h"
#include "ecmascript/mujs/navigator.h" #include "ecmascript/mujs/navigator.h"
#include "ecmascript/mujs/screen.h" #include "ecmascript/mujs/screen.h"
@ -84,6 +85,7 @@ mujs_get_interpreter(struct ecmascript_interpreter *interpreter)
mjs_unibar_init(interpreter, J); mjs_unibar_init(interpreter, J);
mjs_navigator_init(interpreter, J); mjs_navigator_init(interpreter, J);
mjs_history_init(interpreter, J); mjs_history_init(interpreter, J);
mjs_console_init(interpreter, J);
return J; return J;
#if 0 #if 0

View File

@ -0,0 +1,108 @@
/* The QuickJS console 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 "config/home.h"
#include "dialogs/menu.h"
#include "dialogs/status.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/mujs.h"
#include "ecmascript/mujs/console.h"
#include "intl/libintl.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"
#include "util/conv.h"
#include "util/memory.h"
#include "util/string.h"
#include <time.h>
#include "document/renderer.h"
#include "document/refresh.h"
#include "terminal/screen.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_touserdata(J, 0, "console");
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(struct ecmascript_interpreter *interpreter, js_State *J)
{
js_getglobal(J, "Object");
js_getproperty(J, -1, "prototype");
js_newuserdata(J, "console", interpreter, NULL);
js_newcfunction(J, mjs_console_log, "console.prototype.log", 1);
js_defproperty(J, -2, "log", JS_DONTENUM);
js_newcfunction(J, mjs_console_error, "console.prototype.error", 1);
js_defproperty(J, -2, "error", JS_DONTENUM);
js_newcfunction(J, mjs_console_toString, "console.prototype.toString", 0);
js_defproperty(J, -2, "toString", JS_DONTENUM);
js_defglobal(J, "console", JS_DONTENUM);
return 0;
}

View File

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

View File

@ -1,3 +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', #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') #'input.cpp', 'localstorage.cpp', 'location.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp')
srcs += files('history.cpp', 'navigator.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp') srcs += files('console.cpp', 'history.cpp', 'navigator.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp')