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

[mujs] Removed old code

This commit is contained in:
Witold Filipczyk 2023-05-04 16:10:44 +02:00
parent 1544b1fd02
commit d3dc68ab3e
25 changed files with 0 additions and 10965 deletions

View File

@ -4,8 +4,6 @@ INCLUDES += $(SPIDERMONKEY_CFLAGS) $(MUJS_CFLAGS)
SUBDIRS-$(CONFIG_LIBDOM) += libdom
SUBDIRS-$(CONFIG_MUJS) += mujs
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

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

View File

@ -1,9 +0,0 @@
top_builddir=../../..
include $(top_builddir)/Makefile.config
INCLUDES += $(MUJS_CFLAGS)
OBJS = attr.obj attributes.obj collection.obj console.obj document.obj element.obj form.obj \
forms.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,139 +0,0 @@
/* The MuJS 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/mujs.h"
#include "ecmascript/mujs/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>
#ifndef CONFIG_LIBDOM
static void
mjs_attr_get_property_name(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
xmlpp::AttributeNode *attr = static_cast<xmlpp::AttributeNode *>(js_touserdata(J, 0, "attr"));
if (!attr) {
js_pushnull(J);
return;
}
xmlpp::ustring v = attr->get_name();
js_pushstring(J, v.c_str());
}
static void
mjs_attr_get_property_value(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
xmlpp::AttributeNode *attr = static_cast<xmlpp::AttributeNode *>(js_touserdata(J, 0, "attr"));
if (!attr) {
js_pushnull(J);
return;
}
xmlpp::ustring v = attr->get_value();
js_pushstring(J, v.c_str());
}
static void
mjs_attr_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[attr object]");
}
static std::map<void *, void *> map_attrs;
static
void mjs_attr_finalizer(js_State *J, void *node)
{
map_attrs.erase(node);
}
void
mjs_push_attr(js_State *J, void *node)
{
js_newobject(J);
{
js_newuserdata(J, "attr", node, mjs_attr_finalizer);
addmethod(J, "toString", mjs_attr_toString, 0);
addproperty(J, "name", mjs_attr_get_property_name, NULL);
addproperty(J, "value", mjs_attr_get_property_value, NULL);
}
}
#endif

View File

@ -1,242 +0,0 @@
/* The MuJS 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/mujs.h"
#include "ecmascript/mujs/attr.h"
#include "ecmascript/mujs/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
static std::map<void *, void *> map_attributes;
static std::map<void *, void *> map_rev_attributes;
static void
mjs_attributes_set_items(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
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;
}
// TODO Check it
mjs_push_attr(J, attr);
js_setindex(J, -2, i);
xmlpp::ustring name = attr->get_name();
if (js_try(J)) {
js_pop(J, 1);
continue;
}
mjs_push_attr(J, attr);
js_setproperty(J, -2, name.c_str());
js_endtry(J);
}
}
static void
mjs_attributes_get_property_length(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
xmlpp::Element::AttributeList *al = static_cast<xmlpp::Element::AttributeList *>(js_touserdata(J, 0, "attribute"));
if (!al) {
js_pushnumber(J, 0);
return;
}
js_pushnumber(J, al->size());
}
static void
mjs_push_attributes_item2(js_State *J, int idx)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
xmlpp::Element::AttributeList *al = static_cast<xmlpp::Element::AttributeList *>(js_touserdata(J, 0, "attribute"));
if (!al) {
js_pushundefined(J);
return;
}
auto it = al->begin();
auto end = al->end();
int i = 0;
for (;it != end; it++, i++) {
if (i != idx) {
continue;
}
xmlpp::Attribute *attr = *it;
mjs_push_attr(J, attr);
return;
}
js_pushundefined(J);
}
static void
mjs_attributes_item(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
int index = js_toint32(J, 1);
mjs_push_attributes_item2(J, index);
}
static void
mjs_push_attributes_namedItem2(js_State *J, const char *str)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
xmlpp::Element::AttributeList *al = static_cast<xmlpp::Element::AttributeList *>(js_touserdata(J, 0, "attribute"));
if (!al) {
js_pushundefined(J);
return;
}
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()) {
mjs_push_attr(J, attr);
return;
}
}
js_pushundefined(J);
}
static void
mjs_attributes_getNamedItem(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
const char *str = js_tostring(J, 1);
mjs_push_attributes_namedItem2(J, str);
}
static void
mjs_attributes_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[attributes object]");
}
static void
mjs_attributes_finalizer(js_State *J, void *node)
{
map_attributes.erase(node);
}
void
mjs_push_attributes(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_newarray(J);
{
js_newuserdata(J, "attribute", node, mjs_attributes_finalizer);
addmethod(J, "item", mjs_attributes_item, 1);
addmethod(J, "getNamedItem", mjs_attributes_getNamedItem, 1);
addmethod(J, "toString", mjs_attributes_toString, 0);
addproperty(J, "length", mjs_attributes_get_property_length, NULL);
mjs_attributes_set_items(J, node);
}
map_attributes[node] = node;
}
#endif

View File

@ -1,239 +0,0 @@
/* The MuJS 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/mujs.h"
#include "ecmascript/mujs/collection.h"
#include "ecmascript/mujs/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>
#ifndef CONFIG_LIBDOM
static std::map<void *, void *> map_collections;
static std::map<void *, void *> map_rev_collections;
static void
mjs_htmlCollection_get_property_length(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
xmlpp::Node::NodeSet *ns = static_cast<xmlpp::Node::NodeSet *>(js_touserdata(J, 0, "collection"));
if (!ns) {
js_pushnumber(J, 0);
return;
}
js_pushnumber(J, ns->size());
}
static void
mjs_push_htmlCollection_item2(js_State *J, int idx)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
xmlpp::Node::NodeSet *ns = static_cast<xmlpp::Node::NodeSet *>(js_touserdata(J, 0, "collection"));
if (!ns) {
js_pushundefined(J);
return;
}
xmlpp::Element *element;
try {
element = dynamic_cast<xmlpp::Element *>(ns->at(idx));
} catch (std::out_of_range &e) {
js_pushundefined(J);
return;
}
if (!element) {
js_pushundefined(J);
return;
}
mjs_push_element(J, element);
}
static void
mjs_htmlCollection_item(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
int index = js_toint32(J, 1);
mjs_push_htmlCollection_item2(J, index);
}
static void
mjs_push_htmlCollection_namedItem2(js_State *J, const char *str)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
xmlpp::Node::NodeSet *ns = static_cast<xmlpp::Node::NodeSet *>(js_touserdata(J, 0, "collection"));
if (!ns) {
js_pushundefined(J);
return;
}
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")) {
mjs_push_element(J, element);
return;
}
}
js_pushundefined(J);
}
static void
mjs_htmlCollection_namedItem(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
const char *str = js_tostring(J, 1);
mjs_push_htmlCollection_namedItem2(J, str);
}
static void
mjs_htmlCollection_set_items(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
int counter = 0;
xmlpp::Node::NodeSet *ns = static_cast<xmlpp::Node::NodeSet *>(node);
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;
}
mjs_push_element(J, element);
js_setindex(J, -2, counter);
xmlpp::ustring name = element->get_attribute_value("id");
if (name == "") {
name = element->get_attribute_value("name");
}
if (js_try(J)) {
js_pop(J, 1);
goto next;
}
mjs_push_element(J, element);
js_setproperty(J, -2, name.c_str());
js_endtry(J);
next:
counter++;
}
}
static void
mjs_htmlCollection_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[htmlCollection object]");
}
static void
mjs_htmlCollection_finalizer(js_State *J, void *node)
{
map_collections.erase(node);
}
void
mjs_push_collection(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_newarray(J);
{
js_newuserdata(J, "collection", node, mjs_htmlCollection_finalizer);
addmethod(J, "item", mjs_htmlCollection_item, 1);
addmethod(J, "namedItem", mjs_htmlCollection_namedItem, 1);
addmethod(J, "toString", mjs_htmlCollection_toString, 0);
addproperty(J, "length", mjs_htmlCollection_get_property_length, NULL);
mjs_htmlCollection_set_items(J, node);
}
map_collections[node] = node;
}
#endif

View File

@ -1,103 +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/mujs.h"
#include "ecmascript/mujs/console.h"
#include "intl/libintl.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"
#include "util/conv.h"
#include "util/memory.h"
#include "util/string.h"
#include <time.h>
#include "document/renderer.h"
#include "document/refresh.h"
#include "terminal/screen.h"
#ifndef CONFIG_LIBDOM
#define DEBUG 0
static void
mjs_console_log_common(js_State *J, const char *str, const char *log_filename)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
if (log_filename && get_opt_bool("ecmascript.enable_console_log", NULL) && str)
{
FILE *f = fopen(log_filename, "a");
if (f)
{
fprintf(f, "%s\n", str);
fclose(f);
}
}
js_pushundefined(J);
}
static void
mjs_console_log(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
const char *str = js_tostring(J, 1);
mjs_console_log_common(J, str, console_log_filename);
}
static void
mjs_console_error(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
const char *str = js_tostring(J, 1);
mjs_console_log_common(J, str, console_error_filename);
}
static void
mjs_console_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[console object]");
}
int
mjs_console_init(js_State *J)
{
js_newobject(J);
{
addmethod(J, "console.log", mjs_console_log, 1);
addmethod(J, "console.error", mjs_console_error, 1);
addmethod(J, "console.toString", mjs_console_toString, 0);
}
js_defglobal(J, "console", JS_DONTENUM);
return 0;
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,867 +0,0 @@
/* The MuJS form 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/mujs.h"
#include "ecmascript/mujs/document.h"
#include "ecmascript/mujs/form.h"
#include "ecmascript/mujs/forms.h"
#include "ecmascript/mujs/input.h"
#include "ecmascript/mujs/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
static std::map<struct form_view *, void *> map_form_elements;
static std::map<void *, struct form_view *> map_elements_form;
static std::map<struct form *, void *> map_form;
static std::map<void *, struct form *> map_rev_form;
//void mjs_push_form_object(js_State *J, struct form *form);
static void
mjs_push_form_control_object(js_State *J,
enum form_type type, struct form_state *fs)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
switch (type) {
case FC_TEXT:
case FC_PASSWORD:
case FC_FILE:
case FC_CHECKBOX:
case FC_RADIO:
case FC_SUBMIT:
case FC_IMAGE:
case FC_RESET:
case FC_BUTTON:
case FC_HIDDEN:
case FC_SELECT:
mjs_push_input_object(J, fs);
return;
case FC_TEXTAREA:
/* TODO */
js_pushnull(J);
return;
default:
INTERNAL("Weird fc->type %d", type);
js_pushnull(J);
return;
}
}
static void
mjs_form_set_items(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
struct form_view *form_view;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
doc_view = vs->doc_view;
document = doc_view->document;
form_view = (struct form_view *)node;
if (!form_view) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return; /* detached */
}
form = find_form_by_form_view(document, form_view);
int counter = 0;
struct el_form_control *fc;
foreach (fc, form->items) {
struct form_state *fs = find_form_state(doc_view, fc);
if (!fs) {
continue;
}
mjs_push_form_control_object(J, fc->type, fs);
js_setindex(J, -2, counter);
if (fc->id) {
if (js_try(J)) {
js_pop(J, 1);
goto next;
}
mjs_push_form_control_object(J, fc->type, fs);
js_setproperty(J, -2, fc->id);
js_endtry(J);
} else if (fc->name) {
if (js_try(J)) {
js_pop(J, 1);
goto next;
}
mjs_push_form_control_object(J, fc->type, fs);
js_setproperty(J, -2, fc->name);
js_endtry(J);
}
next:
counter++;
}
}
static void
mjs_form_set_items2(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct document_view *doc_view;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
doc_view = vs->doc_view;
form = (struct form *)node;
int counter = 0;
struct el_form_control *fc;
foreach (fc, form->items) {
struct form_state *fs = find_form_state(doc_view, fc);
if (!fs) {
continue;
}
mjs_push_form_control_object(J, fc->type, fs);
js_setindex(J, -2, counter);
if (fc->id) {
if (js_try(J)) {
js_pop(J, 1);
goto next;
}
mjs_push_form_control_object(J, fc->type, fs);
js_setproperty(J, -2, fc->id);
js_endtry(J);
} else if (fc->name) {
if (js_try(J)) {
js_pop(J, 1);
goto next;
}
mjs_push_form_control_object(J, fc->type, fs);
js_setproperty(J, -2, fc->name);
js_endtry(J);
}
next:
counter++;
}
}
static void
mjs_form_elements_get_property_length(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
struct form_view *form_view;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
doc_view = vs->doc_view;
document = doc_view->document;
form_view = (struct form_view *)js_touserdata(J, 0, "form_view");
if (!form_view) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return; /* detached */
}
form = find_form_by_form_view(document, form_view);
js_pushnumber(J, list_size(&form->items));
}
static void
mjs_form_elements_item2(js_State *J, int index)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
struct form_view *form_view;
struct form *form;
struct el_form_control *fc;
int counter = -1;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
doc_view = vs->doc_view;
document = doc_view->document;
form_view = (struct form_view *)js_touserdata(J, 0, "form_view");
if (!form_view) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushnull(J);
return; /* detached */
}
form = find_form_by_form_view(document, form_view);
foreach (fc, form->items) {
counter++;
if (counter == index) {
struct form_state *fs = find_form_state(doc_view, fc);
if (fs) {
mjs_push_form_control_object(J, fc->type, fs);
return;
}
}
}
js_pushundefined(J);
}
/* @form_elements_funcs{"item"} */
static void
mjs_form_elements_item(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
int index = js_toint32(J, 1);
mjs_form_elements_item2(J, index);
}
static void
mjs_form_elements_namedItem2(js_State *J, const char *string)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct document_view *doc_view;
struct document *document;
struct form_view *form_view;
struct form *form;
struct el_form_control *fc;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
if (!*string) {
js_pushundefined(J);
return;
}
vs = interpreter->vs;
doc_view = vs->doc_view;
document = doc_view->document;
form_view = (struct form_view *)js_touserdata(J, 0, "form_view");
if (!form_view) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushnull(J);
return; /* detached */
}
form = find_form_by_form_view(document, form_view);
foreach (fc, form->items) {
if ((fc->id && !c_strcasecmp(string, fc->id))
|| (fc->name && !c_strcasecmp(string, fc->name))) {
struct form_state *fs = find_form_state(doc_view, fc);
if (fs) {
mjs_push_form_control_object(J, fc->type, fs);
return;
}
}
}
js_pushundefined(J);
}
/* @form_elements_funcs{"namedItem"} */
static void
mjs_form_elements_namedItem(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
mjs_form_elements_namedItem2(J, str);
}
static void
mjs_form_elements_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[form elements object]");
}
static void
mjs_form_get_property_action(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
js_pushstring(J, form->action);
}
static void
mjs_form_set_property_action(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
const char *str = js_tostring(J, 1);
char *string;
if (!str) {
js_error(J, "!str");
return;
}
string = stracpy(str);
if (form->action) {
ecmascript_set_action(&form->action, string);
} else {
mem_free_set(&form->action, string);
}
js_pushundefined(J);
}
#if 0
void
mjs_detach_form_view(struct form_view *fv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JSValue jsform = fv->ecmascript_obj;
if (!JS_IsNull(jsform)) {
map_form_elements.erase(fv);
setOpaque(jsform, nullptr);
fv->ecmascript_obj = JS_NULL;
}
}
#endif
static void
mjs_elements_finalizer(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct form_view *fv = (struct form_view *)node;
map_form_elements.erase(fv);
}
void
mjs_push_form_elements(js_State *J, struct form_view *fv)
{
js_newarray(J);
{
js_newuserdata(J, "form_view", fv, mjs_elements_finalizer);
addmethod(J, "item", mjs_form_elements_item, 1);
addmethod(J, "namedItem", mjs_form_elements_namedItem, 1);
addmethod(J, "toString", mjs_form_elements_toString, 0);
addproperty(J, "length", mjs_form_elements_get_property_length, NULL);
mjs_form_set_items(J, fv);
}
map_form_elements[fv] = fv;
}
static void
mjs_form_get_property_elements(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
struct form *form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
struct form_view *fv = NULL;
bool found = false;
foreach (fv, vs->forms) {
if (form->form_num == fv->form_num) {
found = true;
break;
}
}
if (!found || !fv) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushnull(J);
return; /* detached */
}
mjs_push_form_elements(J, fv);
}
static void
mjs_form_get_property_encoding(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
switch (form->method) {
case FORM_METHOD_GET:
case FORM_METHOD_POST:
js_pushstring(J, "application/x-www-form-urlencoded");
return;
case FORM_METHOD_POST_MP:
js_pushstring(J, "multipart/form-data");
return;
case FORM_METHOD_POST_TEXT_PLAIN:
js_pushstring(J, "text/plain");
return;
}
js_pushundefined(J);
}
/* @form_class.setProperty */
static void
mjs_form_set_property_encoding(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
if (!c_strcasecmp(str, "application/x-www-form-urlencoded")) {
form->method = form->method == FORM_METHOD_GET ? FORM_METHOD_GET
: FORM_METHOD_POST;
} else if (!c_strcasecmp(str, "multipart/form-data")) {
form->method = FORM_METHOD_POST_MP;
} else if (!c_strcasecmp(str, "text/plain")) {
form->method = FORM_METHOD_POST_TEXT_PLAIN;
}
js_pushundefined(J);
}
static void
mjs_form_get_property_length(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
js_pushnumber(J, list_size(&form->items));
}
static void
mjs_form_get_property_method(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
switch (form->method) {
case FORM_METHOD_GET:
js_pushstring(J, "GET");
return;
case FORM_METHOD_POST:
case FORM_METHOD_POST_MP:
case FORM_METHOD_POST_TEXT_PLAIN:
js_pushstring(J, "POST");
return;
}
js_pushundefined(J);
}
/* @form_class.setProperty */
static void
mjs_form_set_property_method(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
if (!c_strcasecmp(str, "GET")) {
form->method = FORM_METHOD_GET;
} else if (!c_strcasecmp(str, "POST")) {
form->method = FORM_METHOD_POST;
}
js_pushundefined(J);
}
static void
mjs_form_get_property_name(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
js_pushstring(J, form->name);
}
/* @form_class.setProperty */
static void
mjs_form_set_property_name(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
mem_free_set(&form->name, stracpy(str));
js_pushundefined(J);
}
static void
mjs_form_get_property_target(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
js_pushstring(J, form->target);
}
static void
mjs_form_set_property_target(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
mem_free_set(&form->target, stracpy(str));
js_pushundefined(J);
}
/* @form_funcs{"reset"} */
static void
mjs_form_reset(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct document_view *doc_view;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
doc_view = vs->doc_view;
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
do_reset_form(doc_view, form);
draw_forms(doc_view->session->tab->term, doc_view);
js_pushundefined(J);
}
/* @form_funcs{"submit"} */
static void
mjs_form_submit(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct document_view *doc_view;
struct session *ses;
struct form *form;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
vs = interpreter->vs;
doc_view = vs->doc_view;
ses = doc_view->session;
form = (struct form *)js_touserdata(J, 0, "form");
assert(form);
submit_given_form(ses, doc_view, form, 0);
js_pushundefined(J);
}
static void
mjs_form_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[form object]");
}
static
void mjs_form_finalizer(js_State *J, void *node)
{
struct form *form = (struct form *)node;
map_form.erase(form);
}
void
mjs_push_form_object(js_State *J, struct form *form)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_newarray(J);
{
js_newuserdata(J, "form", form, mjs_form_finalizer);
addmethod(J, "reset", mjs_form_reset, 0);
addmethod(J, "submit", mjs_form_submit, 0);
addmethod(J, "toString", mjs_form_toString, 0);
addproperty(J, "action", mjs_form_get_property_action, mjs_form_set_property_action);
addproperty(J, "elements", mjs_form_get_property_elements, NULL);
addproperty(J, "encoding", mjs_form_get_property_encoding, mjs_form_set_property_encoding);
addproperty(J, "length", mjs_form_get_property_length, NULL);
addproperty(J, "method", mjs_form_get_property_method, mjs_form_set_property_method);
addproperty(J, "name", mjs_form_get_property_name, mjs_form_set_property_name);
addproperty(J, "target", mjs_form_get_property_target, mjs_form_set_property_target);
mjs_form_set_items2(J, form);
}
map_form[form] = form;
}
#endif

