1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-29 03:17:53 -04:00

[quickjs] Removed old code

This commit is contained in:
Witold Filipczyk 2023-05-04 16:09:09 +02:00
parent 70e295f90b
commit 1544b1fd02
26 changed files with 0 additions and 13373 deletions

View File

@ -6,8 +6,6 @@ SUBDIRS-$(CONFIG_LIBDOM) += libdom
SUBDIRS-$(CONFIG_MUJS) += mujs
SUBDIRS-$(CONFIG_QUICKJS) += quickjs
OBJS-$(CONFIG_ECMASCRIPT_SMJS) += css2xpath.obj ecmascript.obj localstorage-db.obj spidermonkey.obj timer.obj
OBJS-$(CONFIG_MUJS) += css2xpath.obj ecmascript.obj localstorage-db.obj mujs.obj timer.obj

View File

@ -21,7 +21,6 @@ if conf_data.get('CONFIG_MUJS')
endif
if conf_data.get('CONFIG_QUICKJS')
subdir('quickjs')
srcs += files('css2xpath.cpp', 'ecmascript.cpp', 'localstorage-db.cpp', 'quickjs.cpp', 'timer.cpp')
endif

View File

@ -1,8 +0,0 @@
top_builddir=../../..
include $(top_builddir)/Makefile.config
OBJS = attr.obj attributes.obj collection.obj console.obj document.obj element.obj form.obj \
forms.obj heartbeat.obj history.obj implementation.obj input.obj keyboard.obj location.obj \
localstorage.obj message.obj navigator.obj nodelist.obj screen.obj unibar.obj window.obj xhr.obj
include $(top_srcdir)/Makefile.lib

View File

@ -1,189 +0,0 @@
/* The QuickJS attr 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 "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/quickjs.h"
#include "ecmascript/quickjs/attr.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"
#include <libxml/tree.h>
#include <libxml/HTMLparser.h>
#include <libxml++/libxml++.h>
#include <libxml++/attributenode.h>
#include <libxml++/parsers/domparser.h>
#include <iostream>
#include <algorithm>
#include <string>
#define countof(x) (sizeof(x) / sizeof((x)[0]))
#ifndef CONFIG_LIBDOM
static JSClassID js_attr_class_id;
static JSValue
js_attr_get_property_name(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
xmlpp::AttributeNode *attr = static_cast<xmlpp::AttributeNode *>(JS_GetOpaque(this_val, js_attr_class_id));
if (!attr) {
return JS_NULL;
}
xmlpp::ustring v = attr->get_name();
JSValue r = JS_NewString(ctx, v.c_str());
RETURN_JS(r);
}
static JSValue
js_attr_get_property_value(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
xmlpp::AttributeNode *attr = static_cast<xmlpp::AttributeNode *>(JS_GetOpaque(this_val, js_attr_class_id));
if (!attr) {
return JS_NULL;
}
xmlpp::ustring v = attr->get_value();
JSValue r = JS_NewString(ctx, v.c_str());
RETURN_JS(r);
}
static JSValue
js_attr_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[attr object]");
}
static const JSCFunctionListEntry js_attr_proto_funcs[] = {
JS_CGETSET_DEF("name", js_attr_get_property_name, nullptr),
JS_CGETSET_DEF("value", js_attr_get_property_value, nullptr),
JS_CFUNC_DEF("toString", 0, js_attr_toString)
};
static std::map<void *, JSValueConst> map_attrs;
static
void js_attr_finalizer(JSRuntime *rt, JSValue val)
{
REF_JS(val);
void *node = JS_GetOpaque(val, js_attr_class_id);
map_attrs.erase(node);
}
static JSClassDef js_attr_class = {
"attr",
js_attr_finalizer
};
JSValue
getAttr(JSContext *ctx, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
static int initialized;
/* create the element class */
if (!initialized) {
JS_NewClassID(&js_attr_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_attr_class_id, &js_attr_class);
initialized = 1;
}
auto node_find = map_attrs.find(node);
if (node_find != map_attrs.end()) {
JSValue r = JS_DupValue(ctx, node_find->second);
RETURN_JS(r);
}
JSValue attr_obj = JS_NewObjectClass(ctx, js_attr_class_id);
JS_SetPropertyFunctionList(ctx, attr_obj, js_attr_proto_funcs, countof(js_attr_proto_funcs));
JS_SetClassProto(ctx, js_attr_class_id, attr_obj);
JS_SetOpaque(attr_obj, node);
map_attrs[node] = attr_obj;
JSValue rr = JS_DupValue(ctx, attr_obj);
RETURN_JS(rr);
}
#endif

View File

@ -1,319 +0,0 @@
/* The QuickJS attributes 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 "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/quickjs.h"
#include "ecmascript/quickjs/attr.h"
#include "ecmascript/quickjs/attributes.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"
#include <libxml/tree.h>
#include <libxml/HTMLparser.h>
#include <libxml++/libxml++.h>
#include <libxml++/attributenode.h>
#include <libxml++/parsers/domparser.h>
#include <iostream>
#include <algorithm>
#include <string>
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static std::map<void *, JSValueConst> map_attributes;
static std::map<JSValueConst, void *> map_rev_attributes;
static void *
js_attributes_GetOpaque(JSValueConst this_val)
{
REF_JS(this_val);
return map_rev_attributes[this_val];
}
static void
js_attributes_SetOpaque(JSValueConst this_val, void *node)
{
REF_JS(this_val);
if (!node) {
map_rev_attributes.erase(this_val);
} else {
map_rev_attributes[this_val] = node;
}
}
static void
js_attributes_set_items(JSContext *ctx, JSValue this_val, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
xmlpp::Element::AttributeList *al = static_cast<xmlpp::Element::AttributeList *>(node);
if (!al) {
return;
}
auto it = al->begin();
auto end = al->end();
int i = 0;
for (;it != end; ++it, ++i) {
xmlpp::Attribute *attr = *it;
if (!attr) {
continue;
}
JSValue obj = getAttr(ctx, attr);
REF_JS(obj);
JS_SetPropertyUint32(ctx, this_val, i, JS_DupValue(ctx, obj));
xmlpp::ustring name = attr->get_name();
if (name != "" && name != "item" && name != "namedItem") {
JS_DefinePropertyValueStr(ctx, this_val, name.c_str(), JS_DupValue(ctx, obj), 0);
}
JS_FreeValue(ctx, obj);
}
}
static JSValue
js_attributes_get_property_length(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
xmlpp::Element::AttributeList *al = static_cast<xmlpp::Element::AttributeList *>(js_attributes_GetOpaque(this_val));
if (!al) {
return JS_NewInt32(ctx, 0);
}
return JS_NewInt32(ctx, al->size());
}
static JSValue
js_attributes_item2(JSContext *ctx, JSValueConst this_val, int idx)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
xmlpp::Element::AttributeList *al = static_cast<xmlpp::Element::AttributeList *>(js_attributes_GetOpaque(this_val));
if (!al) {
return JS_UNDEFINED;
}
auto it = al->begin();
auto end = al->end();
int i = 0;
for (;it != end; it++, i++) {
if (i != idx) {
continue;
}
xmlpp::Attribute *attr = *it;
return getAttr(ctx, attr);
}
return JS_UNDEFINED;
}
static JSValue
js_attributes_item(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1) {
return JS_UNDEFINED;
}
int index;
JS_ToInt32(ctx, &index, argv[0]);
return js_attributes_item2(ctx, this_val, index);
}
static JSValue
js_attributes_namedItem2(JSContext *ctx, JSValueConst this_val, const char *str)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
xmlpp::Element::AttributeList *al = static_cast<xmlpp::Element::AttributeList *>(js_attributes_GetOpaque(this_val));
if (!al) {
return JS_UNDEFINED;
}
xmlpp::ustring name = str;
auto it = al->begin();
auto end = al->end();
for (; it != end; ++it) {
auto attr = dynamic_cast<xmlpp::AttributeNode*>(*it);
if (!attr) {
continue;
}
if (name == attr->get_name()) {
JSValue obj = getAttr(ctx, attr);
RETURN_JS(obj);
}
}
return JS_UNDEFINED;
}
static JSValue
js_attributes_getNamedItem(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1) {
return JS_UNDEFINED;
}
const char *str;
size_t len;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
JSValue ret = js_attributes_namedItem2(ctx, this_val, str);
JS_FreeCString(ctx, str);
RETURN_JS(ret);
}
static JSValue
js_attributes_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[attributes object]");
}
static const JSCFunctionListEntry js_attributes_proto_funcs[] = {
JS_CGETSET_DEF("length", js_attributes_get_property_length, nullptr),
JS_CFUNC_DEF("item", 1, js_attributes_item),
JS_CFUNC_DEF("getNamedItem", 1, js_attributes_getNamedItem),
JS_CFUNC_DEF("toString", 0, js_attributes_toString)
};
#if 0
static void
js_attributes_finalizer(JSRuntime *rt, JSValue val)
{
void *node = js_attributes_GetOpaque(val);
js_attributes_SetOpaque(val, nullptr);
map_attributes.erase(node);
}
static JSClassDef js_attributes_class = {
"attributes",
js_attributes_finalizer
};
#endif
JSValue
getAttributes(JSContext *ctx, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
auto node_find = map_attributes.find(node);
if (node_find != map_attributes.end()) {
JSValue r = JS_DupValue(ctx, node_find->second);
RETURN_JS(r);
}
JSValue attributes_obj = JS_NewArray(ctx);
JS_SetPropertyFunctionList(ctx, attributes_obj, js_attributes_proto_funcs, countof(js_attributes_proto_funcs));
js_attributes_SetOpaque(attributes_obj, node);
js_attributes_set_items(ctx, attributes_obj, node);
map_attributes[node] = attributes_obj;
JSValue rr = JS_DupValue(ctx, attributes_obj);
RETURN_JS(rr);
}
#endif

View File

@ -1,371 +0,0 @@
/* The QuickJS html collection 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 "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/quickjs.h"
#include "ecmascript/quickjs/collection.h"
#include "ecmascript/quickjs/element.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"
#include <libxml/tree.h>
#include <libxml/HTMLparser.h>
#include <libxml++/libxml++.h>
#include <libxml++/attributenode.h>
#include <libxml++/parsers/domparser.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#define countof(x) (sizeof(x) / sizeof((x)[0]))
#ifndef CONFIG_LIBDOM
static std::map<void *, JSValueConst> map_collections;
static std::map<JSValueConst, void *> map_rev_collections;
static void *
js_htmlCollection_GetOpaque(JSValueConst this_val)
{
REF_JS(this_val);
return map_rev_collections[this_val];
}
static void
js_htmlCollection_SetOpaque(JSValueConst this_val, void *node)
{
REF_JS(this_val);
if (!node) {
map_rev_collections.erase(this_val);
} else {
map_rev_collections[this_val] = node;
}
}
static JSValue
js_htmlCollection_get_property_length(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
xmlpp::Node::NodeSet *ns = static_cast<xmlpp::Node::NodeSet *>(js_htmlCollection_GetOpaque(this_val));
if (!ns) {
return JS_NewInt32(ctx, 0);
}
return JS_NewInt32(ctx, ns->size());
}
static JSValue
js_htmlCollection_item2(JSContext *ctx, JSValueConst this_val, int idx)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
xmlpp::Node::NodeSet *ns = static_cast<xmlpp::Node::NodeSet *>(js_htmlCollection_GetOpaque(this_val));
if (!ns) {
return JS_UNDEFINED;
}
xmlpp::Element *element;
try {
element = dynamic_cast<xmlpp::Element *>(ns->at(idx));
} catch (std::out_of_range &e) { return JS_UNDEFINED;}
if (!element) {
return JS_UNDEFINED;
}
return getElement(ctx, element);
}
static JSValue
js_htmlCollection_item(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1) {
return JS_UNDEFINED;
}
int index;
JS_ToInt32(ctx, &index, argv[0]);
return js_htmlCollection_item2(ctx, this_val, index);
}
static JSValue
js_htmlCollection_namedItem2(JSContext *ctx, JSValueConst this_val, const char *str)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
xmlpp::Node::NodeSet *ns = static_cast<xmlpp::Node::NodeSet *>(js_htmlCollection_GetOpaque(this_val));
if (!ns) {
return JS_UNDEFINED;
}
xmlpp::ustring name = str;
auto it = ns->begin();
auto end = ns->end();
for (; it != end; ++it) {
auto element = dynamic_cast<xmlpp::Element*>(*it);
if (!element) {
continue;
}
if (name == element->get_attribute_value("id")
|| name == element->get_attribute_value("name")) {
return getElement(ctx, element);
}
}
return JS_UNDEFINED;
}
static JSValue
js_htmlCollection_namedItem(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1) {
return JS_UNDEFINED;
}
const char *str;
size_t len;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
JSValue ret = js_htmlCollection_namedItem2(ctx, this_val, str);
JS_FreeCString(ctx, str);
RETURN_JS(ret);
}
static void
js_htmlCollection_set_items(JSContext *ctx, JSValue this_val, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
int counter = 0;
xmlpp::Node::NodeSet *ns = static_cast<xmlpp::Node::NodeSet *>(js_htmlCollection_GetOpaque(this_val));
if (!ns) {
return;
}
xmlpp::Element *element;
while (1) {
try {
element = dynamic_cast<xmlpp::Element *>(ns->at(counter));
} catch (std::out_of_range &e) { return;}
if (!element) {
return;
}
JSValue obj = getElement(ctx, element);
REF_JS(obj);
JS_SetPropertyUint32(ctx, this_val, counter, JS_DupValue(ctx, obj));
xmlpp::ustring name = element->get_attribute_value("id");
if (name == "") {
name = element->get_attribute_value("name");
}
if (name != "" && name != "item" && name != "namedItem") {
JS_DefinePropertyValueStr(ctx, this_val, name.c_str(), JS_DupValue(ctx, obj), 0);
}
JS_FreeValue(ctx, obj);
counter++;
}
}
static JSValue
js_htmlCollection_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[htmlCollection object]");
}
static const JSCFunctionListEntry js_htmlCollection_proto_funcs[] = {
JS_CGETSET_DEF("length", js_htmlCollection_get_property_length, nullptr),
JS_CFUNC_DEF("item", 1, js_htmlCollection_item),
JS_CFUNC_DEF("namedItem", 1, js_htmlCollection_namedItem),
JS_CFUNC_DEF("toString", 0, js_htmlCollection_toString)
};
#if 0
static void
js_htmlCollection_finalizer(JSRuntime *rt, JSValue val)
{
REF_JS(val);
void *node = js_htmlCollection_GetOpaque(val);
js_htmlCollection_SetOpaque(val, nullptr);
map_collections.erase(node);
}
static JSClassDef js_htmlCollection_class = {
"htmlCollection",
js_htmlCollection_finalizer
};
#endif
#if 0
static JSValue
js_htmlCollection_ctor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
{
JSValue obj = JS_UNDEFINED;
JSValue proto;
/* using new_target to get the prototype is necessary when the
class is extended. */
proto = JS_GetPropertyStr(ctx, new_target, "prototype");
if (JS_IsException(proto)) {
goto fail;
}
obj = JS_NewObjectProtoClass(ctx, proto, js_htmlCollection_class_id);
JS_FreeValue(ctx, proto);
if (JS_IsException(obj)) {
goto fail;
}
RETURN_JS(obj);
fail:
JS_FreeValue(ctx, obj);
return JS_EXCEPTION;
}
int
js_htmlCollection_init(JSContext *ctx, JSValue global_obj)
{
REF_JS(global_obj);
JSValue htmlCollection_proto, htmlCollection_class;
/* create the htmlCollection class */
JS_NewClassID(&js_htmlCollection_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_htmlCollection_class_id, &js_htmlCollection_class);
htmlCollection_proto = JS_NewObject(ctx);
REF_JS(htmlCollection_proto);
JS_SetPropertyFunctionList(ctx, htmlCollection_proto, js_htmlCollection_proto_funcs, countof(js_htmlCollection_proto_funcs));
htmlCollection_class = JS_NewCFunction2(ctx, js_htmlCollection_ctor, "htmlCollection", 0, JS_CFUNC_constructor, 0);
REF_JS(htmlCollection_class);
/* set proto.constructor and ctor.prototype */
JS_SetConstructor(ctx, htmlCollection_class, htmlCollection_proto);
JS_SetClassProto(ctx, js_htmlCollection_class_id, htmlCollection_proto);
JS_SetPropertyStr(ctx, global_obj, "htmlCollection", htmlCollection_proto);
return 0;
}
#endif
JSValue
getCollection(JSContext *ctx, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
auto node_find = map_collections.find(node);
if (node_find != map_collections.end()) {
JSValue r = JS_DupValue(ctx, node_find->second);
RETURN_JS(r);
}
JSValue htmlCollection_obj = JS_NewArray(ctx);
JS_SetPropertyFunctionList(ctx, htmlCollection_obj, js_htmlCollection_proto_funcs, countof(js_htmlCollection_proto_funcs));
js_htmlCollection_SetOpaque(htmlCollection_obj, node);
js_htmlCollection_set_items(ctx, htmlCollection_obj, node);
map_collections[node] = htmlCollection_obj;
JSValue rr = JS_DupValue(ctx, htmlCollection_obj);
RETURN_JS(rr);
}
#endif

