mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
SpiderMonkey Update v0.1.a - Console Log
This commit is contained in:
parent
dfbd75c958
commit
c6a3d04e21
@ -25,6 +25,7 @@
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/spidermonkey.h"
|
||||
#include "ecmascript/spidermonkey/console.h"
|
||||
#include "ecmascript/spidermonkey/document.h"
|
||||
#include "ecmascript/spidermonkey/form.h"
|
||||
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||
@ -207,7 +208,7 @@ void *
|
||||
spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
{
|
||||
JSContext *ctx;
|
||||
JSObject *document_obj, *forms_obj, *history_obj, *location_obj,
|
||||
JSObject *console_obj, *document_obj, *forms_obj, *history_obj, *location_obj,
|
||||
*statusbar_obj, *menubar_obj, *navigator_obj;
|
||||
|
||||
static int initialized = 0;
|
||||
@ -315,6 +316,16 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
if (!navigator_obj) {
|
||||
goto release_and_fail;
|
||||
}
|
||||
|
||||
console_obj = spidermonkey_InitClass(ctx, window_obj, NULL,
|
||||
&console_class, NULL, 0,
|
||||
console_props,
|
||||
console_funcs,
|
||||
NULL, NULL);
|
||||
if (!console_obj) {
|
||||
goto release_and_fail;
|
||||
}
|
||||
|
||||
JS_SetCompartmentPrivate(js::GetContextCompartment(ctx), interpreter);
|
||||
|
||||
return ctx;
|
||||
|
@ -2,6 +2,6 @@ top_builddir=../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||
|
||||
OBJS = document.o form.o heartbeat.o location.o navigator.o unibar.o window.o
|
||||
OBJS = console.o document.o form.o heartbeat.o location.o navigator.o unibar.o window.o
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
137
src/ecmascript/spidermonkey/console.c
Normal file
137
src/ecmascript/spidermonkey/console.c
Normal file
@ -0,0 +1,137 @@
|
||||
/* The SpiderMonkey 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/spidermonkey/util.h"
|
||||
|
||||
#include "bfu/dialog.h"
|
||||
#include "cache/cache.h"
|
||||
#include "config/home.h"
|
||||
#include "cookies/cookies.h"
|
||||
#include "dialogs/menu.h"
|
||||
#include "dialogs/status.h"
|
||||
#include "document/html/frames.h"
|
||||
#include "document/document.h"
|
||||
#include "document/forms.h"
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/spidermonkey/console.h"
|
||||
#include "ecmascript/spidermonkey/form.h"
|
||||
#include "ecmascript/spidermonkey/location.h"
|
||||
#include "ecmascript/spidermonkey/document.h"
|
||||
#include "ecmascript/spidermonkey/window.h"
|
||||
#include "intl/gettext/libintl.h"
|
||||
#include "main/select.h"
|
||||
#include "osdep/newwin.h"
|
||||
#include "osdep/sysname.h"
|
||||
#include "protocol/http/http.h"
|
||||
#include "protocol/uri.h"
|
||||
#include "session/history.h"
|
||||
#include "session/location.h"
|
||||
#include "session/session.h"
|
||||
#include "session/task.h"
|
||||
#include "terminal/tab.h"
|
||||
#include "terminal/terminal.h"
|
||||
#include "util/conv.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include "viewer/text/draw.h"
|
||||
#include "viewer/text/form.h"
|
||||
#include "viewer/text/link.h"
|
||||
#include "viewer/text/vs.h"
|
||||
|
||||
#include <time.h>
|
||||
#include "document/renderer.h"
|
||||
#include "document/refresh.h"
|
||||
#include "terminal/screen.h"
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
static bool console_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
|
||||
|
||||
JSClassOps console_ops = {
|
||||
JS_PropertyStub, nullptr,
|
||||
console_get_property, JS_StrictPropertyStub,
|
||||
nullptr, nullptr, nullptr
|
||||
};
|
||||
|
||||
/* Each @console_class object must have a @window_class parent. */
|
||||
const JSClass console_class = {
|
||||
"console",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
&console_ops
|
||||
};
|
||||
|
||||
/* Tinyids of properties. Use negative values to distinguish these
|
||||
* from array indexes (even though this object has no array elements).
|
||||
* ECMAScript code should not use these directly as in document[-1];
|
||||
* future versions of ELinks may change the numbers. */
|
||||
enum console_prop {
|
||||
JSP_LOCALSTORAGE_LOC = -1,
|
||||
JSP_LOCALSTORAGE_REF = -2,
|
||||
JSP_LOCALSTORAGE_TITLE = -3,
|
||||
JSP_LOCALSTORAGE_URL = -4,
|
||||
};
|
||||
/* "cookie" is special; it isn't a regular property but we channel it to the
|
||||
* cookie-module. XXX: Would it work if "cookie" was defined in this array? */
|
||||
const JSPropertySpec console_props[] = {
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* @console_class.getProperty */
|
||||
static bool
|
||||
console_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||
{
|
||||
JSObject *parent_win; /* instance of @window_class */
|
||||
struct view_state *vs;
|
||||
struct document_view *doc_view;
|
||||
struct document *document;
|
||||
struct session *ses;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool console_log(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
|
||||
const spidermonkeyFunctionSpec console_funcs[] = {
|
||||
{ "log", console_log, 2 },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static bool
|
||||
console_log(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
|
||||
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||
struct session *ses = doc_view->session;
|
||||
struct terminal *term = ses->tab->term;
|
||||
struct string *ret = interpreter->ret;
|
||||
struct document *document;
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
document = doc_view->document;
|
||||
|
||||
if (argc != 1) {
|
||||
args.rval().setBoolean(true);
|
||||
return(true);
|
||||
}
|
||||
|
||||
unsigned char *key= JS_EncodeString(ctx, args[0].toString());
|
||||
char log_fname[8192]="";
|
||||
strcat(log_fname,elinks_home);
|
||||
strcat(log_fname,"console.log");
|
||||
FILE *f = fopen(log_fname,"a");
|
||||
fprintf(f, "%s\n", key);
|
||||
fclose(f);
|
||||
args.rval().setBoolean(true);
|
||||
return(true);
|
||||
|
||||
}
|
11
src/ecmascript/spidermonkey/console.h
Normal file
11
src/ecmascript/spidermonkey/console.h
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
#ifndef EL__ECMASCRIPT_SPIDERMONKEY_CONSOLE_H
|
||||
#define EL__ECMASCRIPT_SPIDERMONKEY_CONSOLE_H
|
||||
|
||||
#include "ecmascript/spidermonkey/util.h"
|
||||
|
||||
extern const JSClass console_class;
|
||||
extern const spidermonkeyFunctionSpec console_funcs[];
|
||||
extern const JSPropertySpec console_props[];
|
||||
|
||||
#endif
|
13
test/ecmascript/console_log.html
Normal file
13
test/ecmascript/console_log.html
Normal file
@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<body onload="hello()">
|
||||
<script>
|
||||
function hello() {
|
||||
console.log("Hello World");
|
||||
}
|
||||
</script>
|
||||
<pre>
|
||||
You'll find the console.log
|
||||
at config dir (~/elinks)
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user