View File

@ -1,230 +0,0 @@
/* The MuJS forms 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/mujs.h"
#include "ecmascript/mujs/document.h"
#include "ecmascript/mujs/form.h"
#include "ecmascript/mujs/forms.h"
#include "ecmascript/mujs/input.h"
#include "ecmascript/mujs/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
static std::map<void *, void *> map_forms;
static std::map<void *, void *> map_rev_forms;
/* Find the form whose name is @name, which should normally be a
* string (but might not be). */
static void
mjs_find_form_by_name(js_State *J,
struct document_view *doc_view,
const char *string)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct form *form;
if (!*string) {
js_pushnull(J);
return;
}
foreach (form, doc_view->document->forms) {
if (form->name && !c_strcasecmp(string, form->name)) {
mjs_push_form_object(J, form);
return;
}
}
js_pushnull(J);
}
static void
mjs_forms_set_items(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct document_view *doc_view;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
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);
mjs_push_form_object(J, form);
js_setindex(J, -2, counter);
if (form->name) {
if (js_try(J)) {
js_pop(J, 1);
goto next;
}
mjs_push_form_object(J, form);
js_setproperty(J, -2, form->name);
js_endtry(J);
}
next:
counter++;
}
}
static void
mjs_forms_get_property_length(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
struct document_view *doc_view = vs->doc_view;
struct document *document = doc_view->document;
js_pushnumber(J, list_size(&document->forms));
}
static void
mjs_forms_item2(js_State *J, int index)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct view_state *vs;
struct form_view *fv;
int counter = -1;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
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);
mjs_push_form_object(J, form);
return;
}
}
js_pushundefined(J);
}
/* @forms_funcs{"item"} */
static void
mjs_forms_item(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
int index = js_toint32(J, 1);;
mjs_forms_item2(J, index);
}
/* @forms_funcs{"namedItem"} */
static void
mjs_forms_namedItem(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
const char *str = js_tostring(J, 1);;
if (!str) {
js_error(J, "!str");
return;
}
mjs_find_form_by_name(J, doc_view, str);
}
static void
mjs_forms_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[forms object]");
}
void
mjs_push_forms(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_newarray(J);
{
js_newuserdata(J, "forms", node, NULL);
addmethod(J, "item", mjs_forms_item, 1);
addmethod(J, "namedItem", mjs_forms_namedItem, 1);
addmethod(J, "toString", mjs_forms_toString, 0);
addproperty(J, "length", mjs_forms_get_property_length, NULL);
mjs_forms_set_items(J);
}
map_forms[node] = node;
}
#endif