View File

@ -1,139 +0,0 @@
/* 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/quickjs.h"
#include "ecmascript/quickjs/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
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_console_class_id;
static JSValue
js_console_log_common(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, const char *log_filename)
{
REF_JS(this_val);
if (argc != 1 || !log_filename)
{
return JS_UNDEFINED;
}
if (get_opt_bool("ecmascript.enable_console_log", NULL))
{
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
FILE *f = fopen(log_filename, "a");
if (f)
{
fprintf(f, "%s\n", str);
fclose(f);
}
JS_FreeCString(ctx, str);
}
return JS_UNDEFINED;
}
static JSValue
js_console_log(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return js_console_log_common(ctx, this_val, argc, argv, console_log_filename);
}
static JSValue
js_console_error(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return js_console_log_common(ctx, this_val, argc, argv, console_error_filename);
}
static JSValue
js_console_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[console object]");
}
static const JSCFunctionListEntry js_console_funcs[] = {
JS_CFUNC_DEF("log", 1, js_console_log),
JS_CFUNC_DEF("error", 1, js_console_error),
JS_CFUNC_DEF("toString", 0, js_console_toString)
};
static JSClassDef js_console_class = {
"console",
};
int
js_console_init(JSContext *ctx)
{
JSValue console_proto;
/* create the console class */
JS_NewClassID(&js_console_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_console_class_id, &js_console_class);
JSValue global_obj = JS_GetGlobalObject(ctx);
REF_JS(global_obj);
console_proto = JS_NewObject(ctx);
REF_JS(console_proto);
JS_SetPropertyFunctionList(ctx, console_proto, js_console_funcs, countof(js_console_funcs));
JS_SetClassProto(ctx, js_console_class_id, console_proto);
JS_SetPropertyStr(ctx, global_obj, "console", JS_DupValue(ctx, console_proto));
JS_FreeValue(ctx, global_obj);
return 0;
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,360 +0,0 @@
/* The SpiderMonkey window 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 "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/quickjs.h"
#include "ecmascript/quickjs/document.h"
#include "ecmascript/quickjs/form.h"
#include "ecmascript/quickjs/forms.h"
#include "ecmascript/quickjs/input.h"
#include "ecmascript/quickjs/window.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"
#include <libxml++/libxml++.h>
#include <map>
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static std::map<void *, JSValueConst> map_forms;
static std::map<JSValueConst, void *> map_rev_forms;
#if 0
static void *
forms_GetOpaque(JSValueConst this_val)
{
return map_rev_forms[this_val];
}
#endif
static void
forms_SetOpaque(JSValueConst this_val, void *node)
{
REF_JS(this_val);
if (!node) {
map_rev_forms.erase(this_val);
} else {
map_rev_forms[this_val] = node;
}
}
/* Find the form whose name is @name, which should normally be a
* string (but might not be). */
static JSValue
js_find_form_by_name(JSContext *ctx,
struct document_view *doc_view,
const char *string)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct form *form;
if (!*string)
return JS_NULL;
foreach (form, doc_view->document->forms) {
if (form->name && !c_strcasecmp(string, form->name)) {
return js_get_form_object(ctx, JS_NULL, form);
}
}
return JS_NULL;
}
static void
js_forms_set_items(JSContext *ctx, JSValueConst this_val, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct view_state *vs;
struct document_view *doc_view;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
vs = interpreter->vs;
doc_view = vs->doc_view;
struct document *document = doc_view->document;
int counter = 0;
struct form_view *fv;
foreach (fv, vs->forms) {
struct form *form = find_form_by_form_view(document, fv);
JSValue v = js_get_form_object(ctx, JS_NULL, form);
REF_JS(v);
JS_SetPropertyUint32(ctx, this_val, counter, JS_DupValue(ctx, v));
if (form->name) {
if (strcmp(form->name, "item") && strcmp(form->name, "namedItem")) {
JS_SetPropertyStr(ctx, this_val, form->name, JS_DupValue(ctx, v));
}
}
JS_FreeValue(ctx, v);
counter++;
}
}
static JSValue
js_forms_get_property_length(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_UNDEFINED;
}
struct document_view *doc_view = vs->doc_view;
struct document *document = doc_view->document;
return JS_NewInt32(ctx, list_size(&document->forms));
}
static JSValue
js_forms_item2(JSContext *ctx, JSValueConst this_val, int index)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct view_state *vs;
struct form_view *fv;
int counter = -1;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
struct document *document = doc_view->document;
foreach (fv, vs->forms) {
counter++;
if (counter == index) {
struct form *form = find_form_by_form_view(document, fv);
return js_get_form_object(ctx, JS_NULL, form);
}
}
return JS_UNDEFINED;
}
/* @forms_funcs{"item"} */
static JSValue
js_forms_item(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1) {
return JS_UNDEFINED;
}
int index;
if (JS_ToInt32(ctx, &index, argv[0])) {
return JS_UNDEFINED;
}
return js_forms_item2(ctx, this_val, index);
}
/* @forms_funcs{"namedItem"} */
static JSValue
js_forms_namedItem(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1) {
return JS_UNDEFINED;
}
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
const char *str;
size_t len;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
JSValue ret = js_find_form_by_name(ctx, doc_view, str);
JS_FreeCString(ctx, str);
RETURN_JS(ret);
}
#if 0
JSString *
unicode_to_jsstring(JSContext *ctx, unicode_val_T u)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
char16_t buf[2];
/* This is supposed to make a string from which
* jsval_to_accesskey() can get the original @u back.
* If @u is a surrogate, then that is not possible, so
* return NULL to indicate an error instead.
*
* If JS_NewUCStringCopyN hits a null character, it truncates
* the string there and pads it with more nulls. However,
* that is not a problem here, because if there is a null
* character in buf[], then it must be the only character. */
if (u <= 0xFFFF && !is_utf16_surrogate(u)) {
buf[0] = u;
return JS_NewUCStringCopyN(ctx, buf, 1);
} else if (needs_utf16_surrogates(u)) {
buf[0] = get_utf16_high_surrogate(u);
buf[1] = get_utf16_low_surrogate(u);
return JS_NewUCStringCopyN(ctx, buf, 2);
} else {
return NULL;
}
}
#endif
static JSValue
js_forms_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[forms object]");
}
static const JSCFunctionListEntry js_forms_proto_funcs[] = {
JS_CGETSET_DEF("length", js_forms_get_property_length, nullptr),
JS_CFUNC_DEF("item", 1, js_forms_item),
JS_CFUNC_DEF("namedItem", 1, js_forms_namedItem),
JS_CFUNC_DEF("toString", 0, js_forms_toString)
};
#if 0
static JSValue
js_forms_ctor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
{
JSValue obj = JS_UNDEFINED;
JSValue proto;
/* using new_target to get the prototype is necessary when the
class is extended. */
proto = JS_GetPropertyStr(ctx, new_target, "prototype");
if (JS_IsException(proto)) {
goto fail;
}
obj = JS_NewObjectProtoClass(ctx, proto, js_forms_class_id);
JS_FreeValue(ctx, proto);
if (JS_IsException(obj)) {
goto fail;
}
RETURN_JS(obj);
fail:
JS_FreeValue(ctx, obj);
return JS_EXCEPTION;
}
int
js_forms_init(JSContext *ctx, JSValue global_obj)
{
JSValue forms_proto, forms_class;
/* create the forms class */
JS_NewClassID(&js_forms_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_forms_class_id, &js_forms_class);
forms_proto = JS_NewObject(ctx);
JS_SetPropertyFunctionList(ctx, forms_proto, js_forms_proto_funcs, countof(js_forms_proto_funcs));
forms_class = JS_NewCFunction2(ctx, js_forms_ctor, "forms", 0, JS_CFUNC_constructor, 0);
/* set proto.constructor and ctor.prototype */
JS_SetConstructor(ctx, forms_class, forms_proto);
JS_SetClassProto(ctx, js_forms_class_id, forms_proto);
JS_SetPropertyStr(ctx, global_obj, "forms", forms_proto);
return 0;
}
#endif
JSValue
getForms(JSContext *ctx, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
auto node_find = map_forms.find(node);
if (node_find != map_forms.end()) {
JSValue r = JS_DupValue(ctx, node_find->second);
RETURN_JS(r);
}
JSValue forms_obj = JS_NewArray(ctx);
JS_SetPropertyFunctionList(ctx, forms_obj, js_forms_proto_funcs, countof(js_forms_proto_funcs));
forms_SetOpaque(forms_obj, node);
js_forms_set_items(ctx, forms_obj, node);
map_forms[node] = forms_obj;
JSValue rr = JS_DupValue(ctx, forms_obj);
RETURN_JS(rr);
}
#endif

