1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-27 01:25:34 +00:00

[spidermonkey] history.c

This commit is contained in:
Witold Filipczyk 2021-10-25 17:22:42 +02:00
parent 97daf0871a
commit 44a286f8af
7 changed files with 194 additions and 142 deletions

View File

@ -31,6 +31,7 @@
#include "ecmascript/spidermonkey/document.h"
#include "ecmascript/spidermonkey/form.h"
#include "ecmascript/spidermonkey/heartbeat.h"
#include "ecmascript/spidermonkey/history.h"
#include "ecmascript/spidermonkey/location.h"
#include "ecmascript/spidermonkey/localstorage.h"
#include "ecmascript/spidermonkey/navigator.h"

View File

@ -2,7 +2,7 @@ top_builddir=../../..
include $(top_builddir)/Makefile.config
INCLUDES += $(SPIDERMONKEY_CFLAGS)
OBJS = attr.o attributes.o collection.o console.o css2xpath.o document.o element.o form.o heartbeat.o implementation.o location.o \
localstorage.o localstorage-db.o navigator.o nodelist.o screen.o unibar.o window.o
OBJS = attr.o attributes.o collection.o console.o css2xpath.o document.o element.o form.o heartbeat.o history.o implementation.o \
location.o localstorage.o localstorage-db.o navigator.o nodelist.o screen.o unibar.o window.o
include $(top_srcdir)/Makefile.lib

View File

@ -0,0 +1,180 @@
/* The SpiderMonkey history 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 <jsfriendapi.h>
#include "bfu/dialog.h"
#include "cache/cache.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/history.h"
#include "intl/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"
static bool history_back(JSContext *ctx, unsigned int argc, JS::Value *rval);
static bool history_forward(JSContext *ctx, unsigned int argc, JS::Value *rval);
static bool history_go(JSContext *ctx, unsigned int argc, JS::Value *rval);
JSClassOps history_ops = {
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
JS_GlobalObjectTraceHook
};
JSClass history_class = {
"history",
JSCLASS_HAS_PRIVATE,
&history_ops
};
const spidermonkeyFunctionSpec history_funcs[] = {
{ "back", history_back, 0 },
{ "forward", history_forward, 0 },
{ "go", history_go, 1 },
{ NULL }
};
/* @history_funcs{"back"} */
static bool
history_back(JSContext *ctx, unsigned int argc, JS::Value *rval)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JS::Realm *comp = js::GetContextRealm(ctx);
if (!comp) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
go_back(ses);
/* history_back() must return 0 for onClick to cause displaying previous page
* and return non zero for <a href="javascript:history.back()"> to prevent
* "calculating" new link. Returned value 2 is changed to 0 in function
* spidermonkey_eval_boolback */
args.rval().setNull();
return 2;
}
/* @history_funcs{"forward"} */
static bool
history_forward(JSContext *ctx, unsigned int argc, JS::Value *rval)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JS::Realm *comp = js::GetContextRealm(ctx);
if (!comp) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp);
// struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
go_unback(ses);
args.rval().setNull();
return 2;
}
/* @history_funcs{"go"} */
static bool
history_go(JSContext *ctx, unsigned int argc, JS::Value *rval)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JS::Realm *comp = js::GetContextRealm(ctx);
if (!comp) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp);
// struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
struct location *loc;
if (argc != 1)
return true;
int index = args[0].toInt32();
for (loc = cur_loc(ses);
loc != (struct location *) &ses->history.history;
loc = index > 0 ? loc->next : loc->prev) {
if (!index) {
go_history(ses, loc);
break;
}
index += index > 0 ? -1 : 1;
}
args.rval().setNull();
return 2;
}

View File

@ -0,0 +1,9 @@
#ifndef EL__ECMASCRIPT_SPIDERMONKEY_HISTORY_H
#define EL__ECMASCRIPT_SPIDERMONKEY_HISTORY_H
#include "ecmascript/spidermonkey/util.h"
extern JSClass history_class;
extern const spidermonkeyFunctionSpec history_funcs[];
#endif

View File

@ -1,4 +1,4 @@
/* The SpiderMonkey location and history objects implementation. */
/* The SpiderMonkey location object implementation. */
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -45,141 +45,6 @@
#include "viewer/text/link.h"
#include "viewer/text/vs.h"
static bool history_back(JSContext *ctx, unsigned int argc, JS::Value *rval);
static bool history_forward(JSContext *ctx, unsigned int argc, JS::Value *rval);
static bool history_go(JSContext *ctx, unsigned int argc, JS::Value *rval);
JSClassOps history_ops = {
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
JS_GlobalObjectTraceHook
};
JSClass history_class = {
"history",
JSCLASS_HAS_PRIVATE,
&history_ops
};
const spidermonkeyFunctionSpec history_funcs[] = {
{ "back", history_back, 0 },
{ "forward", history_forward, 0 },
{ "go", history_go, 1 },
{ NULL }
};
/* @history_funcs{"back"} */
static bool
history_back(JSContext *ctx, unsigned int argc, JS::Value *rval)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JS::Realm *comp = js::GetContextRealm(ctx);
if (!comp) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
go_back(ses);
/* history_back() must return 0 for onClick to cause displaying previous page
* and return non zero for <a href="javascript:history.back()"> to prevent
* "calculating" new link. Returned value 2 is changed to 0 in function
* spidermonkey_eval_boolback */
args.rval().setNull();
return 2;
}
/* @history_funcs{"forward"} */
static bool
history_forward(JSContext *ctx, unsigned int argc, JS::Value *rval)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JS::Realm *comp = js::GetContextRealm(ctx);
if (!comp) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp);
// struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
go_unback(ses);
args.rval().setNull();
return 2;
}
/* @history_funcs{"go"} */
static bool
history_go(JSContext *ctx, unsigned int argc, JS::Value *rval)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JS::Realm *comp = js::GetContextRealm(ctx);
if (!comp) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp);
// struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
struct location *loc;
if (argc != 1)
return true;
int index = args[0].toInt32();
for (loc = cur_loc(ses);
loc != (struct location *) &ses->history.history;
loc = index > 0 ? loc->next : loc->prev) {
if (!index) {
go_history(ses, loc);
break;
}
index += index > 0 ? -1 : 1;
}
args.rval().setNull();
return 2;
}
static void location_goto_common(JSContext *ctx, struct document_view *doc_view, JS::HandleValue val);
static bool location_get_property_hash(JSContext *ctx, unsigned int argc, JS::Value *vp);
static bool location_set_property_hash(JSContext *ctx, unsigned int argc, JS::Value *vp);

View File

@ -4,9 +4,6 @@
#include "ecmascript/spidermonkey/util.h"
extern JSClass history_class;
extern const spidermonkeyFunctionSpec history_funcs[];
extern JSClass location_class;
extern const spidermonkeyFunctionSpec location_funcs[];
extern JSPropertySpec location_props[];

View File

@ -1,3 +1,3 @@
#INCLUDES += $(SPIDERMONKEY_CFLAGS)
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'css2xpath.c', 'document.c', 'element.c', 'form.c', 'heartbeat.c', 'implementation.c', 'location.c', 'localstorage.c', 'localstorage-db.c', 'navigator.c', 'nodelist.c', 'screen.c', 'unibar.c', 'window.c')
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'css2xpath.c', 'document.c', 'element.c', 'form.c', 'heartbeat.c', 'history.c', 'implementation.c', 'location.c', 'localstorage.c', 'localstorage-db.c', 'navigator.c', 'nodelist.c', 'screen.c', 'unibar.c', 'window.c')