View File

@ -1,138 +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/mujs.h"
#include "ecmascript/mujs/history.h"
#include "ecmascript/mujs/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
static void
mjs_history_back(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
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 */
js_pushnull(J);
}
static void
mjs_history_forward(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
go_unback(ses);
js_pushnull(J);
}
static void
mjs_history_go(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
struct document_view *doc_view = interpreter->vs->doc_view;
struct session *ses = doc_view->session;
struct location *loc;
int index = js_tointeger(J, 1);
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;
}
js_pushnull(J);
}
static void
mjs_history_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[history object]");
}
int
mjs_history_init(js_State *J)
{
js_newobject(J);
{
addmethod(J, "history.back", mjs_history_back, 0);
addmethod(J, "history.forward", mjs_history_forward, 0);
addmethod(J, "history.go", mjs_history_go, 1);
addmethod(J, "history.toString", mjs_history_toString, 0);
}
js_defglobal(J, "history", JS_DONTENUM);
return 0;
}
#endif

View File

@ -1,78 +0,0 @@
/* The MuJS 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/mujs.h"
#include "ecmascript/mujs/document.h"
#include "ecmascript/mujs/implementation.h"
#include "util/conv.h"
#include <libxml/HTMLparser.h>
#include <libxml++/libxml++.h>
#ifndef CONFIG_LIBDOM
static void
mjs_implementation_createHTMLDocument(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
const char *title = js_tostring(J, 1);
if (!title) {
js_error(J, "!title");
return;
}
struct string str;
if (!init_string(&str)) {
js_error(J, "out of memory");
return;
}
add_to_string(&str, "<!doctype html>\n<html><head><title>");
add_to_string(&str, title);
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);
mjs_push_document(J, docu);
}
static void
mjs_implementation_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[implementation object]");
}
void
mjs_push_implementation(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_newobject(J);
{
addmethod(J, "createHTMLDocument", mjs_implementation_createHTMLDocument, 1);
addmethod(J, "toString", mjs_implementation_toString, 0);
}
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,128 +0,0 @@
/* The MuJS 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/mujs.h"
#include "ecmascript/mujs/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
static void mjs_keyboardEvent_get_property_key(js_State *J);
static void mjs_keyboardEvent_get_property_keyCode(js_State *J);
static unicode_val_T keyCode;
struct keyboard {
unicode_val_T keyCode;
};
static void
mjs_keyboardEvent_finalizer(js_State *J, void *val)
{
struct keyboard *keyb = (struct keyboard *)val;
if (keyb) {
mem_free(keyb);
}
}
void
mjs_push_keyboardEvent(js_State *J, struct term_event *ev)
{
struct keyboard *keyb = (struct keyboard *)mem_calloc(1, sizeof(*keyb));
if (!keyb) {
js_error(J, "out of memory");
return;
}
keyCode = keyb->keyCode = get_kbd_key(ev);
js_newobject(J);
{
js_newuserdata(J, "event", keyb, mjs_keyboardEvent_finalizer);
addproperty(J, "key", mjs_keyboardEvent_get_property_key, NULL);
addproperty(J, "keyCode", mjs_keyboardEvent_get_property_keyCode, NULL);
}
}
static void
mjs_keyboardEvent_get_property_key(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct keyboard *keyb = (struct keyboard *)js_touserdata(J, 0, "event");
if (!keyb) {
js_pushnull(J);
return;
}
char text[8] = {0};
*text = keyb->keyCode;
js_pushstring(J, text);
}
static void
mjs_keyboardEvent_get_property_keyCode(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct keyboard *keyb = (struct keyboard *)js_touserdata(J, 0, "event");
if (!keyb) {
js_pushnull(J);
return;
}
js_pushnumber(J, keyb->keyCode);
}
#endif

View File

@ -1,188 +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/mujs.h"
#include "ecmascript/mujs/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
/* 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 void
mjs_localstorage_getitem(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
const char *key = js_tostring(J, 1);
if (!key) {
js_pushnull(J);
return;
}
char *val = readFromStorage(key);
if (!val) {
js_pushnull(J);
return;
}
js_pushstring(J, val);
mem_free(val);
}
static void
mjs_localstorage_removeitem(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
const char *key = js_tostring(J, 1);
if (key) {
removeFromStorage(key);
}
js_pushundefined(J);
}
static void
mjs_localstorage_setitem(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
const char *key_str = js_tostring(J, 1);
const char *val_str = js_tostring(J, 2);
if (!key_str || !val_str)
{
js_pushundefined(J);
return;
}
saveToStorage(key_str, val_str);
#ifdef CONFIG_LEDS
set_led_value(interpreter->vs->doc_view->session->status.ecmascript_led, 'J');
#endif
js_pushundefined(J);
}
static void
mjs_localstorage_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[localstorage object]");
}
int
mjs_localstorage_init(js_State *J)
{
js_newobject(J);
{
addmethod(J, "localStorage.getItem", mjs_localstorage_getitem, 1);
addmethod(J, "localStorage.removeItem", mjs_localstorage_removeitem, 1);
addmethod(J, "localStorage.setItem", mjs_localstorage_setitem, 2);
addmethod(J, "localStorage.toString", mjs_localstorage_toString, 0);
}
js_defglobal(J, "localStorage", JS_DONTENUM);
return 0;
}
#endif

View File

@ -1,591 +0,0 @@
/* The MuJS 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/mujs.h"
#include "ecmascript/mujs/location.h"
#include "ecmascript/mujs/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
static void
mjs_location_get_property_hash(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
struct string fragment;
if (!init_string(&fragment)) {
js_error(J, "out of memory");
return;
}
if (vs->uri->fragmentlen) {
add_bytes_to_string(&fragment, vs->uri->fragment, vs->uri->fragmentlen);
}
js_pushstring(J, fragment.source);
done_string(&fragment);
}
static void
mjs_location_get_property_host(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
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
js_error(J, "!str");
return;
}
js_pushstring(J, str);
mem_free(str);
}
static void
mjs_location_get_property_hostname(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
char *str = get_uri_string(vs->uri, URI_HOST);
if (!str) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!str");
return;
}
js_pushstring(J, str);
mem_free(str);
}
static void
mjs_location_get_property_href(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
char *str = get_uri_string(vs->uri, URI_ORIGINAL);
if (!str) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!str");
return;
}
js_pushstring(J, str);
mem_free(str);
}
static void
mjs_location_get_property_origin(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
char *str = get_uri_string(vs->uri, URI_SERVER);
if (!str) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!str");
return;
}
js_pushstring(J, str);
mem_free(str);
}
static void
mjs_location_get_property_pathname(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
struct string pathname;
if (!init_string(&pathname)) {
js_error(J, "out of memory");
return;
}
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);
js_pushstring(J, pathname.source);
done_string(&pathname);
}
static void
mjs_location_get_property_port(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
struct string port;
if (!init_string(&port)) {
js_error(J, "out of memory");
return;
}
if (vs->uri->portlen) {
add_bytes_to_string(&port, vs->uri->port, vs->uri->portlen);
}
js_pushstring(J, port.source);
done_string(&port);
}
static void
mjs_location_get_property_protocol(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
struct string proto;
if (!init_string(&proto)) {
js_error(J, "out of memory");
return;
}
/* 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, ':');
}
js_pushstring(J, proto.source);
done_string(&proto);
}
static void
mjs_location_get_property_search(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
struct string search;
if (!init_string(&search)) {
js_error(J, "out of memory");
return;
}
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));
}
js_pushstring(J, search.source);
done_string(&search);
}
static void
mjs_location_set_property_hash(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
location_goto_const(vs->doc_view, str);
js_pushundefined(J);
}
static void
mjs_location_set_property_host(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
location_goto_const(vs->doc_view, str);
js_pushundefined(J);
}
static void
mjs_location_set_property_hostname(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
location_goto_const(vs->doc_view, str);
js_pushundefined(J);
}
static void
mjs_location_set_property_href(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
location_goto_const(vs->doc_view, str);
js_pushundefined(J);
}
static void
mjs_location_set_property_pathname(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
location_goto_const(vs->doc_view, str);
js_pushundefined(J);
}
static void
mjs_location_set_property_port(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
location_goto_const(vs->doc_view, str);
js_pushundefined(J);
}
static void
mjs_location_set_property_protocol(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
location_goto_const(vs->doc_view, str);
js_pushundefined(J);
}
static void
mjs_location_set_property_search(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
location_goto_const(vs->doc_view, str);
js_pushundefined(J);
}
static void
mjs_location_reload(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_error(J, "!vs");
return;
}
location_goto_const(vs->doc_view, "");
js_pushundefined(J);
}
/* @location_funcs{"toString"}, @location_funcs{"toLocaleString"} */
static void
mjs_location_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
mjs_location_get_property_href(J);
}
int
mjs_location_init(js_State *J)
{
js_newobject(J);
{
addmethod(J, "reload", mjs_location_reload, 0);
addmethod(J, "toString", mjs_location_toString, 0);
addmethod(J, "toLocaleString", mjs_location_toString, 0);
addproperty(J, "hash", mjs_location_get_property_hash, mjs_location_set_property_hash);
addproperty(J, "host", mjs_location_get_property_host, mjs_location_set_property_host);
addproperty(J, "hostname", mjs_location_get_property_hostname, mjs_location_set_property_hostname);
addproperty(J, "href", mjs_location_get_property_href, mjs_location_set_property_href);
addproperty(J, "origin", mjs_location_get_property_origin, NULL);
addproperty(J, "pathname", mjs_location_get_property_pathname, mjs_location_set_property_pathname);
addproperty(J, "port", mjs_location_get_property_port, mjs_location_set_property_port);
addproperty(J, "protocol", mjs_location_get_property_protocol, mjs_location_set_property_protocol);
addproperty(J, "search", mjs_location_get_property_search, mjs_location_set_property_search);
}
js_defglobal(J, "location", JS_DONTENUM);
return 0;
}
void
mjs_push_location(js_State *J)
{
mjs_location_init(J);
}
#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', '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,180 +0,0 @@
/* The MuJS 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/mujs.h"
#include "ecmascript/mujs/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
static void mjs_messageEvent_get_property_data(js_State *J);
static void mjs_messageEvent_get_property_lastEventId(js_State *J);
static void mjs_messageEvent_get_property_origin(js_State *J);
static void mjs_messageEvent_get_property_source(js_State *J);
struct message_event {
char *data;
char *lastEventId;
char *origin;
char *source;
};
static
void mjs_messageEvent_finalizer(js_State *J, void *val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct message_event *event = (struct message_event *)val;
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 int lastEventId;
void
mjs_push_messageEvent(js_State *J, char *data, char *origin, char *source)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct message_event *event = (struct message_event *)mem_calloc(1, sizeof(*event));
if (!event) {
js_error(J, "out of memory");
return;
}
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);
js_newobject(J);
{
js_newuserdata(J, "event", event, mjs_messageEvent_finalizer);
addproperty(J, "data", mjs_messageEvent_get_property_data, NULL);
addproperty(J, "lastEventId", mjs_messageEvent_get_property_lastEventId, NULL);
addproperty(J, "origin", mjs_messageEvent_get_property_origin, NULL);
addproperty(J, "source", mjs_messageEvent_get_property_source, NULL);
}
}
static void
mjs_messageEvent_get_property_data(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct message_event *event = (struct message_event *)js_touserdata(J, 0, "event");
if (!event || !event->data) {
js_pushnull(J);
return;
}
js_pushstring(J, event->data);
}
static void
mjs_messageEvent_get_property_lastEventId(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct message_event *event = (struct message_event *)js_touserdata(J, 0, "event");
if (!event || !event->lastEventId) {
js_pushnull(J);
return;
}
js_pushstring(J, event->lastEventId);
}
static void
mjs_messageEvent_get_property_origin(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct message_event *event = (struct message_event *)js_touserdata(J, 0, "event");
if (!event || !event->origin) {
js_pushnull(J);
return;
}
js_pushstring(J, event->origin);
}
static void
mjs_messageEvent_get_property_source(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct message_event *event = (struct message_event *)js_touserdata(J, 0, "event");
if (!event || !event->source) {
js_pushnull(J);
return;
}
js_pushstring(J, event->source);
}
#endif

View File

@ -1,160 +0,0 @@
/* The mujs 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/mujs.h"
#include "ecmascript/mujs/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
static void
mjs_navigator_get_property_appCodeName(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "Mozilla");
}
static void
mjs_navigator_get_property_appName(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "ELinks (roughly compatible with Netscape Navigator, Mozilla and Microsoft Internet Explorer)");
}
static void
mjs_navigator_get_property_appVersion(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, VERSION);
}
static void
mjs_navigator_get_property_language(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
#ifdef CONFIG_NLS
if (get_opt_bool("protocol.http.accept_ui_language", NULL)) {
js_pushstring(J, language_to_iso639(current_language));
return;
}
#endif
js_pushundefined(J);
}
static void
mjs_navigator_get_property_platform(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, system_name);
}
static void
mjs_navigator_get_property_userAgent(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
char *optstr;
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);
js_pushstring(J, custr);
return;
}
}
js_pushstring(J, system_name);
}
static void
mjs_navigator_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[navigator object]");
}
int
mjs_navigator_init(js_State *J)
{
js_newobject(J);
{
addmethod(J, "navigator.toString", mjs_navigator_toString, 0);
addproperty(J, "navigator.appCodeName", mjs_navigator_get_property_appCodeName, NULL);
addproperty(J, "navigator.appName", mjs_navigator_get_property_appName, NULL);
addproperty(J, "navigator.appVersion", mjs_navigator_get_property_appVersion, NULL);
addproperty(J, "navigator.language", mjs_navigator_get_property_language, NULL);
addproperty(J, "navigator.platform", mjs_navigator_get_property_platform, NULL);
addproperty(J, "navigator.userAgent", mjs_navigator_get_property_userAgent, NULL);
}
js_defglobal(J, "navigator", JS_DONTENUM);
return 0;
}
#endif

View File

@ -1,176 +0,0 @@
/* The MuJS 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/mujs.h"
#include "ecmascript/mujs/element.h"
#include "ecmascript/mujs/nodelist.h"
#include "ecmascript/mujs/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
static std::map<void *, void *> map_nodelist;
static std::map<void *, void *> map_rev_nodelist;
#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 void
mjs_push_nodeList_item2(js_State *J, int idx)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
xmlpp::Node::NodeList *nl = static_cast<xmlpp::Node::NodeList *>(js_touserdata(J, 0, "nodelist"));
if (!nl) {
js_pushundefined(J);
return;
}
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) {
js_pushundefined(J);
return;
}
mjs_push_element(J, element);
}
static void
mjs_nodeList_item(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
int index = js_toint32(J, 1);
mjs_push_nodeList_item2(J, index);
}
static void
mjs_nodeList_set_items(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
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) {
mjs_push_element(J, element);
js_setindex(J, 1, i);
}
}
}
static void
mjs_nodeList_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[nodeList object]");
}
static void
mjs_nodeList_finalizer(js_State *J, void *node)
{
map_nodelist.erase(node);
}
void
mjs_push_nodelist(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_newobject(J);
{
js_newuserdata(J, "nodelist", node, mjs_nodeList_finalizer);
addmethod(J, "item", mjs_nodeList_item, 1);
addmethod(J, "toString", mjs_nodeList_toString, 0);
mjs_nodeList_set_items(J, node);
}
map_nodelist[node] = node;
}
#endif

View File

@ -1,163 +0,0 @@
/* The MuJS 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/mujs.h"
#include "ecmascript/mujs/screen.h"
#include "ecmascript/mujs/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
static void
mjs_screen_get_property_availHeight(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
js_pushundefined(J);
return;
}
js_pushnumber(J, doc_view->box.height * 16);
}
static void
mjs_screen_get_property_availWidth(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
js_pushundefined(J);
return;
}
js_pushnumber(J, doc_view->box.width * 8);
}
static void
mjs_screen_get_property_height(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
js_pushundefined(J);
return;
}
struct session *ses = doc_view->session;
if (!ses) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
js_pushnumber(J, ses->tab->term->height * 16);
}
static void
mjs_screen_get_property_width(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
js_pushundefined(J);
return;
}
struct session *ses = doc_view->session;
if (!ses) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
js_pushnumber(J, ses->tab->term->width * 8);
}
static void
mjs_screen_toString(js_State *J)
{
js_pushstring(J, "[screen object]");
}
int
mjs_screen_init(js_State *J)
{
js_newobject(J);
{
addmethod(J, "screen.toString", mjs_screen_toString, 0);
addproperty(J, "screen.availHeight", mjs_screen_get_property_availHeight, NULL);
addproperty(J, "screen.availWidth", mjs_screen_get_property_availWidth, NULL);
addproperty(J, "screen.height", mjs_screen_get_property_height, NULL);
addproperty(J, "screen.width", mjs_screen_get_property_width, NULL);
}
js_defglobal(J, "screen", JS_DONTENUM);
return 0;
}
#endif

View File

@ -1,181 +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/mujs.h"
#include "ecmascript/mujs/unibar.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
static void
mjs_menubar_get_property_visible(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
js_pushundefined(J);
return;
}
struct session_status *status = &doc_view->session->status;
js_pushboolean(J, status->force_show_title_bar >= 0
? status->force_show_title_bar
: status->show_title_bar);
}
static void
mjs_statusbar_get_property_visible(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
if (!doc_view) {
js_pushundefined(J);
return;
}
struct session_status *status = &doc_view->session->status;
js_pushboolean(J, status->force_show_status_bar >= 0
? status->force_show_status_bar
: status->show_status_bar);
}
static void
mjs_menubar_set_property_visible(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
int val = js_toboolean(J, 1);
if (!doc_view) {
js_pushundefined(J);
return;
}
struct session_status *status = &doc_view->session->status;
status->force_show_title_bar = val;
register_bottom_half(update_status, NULL);
js_pushundefined(J);
}
static void
mjs_statusbar_set_property_visible(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
int val = js_toboolean(J, 1);
if (!doc_view) {
js_pushundefined(J);
return;
}
struct session_status *status = &doc_view->session->status;
status->force_show_status_bar = val;
register_bottom_half(update_status, NULL);
js_pushundefined(J);
}
static void
mjs_menubar_toString(js_State *J)
{
js_pushstring(J, "[menubar object]");
}
static void
mjs_statusbar_toString(js_State *J)
{
js_pushstring(J, "[statusbar object]");
}
static void
mjs_menubar_init(js_State *J)
{
js_newobject(J);
{
addmethod(J, "menubar.toString", mjs_menubar_toString, 0);
addproperty(J, "menubar.visible", mjs_menubar_get_property_visible, mjs_menubar_set_property_visible);
}
js_defglobal(J, "menubar", JS_DONTENUM);
}
static void
mjs_statusbar_init(js_State *J)
{
js_newobject(J);
{
addmethod(J, "statusbar.toString", mjs_statusbar_toString, 0);
addproperty(J, "statusbar.visible", mjs_statusbar_get_property_visible, mjs_statusbar_set_property_visible);
}
js_defglobal(J, "statusbar", JS_DONTENUM);
}
int
mjs_unibar_init(js_State *J)
{
mjs_menubar_init(J);
mjs_statusbar_init(J);
return 0;
}
#endif

View File

@ -1,652 +0,0 @@
/* The MuJS 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/mujs.h"
#include "ecmascript/mujs/message.h"
#include "ecmascript/mujs/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
struct listener {
LIST_HEAD(struct listener);
char *typ;
const char *fun;
};
struct el_window {
struct ecmascript_interpreter *interpreter;
const char *thisval;
LIST_OF(struct listener) listeners;
char *onmessage;
};
struct el_message {
const char *messageObject;
struct el_window *elwin;
};
static
void mjs_window_finalizer(js_State *J, void *val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct el_window *elwin = (struct el_window *)val;
if (elwin) {
struct listener *l;
foreach(l, elwin->listeners) {
mem_free_set(&l->typ, NULL);
}
free_list(elwin->listeners);
mem_free(elwin);
}
}
static void
mjs_window_get_property_closed(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushboolean(J, 0);
}
static void
mjs_window_get_property_parent(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
/* 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. */
js_pushundefined(J);
}
static void
mjs_window_get_property_self(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_copy(J, 0);
}
static void
mjs_window_get_property_status(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushundefined(J);
}
static void
mjs_window_set_property_status(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
js_pushundefined(J);
return;
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
char *text = stracpy(str);
mem_free_set(&vs->doc_view->session->status.window_status, text);
print_screen_status(vs->doc_view->session);
js_pushundefined(J);
}
static void
mjs_window_get_property_top(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct document_view *doc_view;
struct document_view *top_view;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushundefined(J);
return;
}
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) {
js_pushundefined(J);
return;
}
/* 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)) {
js_pushglobal((js_State *)top_view->vs->ecmascript->backend_data);
return;
}
/* 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/ */
js_pushundefined(J);
}
static void
mjs_window_alert(js_State *J)
{
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
assert(interpreter);
struct view_state *vs = interpreter->vs;
const char *str = js_tostring(J, 1);
if (str) {
char *string = stracpy(str);
info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT,
N_("JavaScript Alert"), ALIGN_CENTER, string);
}
js_pushundefined(J);
}
static void
mjs_window_clearTimeout(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
const char *text = js_tostring(J, 1);
int64_t number = atoll(text);
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);
}
js_pushundefined(J);
}
static void
mjs_window_open(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
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_getcontext(J);
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
js_pushundefined(J);
return;
}
/* 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) {
js_pushundefined(J);
return;
}
}
const char *str;
str = js_tostring(J, 1);
if (!str) {
js_pushundefined(J);
return;
}
url = stracpy(str);
if (!url) {
js_pushundefined(J);
return;
}
trim_chars(url, ' ', 0);
url2 = join_urls(doc_view->document->uri, url);
mem_free(url);
if (!url2) {
js_pushundefined(J);
return;
}
if (true) {
frame = js_tostring(J, 2);
if (!frame) {
mem_free(url2);
js_pushundefined(J);
return;
}
}
/* TODO: Support for window naming and perhaps some window features? */
uri = get_uri(url2, URI_NONE);
mem_free(url2);
if (!uri) {
js_pushundefined(J);
return;
}
int ret = 0;
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 = 1;
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 = 1;
} 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 = 1;
} else {
ret = -1;
}
}
end:
done_uri(uri);
if (ret == -1) {
js_pushundefined(J);
return;
}
js_pushboolean(J, ret);
}
static void
mjs_window_setTimeout(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
int timeout = js_toint32(J, 2);
if (timeout <= 0) {
js_pushundefined(J);
return;
}
if (js_isstring(J, 1)) {
const char *code = js_tostring(J, 1);
if (!code) {
js_pushundefined(J);
return;
}
char *code2 = stracpy(code);
if (code2) {
timer_id_T id = ecmascript_set_timeout(interpreter, code2, timeout);
char res[32];
snprintf(res, 31, "%ld", (int64_t)id);
js_pushstring(J, res);
return;
}
} else {
js_copy(J, 1);
const char *handle = js_ref(J);
timer_id_T id = ecmascript_set_timeout2m(J, handle, timeout);
char res[32];
snprintf(res, 31, "%ld", (int64_t)id);
js_pushstring(J, res);
return;
}
js_pushundefined(J);
return;
}
static void
mjs_window_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[window object]");
}
static void
mjs_window_addEventListener(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct el_window *elwin = (struct el_window *)js_touserdata(J, 0, "window");
if (!elwin) {
elwin = (struct el_window *)mem_calloc(1, sizeof(*elwin));
if (!elwin) {
js_error(J, "out of memory");
return;
}
init_list(elwin->listeners);
elwin->interpreter = interpreter;
elwin->thisval = js_ref(J);
js_newuserdata(J, "window", elwin, mjs_window_finalizer);
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
char *method = stracpy(str);
if (!method) {
js_error(J, "out of memory");
return;
}
js_copy(J, 2);
const char *fun = js_ref(J);
struct listener *l;
foreach(l, elwin->listeners) {
if (strcmp(l->typ, method)) {
continue;
}
if (!strcmp(l->fun, fun)) {
mem_free(method);
js_pushundefined(J);
return;
}
}
struct listener *n = (struct listener *)mem_calloc(1, sizeof(*n));
if (n) {
n->typ = method;
n->fun = fun;
add_to_list_end(elwin->listeners, n);
}
js_pushundefined(J);
}
static void
mjs_window_removeEventListener(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct el_window *elwin = (struct el_window *)js_touserdata(J, 0, "window");
if (!elwin) {
js_pushnull(J);
return;
}
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
char *method = stracpy(str);
if (!method) {
js_error(J, "out of memory");
return;
}
js_copy(J, 2);
const char *fun = js_ref(J);
struct listener *l;
foreach(l, elwin->listeners) {
if (strcmp(l->typ, method)) {
continue;
}
if (!strcmp(l->fun, fun)) {
del_from_list(l);
mem_free_set(&l->typ, NULL);
if (l->fun) js_unref(J, l->fun);
mem_free(l);
mem_free(method);
js_pushundefined(J);
return;
}
}
mem_free(method);
js_pushundefined(J);
}
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;
js_State *J = (js_State *)interpreter->backend_data;
struct listener *l;
// TODO parameers for js_pcall
foreach(l, elwin->listeners) {
if (strcmp(l->typ, "message")) {
continue;
}
js_getregistry(J, l->fun); /* retrieve the js function from the registry */
js_getregistry(J, elwin->thisval);
js_pcall(J, 0);
js_pop(J, 1);
}
if (elwin->onmessage) {
js_getregistry(J, elwin->onmessage); /* retrieve the js function from the registry */
js_getregistry(J, mess->messageObject);
js_pcall(J, 0);
js_pop(J, 1);
}
check_for_rerender(interpreter, "window_message");
}
}
static void
mjs_window_postMessage(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct el_window *elwin = (struct el_window *)js_touserdata(J, 0, "window");
const char *str = js_tostring(J, 1);
if (!str) {
js_error(J, "!str");
return;
}
char *data = stracpy(str);
const char *str2 = js_tostring(J, 2);
if (!str2) {
mem_free_if(data);
js_error(J, "!str2");
return;
}
char *targetOrigin = stracpy(str2);
char *source = stracpy("TODO");
mjs_push_messageEvent(J, data, targetOrigin, source);
mem_free_if(data);
mem_free_if(targetOrigin);
mem_free_if(source);
js_pop(J, 1);
const char *val = js_ref(J);
struct el_message *mess = (struct el_message *)mem_calloc(1, sizeof(*mess));
if (!mess) {
js_error(J, "out of memory");
return;
}
mess->messageObject = val;
mess->elwin = elwin;
register_bottom_half(onmessage_run, mess);
js_pushundefined(J);
}
int
mjs_window_init(js_State *J)
{
js_newobject(J);
{
addmethod(J, "addEventListener", mjs_window_addEventListener, 3);
addmethod(J, "alert", mjs_window_alert, 1);
addmethod(J, "clearTimeout", mjs_window_clearTimeout, 1);
addmethod(J, "open", mjs_window_open, 3);
addmethod(J, "postMessage", mjs_window_postMessage, 3);
addmethod(J, "removeEventListener", mjs_window_removeEventListener, 3);
addmethod(J, "setTimeout", mjs_window_setTimeout, 2);
addmethod(J, "toString", mjs_window_toString, 0);
addproperty(J, "closed", mjs_window_get_property_closed, NULL);
addproperty(J, "parent", mjs_window_get_property_parent, NULL);
addproperty(J, "self", mjs_window_get_property_self, NULL);
addproperty(J, "status", mjs_window_get_property_status, mjs_window_set_property_status);
addproperty(J, "top", mjs_window_get_property_top, NULL);
addproperty(J, "window", mjs_window_get_property_self, NULL);
}
js_defglobal(J, "window", JS_DONTENUM);
js_dostring(J, "function alert(text) { return window.alert(text); }\n"
"function clearTimeout(h) { return window.clearTimeout(h); }\n"
"function open(a, b, c) { return window.open(a, b, c); }\n"
"function setTimeout(a, b) { return window.setTimeout(a, b); }\n"
"function toString() { return window.toString(); }\n");
return 0;
}
#endif

File diff suppressed because it is too large Load Diff