View File

@ -1,130 +0,0 @@
/* The QuickJS ECMAScript backend heartbeat fuctionality. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/time.h> /* setitimer(2) */
#include <signal.h>
#include "elinks.h"
#include "config/options.h"
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/quickjs.h"
#include "ecmascript/quickjs/heartbeat.h"
#include "osdep/signals.h"
#include "session/session.h"
#include "util/lists.h"
#include "util/math.h" /* int_upper_bound */
#include "util/memory.h"
#include "viewer/text/vs.h"
#ifndef CONFIG_LIBDOM
static INIT_LIST_OF(struct heartbeat, heartbeats);
static struct itimerval heartbeat_timer = { { 1, 0 }, { 1, 0 } };
/* This callback is installed by JS_SetInterruptHandler.
* Returning 1 terminates script execution immediately. */
int
js_heartbeat_callback(JSRuntime *rt, void *opaque)
{
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)opaque;
if (!interpreter || !interpreter->heartbeat || interpreter->heartbeat->ttl > 0) {
return 0;
}
return 1;
}
/* Callback for SIGVTALRM. Go through all heartbeats, decrease each
* one's TTL, and call JS_RequestInterruptCallback if a heartbeat's TTL
* goes to 0. */
void
check_heartbeats(void *data)
{
struct heartbeat *hb;
foreach (hb, heartbeats) {
assert(hb->interpreter);
--hb->ttl;
if (hb->ttl <= 0) {
if (hb->interpreter->vs
&& hb->interpreter->vs->doc_view
&& hb->interpreter->vs->doc_view->session
&& hb->interpreter->vs->doc_view->session->tab
&& hb->interpreter->vs->doc_view->session->tab->term) {
struct session *ses = hb->interpreter->vs->doc_view->session;
struct terminal *term = ses->tab->term;
int max_exec_time = get_opt_int("ecmascript.max_exec_time", ses);
ecmascript_timeout_dialog(term, max_exec_time);
}
}
}
#ifndef CONFIG_OS_DOS
install_signal_handler(SIGVTALRM, check_heartbeats, NULL, 1);
#endif
}
/* Create a new heartbeat for the given interpreter. */
struct heartbeat *
add_heartbeat(struct ecmascript_interpreter *interpreter)
{
struct session *ses;
struct heartbeat *hb;
assert(interpreter);
if (!interpreter->vs || !interpreter->vs->doc_view)
ses = NULL;
else
ses = interpreter->vs->doc_view->session;
hb = (struct heartbeat *)mem_alloc(sizeof(struct heartbeat));
if (!hb) return NULL;
hb->ttl = get_opt_int("ecmascript.max_exec_time", ses);
hb->interpreter = interpreter;
add_to_list(heartbeats, hb);
#ifndef CONFIG_OS_DOS
/* Update the heartbeat timer. */
if (list_is_singleton(*hb)) {
heartbeat_timer.it_value.tv_sec = 1;
setitimer(ITIMER_VIRTUAL, &heartbeat_timer, NULL);
}
/* We install the handler every call to add_heartbeat instead of only on
* module initialisation because other code may set other handlers for
* the signal. */
install_signal_handler(SIGVTALRM, check_heartbeats, NULL, 1);
#endif
return hb;
}
/* Destroy the given heartbeat. */
void
done_heartbeat(struct heartbeat *hb)
{
if (!hb) return; /* add_heartbeat returned NULL */
assert(hb->interpreter);
#ifndef CONFIG_OS_DOS
/* Stop the heartbeat timer if this heartbeat is the only one. */
if (list_is_singleton(*hb)) {
heartbeat_timer.it_value.tv_sec = 0;
setitimer(ITIMER_VIRTUAL, &heartbeat_timer, NULL);
}
#endif
del_from_list(hb);
hb->interpreter->heartbeat = NULL;
mem_free(hb);
}
#endif

View File

@ -1,177 +0,0 @@
/* The QuickJS history 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 "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/quickjs.h"
#include "ecmascript/quickjs/history.h"
#include "ecmascript/quickjs/window.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"
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_history_class_id;
/* @history_funcs{"back"} */
static JSValue
js_history_back(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
assert(interpreter);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
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 */
return JS_NULL;
}
/* @history_funcs{"forward"} */
static JSValue
js_history_forward(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
assert(interpreter);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
go_unback(ses);
return JS_NULL;
}
/* @history_funcs{"go"} */
static JSValue
js_history_go(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
assert(interpreter);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
struct location *loc;
if (argc != 1) {
return JS_UNDEFINED;
}
int index;
if (JS_ToInt32(ctx, &index, argv[0])) {
return JS_UNDEFINED;
}
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;
}
return JS_NULL;
}
static JSValue
js_history_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[history object]");
}
static const JSCFunctionListEntry js_history_funcs[] = {
JS_CFUNC_DEF("back", 0, js_history_back ),
JS_CFUNC_DEF("forward", 0, js_history_forward ),
JS_CFUNC_DEF("go", 1, js_history_go ),
JS_CFUNC_DEF("toString", 0, js_history_toString)
};
static JSClassDef js_history_class = {
"history",
};
int
js_history_init(JSContext *ctx)
{
JSValue history_proto;
/* create the history class */
JS_NewClassID(&js_history_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_history_class_id, &js_history_class);
JSValue global_obj = JS_GetGlobalObject(ctx);
REF_JS(global_obj);
history_proto = JS_NewObject(ctx);
REF_JS(history_proto);
JS_SetPropertyFunctionList(ctx, history_proto, js_history_funcs, countof(js_history_funcs));
JS_SetClassProto(ctx, js_history_class_id, history_proto);
JS_SetPropertyStr(ctx, global_obj, "history", JS_DupValue(ctx, history_proto));
JS_FreeValue(ctx, global_obj);
return 0;
}
#endif

View File

@ -1,159 +0,0 @@
/* The QuickJS domimplementation object. */
#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/quickjs.h"
#include "ecmascript/quickjs/document.h"
#include "ecmascript/quickjs/implementation.h"
#include "util/conv.h"
#include <libxml/HTMLparser.h>
#include <libxml++/libxml++.h>
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_implementation_class_id;
static JSValue
js_implementation_createHTMLDocument(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_UNDEFINED;
}
size_t len;
const char *title = JS_ToCStringLen(ctx, &len, argv[0]);
if (!title) {
return JS_EXCEPTION;
}
struct string str;
if (!init_string(&str)) {
JS_FreeCString(ctx, title);
return JS_NULL;
}
add_to_string(&str, "<!doctype html>\n<html><head><title>");
add_html_to_string(&str, title, len);
add_to_string(&str, "</title></head><body></body></html>");
// Parse HTML and create a DOM tree
xmlDoc* doc = htmlReadDoc((xmlChar*)str.source, NULL, "utf-8",
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING);
// Encapsulate raw libxml document in a libxml++ wrapper
xmlpp::Document *docu = new(std::nothrow) xmlpp::Document(doc);
done_string(&str);
JS_FreeCString(ctx, title);
return getDocument(ctx, docu);
}
static JSValue
js_implementation_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[implementation object]");
}
static const JSCFunctionListEntry js_implementation_proto_funcs[] = {
JS_CFUNC_DEF("createHTMLDocument", 1, js_implementation_createHTMLDocument),
JS_CFUNC_DEF("toString", 0, js_implementation_toString)
};
static JSClassDef js_implementation_class = {
"implementation",
};
static JSValue
js_implementation_ctor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
{
REF_JS(new_target);
JSValue obj = JS_UNDEFINED;
JSValue proto;
/* using new_target to get the prototype is necessary when the
class is extended. */
proto = JS_GetPropertyStr(ctx, new_target, "prototype");
REF_JS(proto);
if (JS_IsException(proto)) {
goto fail;
}
obj = JS_NewObjectProtoClass(ctx, proto, js_implementation_class_id);
JS_FreeValue(ctx, proto);
if (JS_IsException(obj)) {
goto fail;
}
RETURN_JS(obj);
fail:
JS_FreeValue(ctx, obj);
return JS_EXCEPTION;
}
int
js_implementation_init(JSContext *ctx, JSValue global_obj)
{
REF_JS(global_obj);
JSValue implementation_proto, implementation_class;
/* create the implementation class */
JS_NewClassID(&js_implementation_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_implementation_class_id, &js_implementation_class);
implementation_proto = JS_NewObject(ctx);
REF_JS(implementation_proto);
JS_SetPropertyFunctionList(ctx, implementation_proto, js_implementation_proto_funcs, countof(js_implementation_proto_funcs));
implementation_class = JS_NewCFunction2(ctx, js_implementation_ctor, "implementation", 0, JS_CFUNC_constructor, 0);
REF_JS(implementation_class);
/* set proto.constructor and ctor.prototype */
JS_SetConstructor(ctx, implementation_class, implementation_proto);
JS_SetClassProto(ctx, js_implementation_class_id, implementation_proto);
JS_SetPropertyStr(ctx, global_obj, "implementation", JS_DupValue(ctx, implementation_proto));
return 0;
}
JSValue
getImplementation(JSContext *ctx)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JSValue implementation_obj = JS_NewObject(ctx);
JS_SetPropertyFunctionList(ctx, implementation_obj, js_implementation_proto_funcs, countof(js_implementation_proto_funcs));
// implementation_class = JS_NewCFunction2(ctx, js_implementation_ctor, "implementation", 0, JS_CFUNC_constructor, 0);
// JS_SetConstructor(ctx, implementation_class, implementation_obj);
JS_SetClassProto(ctx, js_implementation_class_id, implementation_obj);
RETURN_JS(implementation_obj);
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,199 +0,0 @@
/* The QuickJS KeyboardEvent 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 "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/quickjs.h"
#include "ecmascript/quickjs/heartbeat.h"
#include "ecmascript/quickjs/keyboard.h"
#include "ecmascript/timer.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "main/timer.h"
#include "network/connection.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"
#include "protocol/http/http.h"
#include "protocol/uri.h"
#include "session/download.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 <iostream>
#include <list>
#include <map>
#include <utility>
#include <sstream>
#include <vector>
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_keyboardEvent_class_id;
static JSValue js_keyboardEvent_get_property_key(JSContext *ctx, JSValueConst this_val);
static JSValue js_keyboardEvent_get_property_keyCode(JSContext *ctx, JSValueConst this_val);
static unicode_val_T keyCode;
struct keyboard {
unicode_val_T keyCode;
};
static
void js_keyboardEvent_finalizer(JSRuntime *rt, JSValue val)
{
REF_JS(val);
struct keyboard *keyb = (struct keyboard *)JS_GetOpaque(val, js_keyboardEvent_class_id);
if (keyb) {
mem_free(keyb);
}
}
static JSClassDef js_keyboardEvent_class = {
"KeyboardEvent",
js_keyboardEvent_finalizer
};
#if 0
static JSValue
js_keyboardEvent_ctor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
{
REF_JS(new_target);
JSValue obj = JS_UNDEFINED;
JSValue proto;
struct keyboard *keyb = (struct keyboard *)mem_calloc(1, sizeof(*keyb));
if (!keyb) {
return JS_EXCEPTION;
}
/* using new_target to get the prototype is necessary when the
class is extended. */
proto = JS_GetPropertyStr(ctx, new_target, "prototype");
REF_JS(proto);
if (JS_IsException(proto)) {
goto fail;
}
obj = JS_NewObjectProtoClass(ctx, proto, js_keyboardEvent_class_id);
JS_FreeValue(ctx, proto);
if (JS_IsException(obj)) {
goto fail;
}
keyb->keyCode = keyCode;
JS_SetOpaque(obj, keyb);
RETURN_JS(obj);
fail:
JS_FreeValue(ctx, obj);
mem_free(keyb);
return JS_EXCEPTION;
}
#endif
static const JSCFunctionListEntry js_keyboardEvent_proto_funcs[] = {
JS_CGETSET_DEF("key", js_keyboardEvent_get_property_key, nullptr),
JS_CGETSET_DEF("keyCode", js_keyboardEvent_get_property_keyCode, nullptr)
};
static JSValue
js_keyboardEvent_get_property_key(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct keyboard *keyb = static_cast<struct keyboard *>(JS_GetOpaque(this_val, js_keyboardEvent_class_id));
if (!keyb) {
return JS_NULL;
}
char text[8] = {0};
*text = keyb->keyCode;
JSValue r = JS_NewString(ctx, text);
RETURN_JS(r);
}
static JSValue
js_keyboardEvent_get_property_keyCode(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct keyboard *keyb = static_cast<struct keyboard *>(JS_GetOpaque(this_val, js_keyboardEvent_class_id));
if (!keyb) {
return JS_NULL;
}
return JS_NewUint32(ctx, keyb->keyCode);
}
JSValue
get_keyboardEvent(JSContext *ctx, struct term_event *ev)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
static int initialized;
/* create the element class */
if (!initialized) {
JS_NewClassID(&js_keyboardEvent_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_keyboardEvent_class_id, &js_keyboardEvent_class);
initialized = 1;
}
struct keyboard *keyb = (struct keyboard *)mem_calloc(1, sizeof(*keyb));
if (!keyb) {
return JS_NULL;
}
keyCode = keyb->keyCode = get_kbd_key(ev);
JSValue keyb_obj = JS_NewObjectClass(ctx, js_keyboardEvent_class_id);
JS_SetPropertyFunctionList(ctx, keyb_obj, js_keyboardEvent_proto_funcs, countof(js_keyboardEvent_proto_funcs));
JS_SetClassProto(ctx, js_keyboardEvent_class_id, keyb_obj);
JS_SetOpaque(keyb_obj, keyb);
JSValue rr = JS_DupValue(ctx, keyb_obj);
RETURN_JS(rr);
}
#endif

View File

@ -1,269 +0,0 @@
/* The quickjs localstorage 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 "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/localstorage-db.h"
#include "ecmascript/quickjs.h"
#include "ecmascript/quickjs/localstorage.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"
#include <time.h>
#include "document/renderer.h"
#include "document/refresh.h"
#include "terminal/screen.h"
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_localstorage_class_id;
/* IMPLEMENTS READ FROM STORAGE USING SQLITE DATABASE */
static char *
readFromStorage(const char *key)
{
char *val;
if (local_storage_ready==0)
{
db_prepare_structure(local_storage_filename);
local_storage_ready=1;
}
val = db_query_by_key(local_storage_filename, key);
//DBG("Read: %s %s %s",local_storage_filename, key, val);
return val;
}
static void
removeFromStorage(const char *key)
{
if (local_storage_ready==0)
{
db_prepare_structure(local_storage_filename);
local_storage_ready=1;
}
db_delete_from(local_storage_filename, key);
}
/* IMPLEMENTS SAVE TO STORAGE USING SQLITE DATABASE */
static void
saveToStorage(const char *key, const char *val)
{
if (local_storage_ready==0) {
db_prepare_structure(local_storage_filename);
local_storage_ready=1;
}
int rows_affected=0;
rows_affected=db_update_set(local_storage_filename, key, val);
if (rows_affected==0) {
rows_affected=db_insert_into(local_storage_filename, key, val);
}
// DBG(log, "UPD ROWS: %d KEY: %s VAL: %s",rows_affected,key,val);
}
static JSValue
js_localstorage_getitem(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1)
{
return JS_UNDEFINED;
}
const char *key;
size_t len;
key = JS_ToCStringLen(ctx, &len, argv[0]);
if (!key) {
return JS_EXCEPTION;
}
char *val = readFromStorage(key);
JS_FreeCString(ctx, key);
if (!val) {
return JS_NULL;
}
JSValue ret = JS_NewString(ctx, val);
mem_free(val);
RETURN_JS(ret);
}
static JSValue
js_localstorage_removeitem(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1)
{
return JS_UNDEFINED;
}
const char *key;
size_t len;
key = JS_ToCStringLen(ctx, &len, argv[0]);
if (!key) {
return JS_EXCEPTION;
}
removeFromStorage(key);
JS_FreeCString(ctx, key);
return JS_UNDEFINED;
}
/* @localstorage_funcs{"setItem"} */
static JSValue
js_localstorage_setitem(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
if (argc != 2)
{
return JS_UNDEFINED;
}
const char *key_str, *val_str;
size_t len_key, len_val;
key_str = JS_ToCStringLen(ctx, &len_key, argv[0]);
if (!key_str) {
return JS_EXCEPTION;
}
val_str = JS_ToCStringLen(ctx, &len_val, argv[1]);
if (!val_str) {
JS_FreeCString(ctx, key_str);
return JS_EXCEPTION;
}
saveToStorage(key_str, val_str);
JS_FreeCString(ctx, key_str);
JS_FreeCString(ctx, val_str);
#ifdef CONFIG_LEDS
set_led_value(interpreter->vs->doc_view->session->status.ecmascript_led, 'J');
#endif
return JS_TRUE;
}
static JSValue
js_localstorage_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[localstorage object]");
}
static const JSCFunctionListEntry js_localstorage_proto_funcs[] = {
JS_CFUNC_DEF("getItem", 1, js_localstorage_getitem),
JS_CFUNC_DEF("removeItem", 1, js_localstorage_removeitem),
JS_CFUNC_DEF("setItem", 2, js_localstorage_setitem),
JS_CFUNC_DEF("toString", 0, js_localstorage_toString)
};
static JSClassDef js_localstorage_class = {
"localStorage",
};
int
js_localstorage_init(JSContext *ctx)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
static int initialized;
if (!initialized) {
/* create the localstorage class */
JS_NewClassID(&js_localstorage_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_localstorage_class_id, &js_localstorage_class);
initialized = 1;
}
JSValue global_obj = JS_GetGlobalObject(ctx);
REF_JS(global_obj);
JSValue localstorage_obj = JS_NewObjectClass(ctx, js_localstorage_class_id);
REF_JS(localstorage_obj);
JS_SetPropertyFunctionList(ctx, localstorage_obj, js_localstorage_proto_funcs, countof(js_localstorage_proto_funcs));
REF_JS(localstorage_obj);
JS_SetClassProto(ctx, js_localstorage_class_id, localstorage_obj);
REF_JS(localstorage_obj);
JS_SetPropertyStr(ctx, global_obj, "localStorage", JS_DupValue(ctx, localstorage_obj));
REF_JS(localstorage_obj);
JS_FreeValue(ctx, global_obj);
return 0;
}
#endif

View File

@ -1,679 +0,0 @@
/* The QuickJS location 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 "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/quickjs.h"
#include "ecmascript/quickjs/location.h"
#include "ecmascript/quickjs/window.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"
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_location_class_id;
static JSValue
js_location_get_property_hash(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
struct string fragment;
if (!init_string(&fragment)) {
return JS_EXCEPTION;
}
if (vs->uri->fragmentlen) {
add_bytes_to_string(&fragment, vs->uri->fragment, vs->uri->fragmentlen);
}
JSValue ret = JS_NewStringLen(ctx, fragment.source, fragment.length);
done_string(&fragment);
RETURN_JS(ret);
}
static JSValue
js_location_get_property_host(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
char *str = get_uri_string(vs->uri, URI_HOST_PORT);
if (!str) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
JSValue ret = JS_NewString(ctx, str);
mem_free(str);
RETURN_JS(ret);
}
static JSValue
js_location_get_property_hostname(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
char *str = get_uri_string(vs->uri, URI_HOST);
if (!str) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
JSValue ret = JS_NewString(ctx, str);
mem_free(str);
RETURN_JS(ret);
}
static JSValue
js_location_get_property_href(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
char *str = get_uri_string(vs->uri, URI_ORIGINAL);
if (!str) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
JSValue ret = JS_NewString(ctx, str);
mem_free(str);
RETURN_JS(ret);
}
static JSValue
js_location_get_property_origin(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
char *str = get_uri_string(vs->uri, URI_SERVER);
if (!str) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
JSValue ret = JS_NewString(ctx, str);
mem_free(str);
RETURN_JS(ret);
}
static JSValue
js_location_get_property_pathname(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
struct string pathname;
if (!init_string(&pathname)) {
return JS_EXCEPTION;
}
const char *query = (const char *)memchr(vs->uri->data, '?', vs->uri->datalen);
int len = (query ? query - vs->uri->data : vs->uri->datalen);
add_bytes_to_string(&pathname, vs->uri->data, len);
JSValue ret = JS_NewStringLen(ctx, pathname.source, pathname.length);
done_string(&pathname);
RETURN_JS(ret);
}
static JSValue
js_location_get_property_port(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
struct string port;
if (!init_string(&port)) {
return JS_EXCEPTION;
}
if (vs->uri->portlen) {
add_bytes_to_string(&port, vs->uri->port, vs->uri->portlen);
}
JSValue ret = JS_NewStringLen(ctx, port.source, port.length);
done_string(&port);
RETURN_JS(ret);
}
static JSValue
js_location_get_property_protocol(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
struct string proto;
if (!init_string(&proto)) {
return JS_EXCEPTION;
}
/* Custom or unknown keep the URI untouched. */
if (vs->uri->protocol == PROTOCOL_UNKNOWN) {
add_to_string(&proto, struri(vs->uri));
} else {
add_bytes_to_string(&proto, vs->uri->string, vs->uri->protocollen);
add_char_to_string(&proto, ':');
}
JSValue ret = JS_NewStringLen(ctx, proto.source, proto.length);
done_string(&proto);
RETURN_JS(ret);
}
static JSValue
js_location_get_property_search(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
struct string search;
if (!init_string(&search)) {
return JS_EXCEPTION;
}
const char *query = (const char *)memchr(vs->uri->data, '?', vs->uri->datalen);
if (query) {
add_bytes_to_string(&search, query, strcspn(query, "#" POST_CHAR_S));
}
JSValue ret = JS_NewStringLen(ctx, search.source, search.length);
done_string(&search);
RETURN_JS(ret);
}
static JSValue
js_location_set_property_hash(JSContext *ctx, JSValueConst this_val, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, val);
if (!str) {
return JS_EXCEPTION;
}
location_goto_const(vs->doc_view, str);
JS_FreeCString(ctx, str);
return JS_UNDEFINED;
}
static JSValue
js_location_set_property_host(JSContext *ctx, JSValueConst this_val, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
REF_JS(val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, val);
if (!str) {
return JS_EXCEPTION;
}
location_goto_const(vs->doc_view, str);
JS_FreeCString(ctx, str);
return JS_UNDEFINED;
}
static JSValue
js_location_set_property_hostname(JSContext *ctx, JSValueConst this_val, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
REF_JS(val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, val);
if (!str) {
return JS_EXCEPTION;
}
location_goto_const(vs->doc_view, str);
JS_FreeCString(ctx, str);
return JS_UNDEFINED;
}
static JSValue
js_location_set_property_href(JSContext *ctx, JSValueConst this_val, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
REF_JS(val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, val);
if (!str) {
return JS_EXCEPTION;
}
location_goto_const(vs->doc_view, str);
JS_FreeCString(ctx, str);
return JS_UNDEFINED;
}
static JSValue
js_location_set_property_pathname(JSContext *ctx, JSValueConst this_val, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
REF_JS(val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, val);
if (!str) {
return JS_EXCEPTION;
}
location_goto_const(vs->doc_view, str);
JS_FreeCString(ctx, str);
return JS_UNDEFINED;
}
static JSValue
js_location_set_property_port(JSContext *ctx, JSValueConst this_val, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
REF_JS(val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, val);
if (!str) {
return JS_EXCEPTION;
}
location_goto_const(vs->doc_view, str);
JS_FreeCString(ctx, str);
return JS_UNDEFINED;
}
static JSValue
js_location_set_property_protocol(JSContext *ctx, JSValueConst this_val, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
REF_JS(val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, val);
if (!str) {
return JS_EXCEPTION;
}
location_goto_const(vs->doc_view, str);
JS_FreeCString(ctx, str);
return JS_UNDEFINED;
}
static JSValue
js_location_set_property_search(JSContext *ctx, JSValueConst this_val, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
REF_JS(val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, val);
if (!str) {
return JS_EXCEPTION;
}
location_goto_const(vs->doc_view, str);
JS_FreeCString(ctx, str);
return JS_UNDEFINED;
}
static JSValue
js_location_reload(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_EXCEPTION;
}
location_goto_const(vs->doc_view, "");
return JS_UNDEFINED;
}
/* @location_funcs{"toString"}, @location_funcs{"toLocaleString"} */
static JSValue
js_location_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return js_location_get_property_href(ctx, this_val);
}
static const JSCFunctionListEntry js_location_proto_funcs[] = {
JS_CGETSET_DEF("hash", js_location_get_property_hash, js_location_set_property_hash),
JS_CGETSET_DEF("host", js_location_get_property_host, js_location_set_property_host),
JS_CGETSET_DEF("hostname", js_location_get_property_hostname, js_location_set_property_hostname),
JS_CGETSET_DEF("href", js_location_get_property_href, js_location_set_property_href),
JS_CGETSET_DEF("origin", js_location_get_property_origin, nullptr),
JS_CGETSET_DEF("pathname", js_location_get_property_pathname, js_location_set_property_pathname),
JS_CGETSET_DEF("port", js_location_get_property_port, js_location_set_property_port),
JS_CGETSET_DEF("protocol", js_location_get_property_protocol, js_location_set_property_protocol),
JS_CGETSET_DEF("search", js_location_get_property_search, js_location_set_property_search),
JS_CFUNC_DEF("reload", 0, js_location_reload),
JS_CFUNC_DEF("toString", 0, js_location_toString),
JS_CFUNC_DEF("toLocaleString", 0, js_location_toString),
};
static JSClassDef js_location_class = {
"location",
};
JSValue
js_location_init(JSContext *ctx)
{
JSValue location_proto;
/* create the location class */
JS_NewClassID(&js_location_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_location_class_id, &js_location_class);
JSValue global_obj = JS_GetGlobalObject(ctx);
REF_JS(global_obj);
location_proto = JS_NewObject(ctx);
REF_JS(location_proto);
JS_SetPropertyFunctionList(ctx, location_proto, js_location_proto_funcs, countof(js_location_proto_funcs));
JS_SetClassProto(ctx, js_location_class_id, location_proto);
JS_SetPropertyStr(ctx, global_obj, "location", JS_DupValue(ctx, location_proto));
JS_FreeValue(ctx, global_obj);
RETURN_JS(location_proto);
}
#endif

View File

@ -1,2 +0,0 @@
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', 'keyboard.cpp', 'localstorage.cpp', 'location.cpp', 'message.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')

View File

@ -1,258 +0,0 @@
/* The QuickJS MessageEvent 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 "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/quickjs.h"
#include "ecmascript/quickjs/heartbeat.h"
#include "ecmascript/quickjs/message.h"
#include "ecmascript/timer.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "main/timer.h"
#include "network/connection.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"
#include "protocol/http/http.h"
#include "protocol/uri.h"
#include "session/download.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 <iostream>
#include <list>
#include <map>
#include <utility>
#include <sstream>
#include <vector>
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_messageEvent_class_id;
static JSValue js_messageEvent_get_property_data(JSContext *cx, JSValueConst this_val);
static JSValue js_messageEvent_get_property_lastEventId(JSContext *cx, JSValueConst this_val);
static JSValue js_messageEvent_get_property_origin(JSContext *cx, JSValueConst this_val);
static JSValue js_messageEvent_get_property_source(JSContext *cx, JSValueConst this_val);
struct message_event {
char *data;
char *lastEventId;
char *origin;
char *source;
};
static
void js_messageEvent_finalizer(JSRuntime *rt, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(val);
struct message_event *event = (struct message_event *)JS_GetOpaque(val, js_messageEvent_class_id);
if (event) {
mem_free_if(event->data);
mem_free_if(event->lastEventId);
mem_free_if(event->origin);
mem_free_if(event->source);
mem_free(event);
}
}
static JSClassDef js_messageEvent_class = {
"MessageEvent",
js_messageEvent_finalizer
};
#if 0
static JSValue
js_messageEvent_ctor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(new_target);
JSValue obj = JS_UNDEFINED;
JSValue proto;
struct message_event *event = (struct message_event *)mem_calloc(1, sizeof(*event));
if (!event) {
return JS_EXCEPTION;
}
/* using new_target to get the prototype is necessary when the
class is extended. */
proto = JS_GetPropertyStr(ctx, new_target, "prototype");
REF_JS(proto);
if (JS_IsException(proto)) {
goto fail;
}
obj = JS_NewObjectProtoClass(ctx, proto, js_messageEvent_class_id);
JS_FreeValue(ctx, proto);
if (JS_IsException(obj)) {
goto fail;
}
JS_SetOpaque(obj, event);
RETURN_JS(obj);
fail:
JS_FreeValue(ctx, obj);
mem_free(event);
return JS_EXCEPTION;
}
#endif
static const JSCFunctionListEntry js_messageEvent_proto_funcs[] = {
JS_CGETSET_DEF("data", js_messageEvent_get_property_data, nullptr),
JS_CGETSET_DEF("lastEventId", js_messageEvent_get_property_lastEventId, nullptr),
JS_CGETSET_DEF("origin", js_messageEvent_get_property_origin, nullptr),
JS_CGETSET_DEF("source", js_messageEvent_get_property_source, nullptr)
};
static JSValue
js_messageEvent_get_property_data(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct message_event *event = static_cast<struct message_event *>(JS_GetOpaque(this_val, js_messageEvent_class_id));
if (!event || !event->data) {
return JS_NULL;
}
JSValue r = JS_NewString(ctx, event->data);
RETURN_JS(r);
}
static JSValue
js_messageEvent_get_property_lastEventId(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct message_event *event = static_cast<struct message_event *>(JS_GetOpaque(this_val, js_messageEvent_class_id));
if (!event || !event->lastEventId) {
return JS_NULL;
}
JSValue r = JS_NewString(ctx, event->lastEventId);
RETURN_JS(r);
}
static JSValue
js_messageEvent_get_property_origin(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct message_event *event = static_cast<struct message_event *>(JS_GetOpaque(this_val, js_messageEvent_class_id));
if (!event || !event->origin) {
return JS_NULL;
}
JSValue r = JS_NewString(ctx, event->origin);
RETURN_JS(r);
}
static JSValue
js_messageEvent_get_property_source(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct message_event *event = static_cast<struct message_event *>(JS_GetOpaque(this_val, js_messageEvent_class_id));
if (!event || !event->source) {
return JS_NULL;
}
JSValue r = JS_NewString(ctx, event->source);
RETURN_JS(r);
}
static int lastEventId;
JSValue
get_messageEvent(JSContext *ctx, char *data, char *origin, char *source)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
static int initialized;
/* create the element class */
if (!initialized) {
JS_NewClassID(&js_messageEvent_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_messageEvent_class_id, &js_messageEvent_class);
initialized = 1;
}
struct message_event *event = (struct message_event *)mem_calloc(1, sizeof(*event));
if (!event) {
return JS_NULL;
}
event->data = null_or_stracpy(data);
event->origin = null_or_stracpy(origin);
event->source = null_or_stracpy(source);
char id[32];
snprintf(id, 31, "%d", ++lastEventId);
event->lastEventId = stracpy(id);
JSValue event_obj = JS_NewObjectClass(ctx, js_messageEvent_class_id);
JS_SetPropertyFunctionList(ctx, event_obj, js_messageEvent_proto_funcs, countof(js_messageEvent_proto_funcs));
JS_SetClassProto(ctx, js_messageEvent_class_id, event_obj);
JS_SetOpaque(event_obj, event);
JSValue rr = JS_DupValue(ctx, event_obj);
RETURN_JS(rr);
}
#endif

View File

@ -1,204 +0,0 @@
/* The Quickjs navigator 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 "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/quickjs.h"
#include "ecmascript/quickjs/navigator.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"
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_navigator_class_id;
/* @navigator_class.getProperty */
static JSValue
js_navigator_get_property_appCodeName(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
JSValue r = JS_NewString(ctx, "Mozilla"); /* More like a constant nowadays. */
RETURN_JS(r);
}
static JSValue
js_navigator_get_property_appName(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
JSValue r = JS_NewString(ctx, "ELinks (roughly compatible with Netscape Navigator, Mozilla and Microsoft Internet Explorer)");
RETURN_JS(r);
}
static JSValue
js_navigator_get_property_appVersion(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
JSValue r = JS_NewString(ctx, VERSION);
RETURN_JS(r);
}
static JSValue
js_navigator_get_property_language(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
#ifdef CONFIG_NLS
if (get_opt_bool("protocol.http.accept_ui_language", NULL)) {
JSValue r = JS_NewString(ctx, language_to_iso639(current_language));
RETURN_JS(r);
}
#endif
return JS_UNDEFINED;
}
static JSValue
js_navigator_get_property_platform(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
JSValue r = JS_NewString(ctx, system_name);
RETURN_JS(r);
}
static JSValue
js_navigator_get_property_userAgent(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
char *optstr = get_opt_str("protocol.http.user_agent", NULL);
if (*optstr && strcmp(optstr, " ")) {
char *ustr, ts[64] = "";
static char custr[256];
/* TODO: Somehow get the terminal in which the
* document is actually being displayed. */
struct terminal *term = get_default_terminal();
if (term) {
unsigned int tslen = 0;
ulongcat(ts, &tslen, term->width, 3, 0);
ts[tslen++] = 'x';
ulongcat(ts, &tslen, term->height, 3, 0);
}
ustr = subst_user_agent(optstr, VERSION_STRING, system_name, ts);
if (ustr) {
safe_strncpy(custr, ustr, 256);
mem_free(ustr);
JSValue r = JS_NewString(ctx, custr);
RETURN_JS(r);
}
}
JSValue rr = JS_NewString(ctx, system_name);
RETURN_JS(rr);
}
static JSValue
js_navigator_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[navigator object]");
}
static const JSCFunctionListEntry js_navigator_proto_funcs[] = {
JS_CGETSET_DEF("appCodeName", js_navigator_get_property_appCodeName, nullptr),
JS_CGETSET_DEF("appName", js_navigator_get_property_appName, nullptr),
JS_CGETSET_DEF("appVersion", js_navigator_get_property_appVersion, nullptr),
JS_CGETSET_DEF("language", js_navigator_get_property_language, nullptr),
JS_CGETSET_DEF("platform", js_navigator_get_property_platform, nullptr),
JS_CGETSET_DEF("userAgent", js_navigator_get_property_userAgent, nullptr),
JS_CFUNC_DEF("toString", 0, js_navigator_toString)
};
static JSClassDef js_navigator_class = {
"navigator",
};
int
js_navigator_init(JSContext *ctx)
{
JSValue navigator_proto;
/* create the navigator class */
JS_NewClassID(&js_navigator_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_navigator_class_id, &js_navigator_class);
JSValue global_obj = JS_GetGlobalObject(ctx);
REF_JS(global_obj);
navigator_proto = JS_NewObject(ctx);
REF_JS(navigator_proto);
JS_SetPropertyFunctionList(ctx, navigator_proto, js_navigator_proto_funcs, countof(js_navigator_proto_funcs));
JS_SetClassProto(ctx, js_navigator_class_id, navigator_proto);
JS_SetPropertyStr(ctx, global_obj, "navigator", JS_DupValue(ctx, navigator_proto));
JS_FreeValue(ctx, global_obj);
return 0;
}
#endif

View File

@ -1,238 +0,0 @@
/* The QuickJS nodeList 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 "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/quickjs.h"
#include "ecmascript/quickjs/element.h"
#include "ecmascript/quickjs/nodelist.h"
#include "ecmascript/quickjs/window.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"
#include <libxml/tree.h>
#include <libxml/HTMLparser.h>
#include <libxml++/libxml++.h>
#include <libxml++/attributenode.h>
#include <libxml++/parsers/domparser.h>
#include <iostream>
#include <algorithm>
#include <string>
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static std::map<void *, JSValueConst> map_nodelist;
static std::map<JSValueConst, void *> map_rev_nodelist;
static void *
js_nodeList_GetOpaque(JSValueConst this_val)
{
REF_JS(this_val);
return map_rev_nodelist[this_val];
}
static void
js_nodeList_SetOpaque(JSValueConst this_val, void *node)
{
REF_JS(this_val);
if (!node) {
map_rev_nodelist.erase(this_val);
} else {
map_rev_nodelist[this_val] = node;
}
}
#if 0
static JSValue
js_nodeList_get_property_length(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
xmlpp::Node::NodeList *nl = static_cast<xmlpp::Node::NodeList *>(js_nodeList_GetOpaque(this_val));
if (!nl) {
return JS_NewInt32(ctx, 0);
}
return JS_NewInt32(ctx, nl->size());
}
#endif
static JSValue
js_nodeList_item2(JSContext *ctx, JSValueConst this_val, int idx)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
xmlpp::Node::NodeList *nl = static_cast<xmlpp::Node::NodeList *>(js_nodeList_GetOpaque(this_val));
if (!nl) {
return JS_UNDEFINED;
}
xmlpp::Node *element = nullptr;
auto it = nl->begin();
auto end = nl->end();
for (int i = 0; it != end; ++it, ++i) {
if (i == idx) {
element = *it;
break;
}
}
if (!element) {
return JS_UNDEFINED;
}
return getElement(ctx, element);
}
static JSValue
js_nodeList_item(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1) {
return JS_UNDEFINED;
}
int index;
JS_ToInt32(ctx, &index, argv[0]);
return js_nodeList_item2(ctx, this_val, index);
}
static void
js_nodeList_set_items(JSContext *ctx, JSValue this_val, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
xmlpp::Node::NodeList *nl = static_cast<xmlpp::Node::NodeList *>(node);
if (!nl) {
return;
}
auto it = nl->begin();
auto end = nl->end();
for (int i = 0; it != end; ++it, ++i) {
xmlpp::Node *element = *it;
if (element) {
JSValue obj = getElement(ctx, element);
REF_JS(obj);
JS_SetPropertyUint32(ctx, this_val, i, JS_DupValue(ctx, obj));
JS_FreeValue(ctx, obj);
}
}
}
static JSValue
js_nodeList_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[nodeList object]");
}
static const JSCFunctionListEntry js_nodeList_proto_funcs[] = {
// JS_CGETSET_DEF("length", js_nodeList_get_property_length, nullptr),
JS_CFUNC_DEF("item", 1, js_nodeList_item),
JS_CFUNC_DEF("toString", 0, js_nodeList_toString)
};
#if 0
static void
js_nodeList_finalizer(JSRuntime *rt, JSValue val)
{
REF_JS(val);
void *node = js_nodeList_GetOpaque(val);
js_nodeList_SetOpaque(val, nullptr);
map_nodelist.erase(node);
}
static JSClassDef js_nodeList_class = {
"nodeList",
js_nodeList_finalizer
};
#endif
JSValue
getNodeList(JSContext *ctx, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
auto node_find = map_nodelist.find(node);
if (node_find != map_nodelist.end()) {
JSValue r = JS_DupValue(ctx, node_find->second);
RETURN_JS(r);
}
JSValue nodeList_obj = JS_NewArray(ctx);
JS_SetPropertyFunctionList(ctx, nodeList_obj, js_nodeList_proto_funcs, countof(js_nodeList_proto_funcs));
map_nodelist[node] = nodeList_obj;
js_nodeList_SetOpaque(nodeList_obj, node);
js_nodeList_set_items(ctx, nodeList_obj, node);
JSValue rr = JS_DupValue(ctx, nodeList_obj);
RETURN_JS(rr);
}
#endif

View File

@ -1,194 +0,0 @@
/* The QuickJS screen 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 "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/quickjs.h"
#include "ecmascript/quickjs/screen.h"
#include "ecmascript/quickjs/window.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"
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_screen_class_id;
static JSValue
js_screen_get_property_availHeight(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
return JS_UNDEFINED;
}
return JS_NewInt32(ctx, doc_view->box.height * 16);
}
static JSValue
js_screen_get_property_availWidth(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
return JS_UNDEFINED;
}
return JS_NewInt32(ctx, doc_view->box.width * 8);
}
static JSValue
js_screen_get_property_height(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
return JS_UNDEFINED;
}
struct session *ses = doc_view->session;
if (!ses) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_UNDEFINED;
}
return JS_NewInt32(ctx, ses->tab->term->height * 16);
}
static JSValue
js_screen_get_property_width(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
return JS_UNDEFINED;
}
struct session *ses = doc_view->session;
if (!ses) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_UNDEFINED;
}
return JS_NewInt32(ctx, ses->tab->term->width * 8);
}
static JSValue
js_screen_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[screen object]");
}
static const JSCFunctionListEntry js_screen_proto_funcs[] = {
JS_CGETSET_DEF("availHeight", js_screen_get_property_availHeight, nullptr),
JS_CGETSET_DEF("availWidth", js_screen_get_property_availWidth, nullptr),
JS_CGETSET_DEF("height", js_screen_get_property_height, nullptr),
JS_CGETSET_DEF("width", js_screen_get_property_width, nullptr),
JS_CFUNC_DEF("toString", 0, js_screen_toString)
};
static JSClassDef js_screen_class = {
"screen",
};
int
js_screen_init(JSContext *ctx)
{
JSValue screen_proto;
/* create the screen class */
JS_NewClassID(&js_screen_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_screen_class_id, &js_screen_class);
JSValue global_obj = JS_GetGlobalObject(ctx);
REF_JS(global_obj);
screen_proto = JS_NewObject(ctx);
REF_JS(screen_proto);
JS_SetPropertyFunctionList(ctx, screen_proto, js_screen_proto_funcs, countof(js_screen_proto_funcs));
JS_SetClassProto(ctx, js_screen_class_id, screen_proto);
JS_SetPropertyStr(ctx, global_obj, "screen", JS_DupValue(ctx, screen_proto));
JS_FreeValue(ctx, global_obj);
REF_JS(global_obj);
return 0;
}
#endif

View File

@ -1,197 +0,0 @@
/* The quickjs unibar objects 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 "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/quickjs.h"
#include "ecmascript/quickjs/unibar.h"
#include "ecmascript/quickjs/window.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"
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_menubar_class_id;
static JSClassID js_statusbar_class_id;
static JSValue
js_unibar_get_property_visible(JSContext *ctx, JSValueConst this_val, int magic)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
return JS_UNDEFINED;
}
struct session_status *status = &doc_view->session->status;
#define unibar_fetch(bar) \
status->force_show_##bar##_bar >= 0 \
? status->force_show_##bar##_bar \
: status->show_##bar##_bar
switch (magic) {
case 0:
return JS_NewBool(ctx, unibar_fetch(status));
case 1:
return JS_NewBool(ctx, unibar_fetch(title));
default:
return JS_NewBool(ctx, 0);
}
#undef unibar_fetch
}
static JSValue
js_unibar_set_property_visible(JSContext *ctx, JSValueConst this_val, JSValue val, int magic)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
REF_JS(val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
return JS_UNDEFINED;
}
struct session_status *status = &doc_view->session->status;
switch (magic) {
case 0:
status->force_show_status_bar = JS_ToBool(ctx, val);
break;
case 1:
status->force_show_title_bar = JS_ToBool(ctx, val);
break;
default:
break;
}
register_bottom_half(update_status, NULL);
return JS_UNDEFINED;
}
static JSValue
js_menubar_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[menubar object]");
}
static JSValue
js_statusbar_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[statusbar object]");
}
static const JSCFunctionListEntry js_menubar_proto_funcs[] = {
JS_CGETSET_MAGIC_DEF("visible", js_unibar_get_property_visible, js_unibar_set_property_visible, 1),
JS_CFUNC_DEF("toString", 0, js_menubar_toString)
};
static const JSCFunctionListEntry js_statusbar_proto_funcs[] = {
JS_CGETSET_MAGIC_DEF("visible", js_unibar_get_property_visible, js_unibar_set_property_visible, 0),
JS_CFUNC_DEF("toString", 0, js_statusbar_toString)
};
static JSClassDef js_menubar_class = {
"menubar",
};
static JSClassDef js_statusbar_class = {
"statusbar",
};
int
js_unibar_init(JSContext *ctx)
{
JSValue menubar_proto;
JSValue statusbar_proto;
/* create the menubar class */
JS_NewClassID(&js_menubar_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_menubar_class_id, &js_menubar_class);
JSValue global_obj = JS_GetGlobalObject(ctx);
REF_JS(global_obj);
menubar_proto = JS_NewObject(ctx);
REF_JS(menubar_proto);
JS_SetPropertyFunctionList(ctx, menubar_proto, js_menubar_proto_funcs, countof(js_menubar_proto_funcs));
JS_SetClassProto(ctx, js_menubar_class_id, menubar_proto);
JS_SetPropertyStr(ctx, global_obj, "menubar", JS_DupValue(ctx, menubar_proto));
/* create the statusbar class */
JS_NewClassID(&js_statusbar_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_statusbar_class_id, &js_statusbar_class);
statusbar_proto = JS_NewObject(ctx);
REF_JS(statusbar_proto);
JS_SetPropertyFunctionList(ctx, statusbar_proto, js_statusbar_proto_funcs, countof(js_statusbar_proto_funcs));
JS_SetClassProto(ctx, js_statusbar_class_id, statusbar_proto);
JS_SetPropertyStr(ctx, global_obj, "statusbar", JS_DupValue(ctx, statusbar_proto));
JS_FreeValue(ctx, global_obj);
return 0;
}
#endif

View File

@ -1,779 +0,0 @@
/* The Quickjs window 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 "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/quickjs.h"
#include "ecmascript/quickjs/heartbeat.h"
#include "ecmascript/quickjs/message.h"
#include "ecmascript/quickjs/window.h"
#include "ecmascript/timer.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "main/timer.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"
#ifndef CONFIG_LIBDOM
#define countof(x) (sizeof(x) / sizeof((x)[0]))
static JSClassID js_window_class_id;
struct listener {
LIST_HEAD(struct listener);
char *typ;
JSValue fun;
};
struct el_window {
struct ecmascript_interpreter *interpreter;
JSValue thisval;
LIST_OF(struct listener) listeners;
JSValue onmessage;
};
struct el_message {
JSValue messageObject;
struct el_window *elwin;
};
static void
js_window_finalize(JSRuntime *rt, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(val);
struct el_window *elwin = (struct el_window *)JS_GetOpaque(val, js_window_class_id);
if (elwin) {
struct listener *l;
foreach(l, elwin->listeners) {
mem_free_set(&l->typ, NULL);
}
free_list(elwin->listeners);
mem_free(elwin);
}
}
static void
js_window_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(val);
struct el_window *elwin = (struct el_window *)JS_GetOpaque(val, js_window_class_id);
if (elwin) {
JS_MarkValue(rt, elwin->thisval, mark_func);
JS_MarkValue(rt, elwin->onmessage, mark_func);
if (elwin->interpreter->vs && elwin->interpreter->vs->doc_view) {
struct document *doc = elwin->interpreter->vs->doc_view->document;
struct ecmascript_timeout *et;
foreach (et, doc->timeouts) {
JS_MarkValue(rt, et->fun, mark_func);
}
}
struct listener *l;
foreach (l, elwin->listeners) {
JS_MarkValue(rt, l->fun, mark_func);
}
}
}
/* @window_funcs{"open"} */
JSValue
js_window_open(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct view_state *vs;
struct document_view *doc_view;
struct session *ses;
const char *frame = NULL;
char *url, *url2;
struct uri *uri;
static time_t ratelimit_start;
static int ratelimit_count;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
vs = interpreter->vs;
doc_view = vs->doc_view;
ses = doc_view->session;
if (get_opt_bool("ecmascript.block_window_opening", ses)) {
#ifdef CONFIG_LEDS
set_led_value(ses->status.popup_led, 'P');
#endif
return JS_UNDEFINED;
}
if (argc < 1) return JS_UNDEFINED;
/* Ratelimit window opening. Recursive window.open() is very nice.
* We permit at most 20 tabs in 2 seconds. The ratelimiter is very
* rough but shall suffice against the usual cases. */
if (!ratelimit_start || time(NULL) - ratelimit_start > 2) {
ratelimit_start = time(NULL);
ratelimit_count = 0;
} else {
ratelimit_count++;
if (ratelimit_count > 20) {
return JS_UNDEFINED;
}
}
const char *str;
size_t len;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
url = stracpy(str);
JS_FreeCString(ctx, str);
if (!url) {
return JS_UNDEFINED;
}
trim_chars(url, ' ', 0);
url2 = join_urls(doc_view->document->uri, url);
mem_free(url);
if (!url2) {
return JS_UNDEFINED;
}
if (argc > 1) {
size_t len2;
frame = JS_ToCStringLen(ctx, &len2, argv[1]);
if (!frame) {
mem_free(url2);
return JS_EXCEPTION;
}
}
/* TODO: Support for window naming and perhaps some window features? */
uri = get_uri(url2, URI_NONE);
mem_free(url2);
if (!uri) {
if (frame) JS_FreeCString(ctx, frame);
return JS_UNDEFINED;
}
JSValue ret;
if (frame && *frame && c_strcasecmp(frame, "_blank")) {
struct delayed_open *deo = (struct delayed_open *)mem_calloc(1, sizeof(*deo));
if (deo) {
deo->ses = ses;
deo->uri = get_uri_reference(uri);
deo->target = stracpy(frame);
register_bottom_half(delayed_goto_uri_frame, deo);
ret = JS_TRUE;
goto end;
}
}
if (!get_cmd_opt_bool("no-connect")
&& !get_cmd_opt_bool("no-home")
&& !get_cmd_opt_bool("anonymous")
&& can_open_in_new(ses->tab->term)) {
open_uri_in_new_window(ses, uri, NULL, ENV_ANY,
CACHE_MODE_NORMAL, TASK_NONE);
ret = JS_TRUE;
} else {
/* When opening a new tab, we might get rerendered, losing our
* context and triggerring a disaster, so postpone that. */
struct delayed_open *deo = (struct delayed_open *)mem_calloc(1, sizeof(*deo));
if (deo) {
deo->ses = ses;
deo->uri = get_uri_reference(uri);
register_bottom_half(delayed_open, deo);
ret = JS_TRUE;
} else {
ret = JS_UNDEFINED;
}
}
end:
done_uri(uri);
if (frame) JS_FreeCString(ctx, frame);
return ret;
}
/* @window_funcs{"setTimeout"} */
JSValue
js_window_setTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
int64_t timeout = 0;
JSValueConst func;
if (argc != 2) {
return JS_UNDEFINED;
}
if (JS_ToInt64(ctx, &timeout, argv[1])) {
return JS_EXCEPTION;
}
if (timeout <= 0) {
return JS_UNDEFINED;
}
func = argv[0];
if (JS_IsFunction(ctx, func)) {
timer_id_T id = ecmascript_set_timeout2q(interpreter, JS_DupValue(ctx, func), timeout);
JS_FreeValue(ctx, func);
return JS_NewInt64(ctx, reinterpret_cast<int64_t>(id));
}
if (JS_IsString(func)) {
const char *code = JS_ToCString(ctx, func);
if (!code) {
return JS_EXCEPTION;
}
char *code2 = stracpy(code);
JS_FreeCString(ctx, code);
if (code2) {
timer_id_T id = ecmascript_set_timeout(interpreter, code2, timeout);
return JS_NewInt64(ctx, reinterpret_cast<int64_t>(id));
}
}
return JS_UNDEFINED;
}
/* @window_funcs{"clearTimeout"} */
JSValue
js_window_clearTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
if (argc != 1) {
return JS_UNDEFINED;
}
int64_t number;
if (JS_ToInt64(ctx, &number, argv[0])) {
return JS_UNDEFINED;
}
timer_id_T id = reinterpret_cast<timer_id_T>(number);
if (found_in_map_timer(id)) {
struct ecmascript_timeout *t = (struct ecmascript_timeout *)(id->data);
kill_timer(&t->tid);
done_string(&t->code);
del_from_list(t);
mem_free(t);
}
return JS_UNDEFINED;
}
static JSValue
js_window_get_property_closed(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_FALSE;
}
static JSValue
js_window_get_property_parent(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
/* XXX: It would be nice if the following worked, yes.
* The problem is that we get called at the point where
* document.frame properties are going to be mostly NULL.
* But the problem is deeper because at that time we are
* yet building scrn_frames so our parent might not be there
* yet (XXX: is this true?). The true solution will be to just
* have struct document_view *(document_view.parent). --pasky */
/* FIXME: So now we alias window.parent to window.top, which is
* INCORRECT but works for the most common cases of just two
* frames. Better something than nothing. */
return JS_UNDEFINED;
}
static JSValue
js_window_get_property_self(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
JSValue r = JS_DupValue(ctx, this_val);
RETURN_JS(r);
}
static JSValue
js_window_get_property_status(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_UNDEFINED;
}
static JSValue
js_window_set_property_status(JSContext *ctx, JSValueConst this_val, JSValue val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
REF_JS(val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
return JS_UNDEFINED;
}
size_t len;
const char *str = JS_ToCStringLen(ctx, &len, val);
if (!str) {
return JS_EXCEPTION;
}
char *text = stracpy(str);
JS_FreeCString(ctx, str);
mem_free_set(&vs->doc_view->session->status.window_status, text);
print_screen_status(vs->doc_view->session);
return JS_UNDEFINED;
}
static JSValue
js_window_get_property_top(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct document_view *doc_view;
struct document_view *top_view;
JSValue newjsframe;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return JS_UNDEFINED;
}
doc_view = vs->doc_view;
top_view = doc_view->session->doc_view;
assert(top_view && top_view->vs);
if (top_view->vs->ecmascript_fragile)
ecmascript_reset_state(top_view->vs);
if (!top_view->vs->ecmascript) {
return JS_UNDEFINED;
}
newjsframe = JS_GetGlobalObject((JSContext *)top_view->vs->ecmascript->backend_data);
/* Keep this unrolled this way. Will have to check document.domain
* JS property. */
/* Note that this check is perhaps overparanoid. If top windows
* is alien but some other child window is not, we should still
* let the script walk thru. That'd mean moving the check to
* other individual properties in this switch. */
if (compare_uri(vs->uri, top_view->vs->uri, URI_HOST)) {
return newjsframe;
}
/* else */
/****X*X*X*** SECURITY VIOLATION! RED ALERT, SHIELDS UP! ***X*X*X****\
|* (Pasky was apparently looking at the Links2 JS code . ___ ^.^ *|
\* for too long.) `.(,_,)\o/ */
return JS_UNDEFINED;
}
JSValue
js_window_alert(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
assert(interpreter);
struct view_state *vs;
const char *str;
char *string;
size_t len;
vs = interpreter->vs;
if (argc != 1)
return JS_UNDEFINED;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
string = stracpy(str);
JS_FreeCString(ctx, str);
info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT,
N_("JavaScript Alert"), ALIGN_CENTER, string);
return JS_UNDEFINED;
}
static JSValue
js_window_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return JS_NewString(ctx, "[window object]");
}
static JSValue
js_window_addEventListener(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct el_window *elwin = (struct el_window *)(JS_GetOpaque(this_val, js_window_class_id));
if (!elwin) {
elwin = (struct el_window *)mem_calloc(1, sizeof(*elwin));
if (!elwin) {
return JS_EXCEPTION;
}
init_list(elwin->listeners);
elwin->interpreter = interpreter;
elwin->thisval = JS_DupValue(ctx, this_val);
JS_SetOpaque(this_val, elwin);
}
if (argc < 2) {
return JS_UNDEFINED;
}
const char *str;
size_t len;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
char *method = stracpy(str);
JS_FreeCString(ctx, str);
if (!method) {
return JS_EXCEPTION;
}
JSValue fun = argv[1];
struct listener *l;
foreach(l, elwin->listeners) {
if (strcmp(l->typ, method)) {
continue;
}
if (JS_VALUE_GET_PTR(l->fun) == JS_VALUE_GET_PTR(fun)) {
mem_free(method);
return JS_UNDEFINED;
}
}
struct listener *n = (struct listener *)mem_calloc(1, sizeof(*n));
if (n) {
n->typ = method;
n->fun = JS_DupValue(ctx, argv[1]);
add_to_list_end(elwin->listeners, n);
}
return JS_UNDEFINED;
}
static JSValue
js_window_removeEventListener(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct el_window *elwin = (struct el_window *)(JS_GetOpaque(this_val, js_window_class_id));
if (!elwin) {
return JS_NULL;
}
if (argc < 2) {
return JS_UNDEFINED;
}
const char *str;
size_t len;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
char *method = stracpy(str);
JS_FreeCString(ctx, str);
if (!method) {
return JS_EXCEPTION;
}
JSValue fun = argv[1];
struct listener *l;
foreach(l, elwin->listeners) {
if (strcmp(l->typ, method)) {
continue;
}
if (JS_VALUE_GET_PTR(l->fun) == JS_VALUE_GET_PTR(fun)) {
del_from_list(l);
mem_free_set(&l->typ, NULL);
mem_free(l);
mem_free(method);
return JS_UNDEFINED;
}
}
mem_free(method);
return JS_UNDEFINED;
}
static void
onmessage_run(void *data)
{
struct el_message *mess = (struct el_message *)data;
if (mess) {
struct el_window *elwin = mess->elwin;
if (!elwin) {
mem_free(mess);
return;
}
struct ecmascript_interpreter *interpreter = elwin->interpreter;
JSContext *ctx = (JSContext *)interpreter->backend_data;
interpreter->heartbeat = add_heartbeat(interpreter);
struct listener *l;
foreach(l, elwin->listeners) {
if (strcmp(l->typ, "message")) {
continue;
}
JSValue func = JS_DupValue(ctx, l->fun);
JSValue arg = JS_DupValue(ctx, mess->messageObject);
JSValue ret = JS_Call(ctx, func, elwin->thisval, 1, (JSValueConst *) &arg);
JS_FreeValue(ctx, ret);
JS_FreeValue(ctx, func);
JS_FreeValue(ctx, arg);
}
if (JS_IsFunction(ctx, elwin->onmessage)) {
JSValue func = JS_DupValue(ctx, elwin->onmessage);
JSValue arg = JS_DupValue(ctx, mess->messageObject);
JSValue ret = JS_Call(ctx, func, elwin->thisval, 1, (JSValueConst *) &arg);
JS_FreeValue(ctx, ret);
JS_FreeValue(ctx, func);
JS_FreeValue(ctx, arg);
}
done_heartbeat(interpreter->heartbeat);
check_for_rerender(interpreter, "window_message");
}
}
static JSValue
js_window_postMessage(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct el_window *elwin = (struct el_window *)(JS_GetOpaque(this_val, js_window_class_id));
if (argc < 2) {
return JS_UNDEFINED;
}
const char *str;
size_t len;
str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) {
return JS_EXCEPTION;
}
char *data = stracpy(str);
JS_FreeCString(ctx, str);
str = JS_ToCStringLen(ctx, &len, argv[1]);
if (!str) {
mem_free_if(data);
return JS_EXCEPTION;
}
char *targetOrigin = stracpy(str);
JS_FreeCString(ctx, str);
char *source = stracpy("TODO");
JSValue val = get_messageEvent(ctx, data, targetOrigin, source);
mem_free_if(data);
mem_free_if(targetOrigin);
mem_free_if(source);
if (JS_IsNull(val) || !elwin) {
return JS_UNDEFINED;
}
struct el_message *mess = (struct el_message *)mem_calloc(1, sizeof(*mess));
if (!mess) {
return JS_EXCEPTION;
}
mess->messageObject = JS_DupValue(ctx, val);
mess->elwin = elwin;
register_bottom_half(onmessage_run, mess);
return JS_UNDEFINED;
}
static const JSCFunctionListEntry js_window_proto_funcs[] = {
JS_CGETSET_DEF("closed", js_window_get_property_closed, nullptr),
JS_CGETSET_DEF("parent", js_window_get_property_parent, nullptr),
JS_CGETSET_DEF("self", js_window_get_property_self, nullptr),
JS_CGETSET_DEF("status", js_window_get_property_status, js_window_set_property_status),
JS_CGETSET_DEF("top", js_window_get_property_top, nullptr),
JS_CGETSET_DEF("window", js_window_get_property_self, nullptr),
JS_CFUNC_DEF("addEventListener", 3, js_window_addEventListener),
JS_CFUNC_DEF("alert", 1, js_window_alert),
JS_CFUNC_DEF("clearTimeout", 1, js_window_clearTimeout),
JS_CFUNC_DEF("open", 3, js_window_open),
JS_CFUNC_DEF("postMessage", 3, js_window_postMessage),
JS_CFUNC_DEF("removeEventListener", 3, js_window_removeEventListener),
JS_CFUNC_DEF("setTimeout", 2, js_window_setTimeout),
JS_CFUNC_DEF("toString", 0, js_window_toString)
};
static JSClassDef js_window_class = {
"window",
.finalizer = js_window_finalize,
.gc_mark = js_window_mark,
};
int
js_window_init(JSContext *ctx)
{
JSValue window_proto;
/* create the window class */
JS_NewClassID(&js_window_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_window_class_id, &js_window_class);
JSValue global_obj = JS_GetGlobalObject(ctx);
REF_JS(global_obj);
window_proto = JS_NewObject(ctx);
REF_JS(window_proto);
JS_SetPropertyFunctionList(ctx, window_proto, js_window_proto_funcs, countof(js_window_proto_funcs));
JS_SetClassProto(ctx, js_window_class_id, window_proto);
JS_SetPropertyStr(ctx, global_obj, "window", JS_DupValue(ctx, window_proto));
JS_SetPropertyFunctionList(ctx, global_obj, js_window_proto_funcs, countof(js_window_proto_funcs));
JS_FreeValue(ctx, global_obj);
return 0;
}
#endif

File diff suppressed because it is too large Load Diff