mirror of
https://github.com/rkd77/elinks.git
synced 2024-09-06 23:44:43 -04:00
Merge branch 'MessageEvent'
This commit is contained in:
commit
f4257b40fd
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,6 +18,7 @@ elinks
|
|||||||
*.swp
|
*.swp
|
||||||
*.patch
|
*.patch
|
||||||
*.o
|
*.o
|
||||||
|
*.obj
|
||||||
features.log
|
features.log
|
||||||
src/elinks.exe
|
src/elinks.exe
|
||||||
test/server/__pycache__
|
test/server/__pycache__
|
||||||
|
@ -13,7 +13,7 @@ RUN cd /etc/apk && echo https://dl-cdn.alpinelinux.org/alpine/edge/testing >> re
|
|||||||
|
|
||||||
# install
|
# install
|
||||||
# [*] install libraries
|
# [*] install libraries
|
||||||
RUN cd /root && apk add \
|
RUN apk add \
|
||||||
brotli-dev \
|
brotli-dev \
|
||||||
brotli-static \
|
brotli-static \
|
||||||
bzip2-dev \
|
bzip2-dev \
|
||||||
@ -43,7 +43,7 @@ RUN cd /root && apk add \
|
|||||||
xz-static
|
xz-static
|
||||||
|
|
||||||
# [*] libxml++5
|
# [*] libxml++5
|
||||||
RUN cd /root && apk add mm-common libtool xz
|
RUN apk add mm-common libtool upx xz
|
||||||
|
|
||||||
# libxml++5 cd
|
# libxml++5 cd
|
||||||
RUN mkdir /root/tmp; cd /root/tmp; \
|
RUN mkdir /root/tmp; cd /root/tmp; \
|
||||||
|
@ -54,3 +54,7 @@ meson /root/tmp/builddir \
|
|||||||
-Dzstd=true
|
-Dzstd=true
|
||||||
|
|
||||||
meson compile -C /root/tmp/builddir
|
meson compile -C /root/tmp/builddir
|
||||||
|
|
||||||
|
strip /root/tmp/builddir/src/elinks
|
||||||
|
|
||||||
|
upx /root/tmp/builddir/src/elinks
|
||||||
|
@ -54,3 +54,7 @@ meson /root/tmp/builddir_js \
|
|||||||
-Dzstd=true
|
-Dzstd=true
|
||||||
|
|
||||||
meson compile -j $(($(nproc) - 1)) -C /root/tmp/builddir_js
|
meson compile -j $(($(nproc) - 1)) -C /root/tmp/builddir_js
|
||||||
|
|
||||||
|
strip /root/tmp/builddir_js/src/elinks
|
||||||
|
|
||||||
|
upx /root/tmp/builddir_js/src/elinks
|
||||||
|
@ -9,7 +9,7 @@ FROM fedora:37
|
|||||||
|
|
||||||
# prepare system
|
# prepare system
|
||||||
RUN dnf -y update && dnf -y install bash wget \
|
RUN dnf -y update && dnf -y install bash wget \
|
||||||
rsync vim screen git make automake meson unzip cmake patch
|
rsync vim screen git make automake meson unzip cmake patch upx
|
||||||
|
|
||||||
RUN cd /root; wget http://ftp.delorie.com/pub/djgpp/rpms/djcross-gcc-12.2.0/djcross-gcc-12.2.0-1ap.x86_64.rpm ; \
|
RUN cd /root; wget http://ftp.delorie.com/pub/djgpp/rpms/djcross-gcc-12.2.0/djcross-gcc-12.2.0-1ap.x86_64.rpm ; \
|
||||||
wget http://ftp.delorie.com/pub/djgpp/rpms/djcross-gcc-12.2.0/djcross-gcc-c++-12.2.0-1ap.x86_64.rpm ; \
|
wget http://ftp.delorie.com/pub/djgpp/rpms/djcross-gcc-12.2.0/djcross-gcc-c++-12.2.0-1ap.x86_64.rpm ; \
|
||||||
|
@ -59,5 +59,6 @@ meson /tmp/builddir --cross-file cross/linux-djgpp.txt \
|
|||||||
|
|
||||||
meson compile -C /tmp/builddir
|
meson compile -C /tmp/builddir
|
||||||
|
|
||||||
cd /tmp/builddir
|
i586-pc-msdosdjgpp-strip /tmp/builddir/src/elinks.exe
|
||||||
ninja install
|
|
||||||
|
upx /tmp/builddir/src/elinks.exe
|
||||||
|
@ -59,3 +59,7 @@ meson /tmp/builddir2 --cross-file cross/linux-djgpp.txt \
|
|||||||
-Dzstd=false \
|
-Dzstd=false \
|
||||||
|
|
||||||
meson compile -C /tmp/builddir2
|
meson compile -C /tmp/builddir2
|
||||||
|
|
||||||
|
i586-pc-msdosdjgpp-strip /tmp/builddir2/src/elinks.exe
|
||||||
|
|
||||||
|
upx /tmp/builddir2/src/elinks.exe
|
||||||
|
@ -228,12 +228,20 @@ download_dialog_layouter(struct dialog_data *dlg_data)
|
|||||||
mem_free(msg);
|
mem_free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static enum dlg_refresh_code
|
||||||
|
refresh_file_download(struct dialog_data *dlg_data, void *data)
|
||||||
|
{
|
||||||
|
/* Always refresh (until we keep finished downloads) */
|
||||||
|
return are_there_downloads() ? REFRESH_DIALOG : REFRESH_STOP;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
display_download(struct terminal *term, struct file_download *file_download,
|
display_download(struct terminal *term, struct file_download *file_download,
|
||||||
struct session *ses)
|
struct session *ses)
|
||||||
{
|
{
|
||||||
/* [gettext_accelerator_context(display_download)] */
|
/* [gettext_accelerator_context(display_download)] */
|
||||||
struct dialog *dlg;
|
struct dialog *dlg;
|
||||||
|
struct dialog_data *ret;
|
||||||
|
|
||||||
if (!is_in_downloads_list(file_download))
|
if (!is_in_downloads_list(file_download))
|
||||||
return;
|
return;
|
||||||
@ -282,9 +290,12 @@ display_download(struct terminal *term, struct file_download *file_download,
|
|||||||
add_dlg_end(dlg, DOWNLOAD_WIDGETS_COUNT - !!file_download->external_handler);
|
add_dlg_end(dlg, DOWNLOAD_WIDGETS_COUNT - !!file_download->external_handler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
do_dialog(term, dlg, getml(dlg, (void *) NULL));
|
ret = do_dialog(term, dlg, getml(dlg, (void *) NULL));
|
||||||
}
|
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
refresh_dialog(ret, refresh_file_download, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* The download manager */
|
/* The download manager */
|
||||||
|
|
||||||
@ -360,12 +371,6 @@ delete_file_download(struct listbox_item *item, int last)
|
|||||||
register_bottom_half(do_abort_download, file_download);
|
register_bottom_half(do_abort_download, file_download);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum dlg_refresh_code
|
|
||||||
refresh_file_download(struct dialog_data *dlg_data, void *data)
|
|
||||||
{
|
|
||||||
/* Always refresh (until we keep finished downloads) */
|
|
||||||
return are_there_downloads() ? REFRESH_DIALOG : REFRESH_STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: Make it configurable */
|
/* TODO: Make it configurable */
|
||||||
#define DOWNLOAD_METER_WIDTH 15
|
#define DOWNLOAD_METER_WIDTH 15
|
||||||
|
@ -373,19 +373,19 @@ check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text)
|
|||||||
struct cache_entry *cached = document->cached;
|
struct cache_entry *cached = document->cached;
|
||||||
|
|
||||||
if (!strcmp(text, "eval")) {
|
if (!strcmp(text, "eval")) {
|
||||||
if (interpreter->element_offset) {
|
if (interpreter->write_element_offset) {
|
||||||
if (interpreter->writecode.length) {
|
if (interpreter->writecode.length) {
|
||||||
std::map<int, xmlpp::Element *> *mapa = (std::map<int, xmlpp::Element *> *)document->element_map;
|
std::map<int, xmlpp::Element *> *mapa = (std::map<int, xmlpp::Element *> *)document->element_map;
|
||||||
|
|
||||||
if (mapa) {
|
if (mapa) {
|
||||||
auto element = (*mapa).find(interpreter->element_offset);
|
auto element = (*mapa).find(interpreter->write_element_offset);
|
||||||
|
|
||||||
if (element != (*mapa).end()) {
|
if (element != (*mapa).end()) {
|
||||||
xmlpp::Element *el = element->second;
|
xmlpp::Element *el = element->second;
|
||||||
|
|
||||||
const xmlpp::Element *parent = el->get_parent();
|
const xmlpp::Element *parent = el->get_parent();
|
||||||
|
|
||||||
if (!parent || !strcasecmp(parent->get_name().c_str(), "HEAD")) goto fromstart;
|
if (!parent) goto fromstart;
|
||||||
|
|
||||||
xmlpp::ustring text = "<root>";
|
xmlpp::ustring text = "<root>";
|
||||||
text += interpreter->writecode.source;
|
text += interpreter->writecode.source;
|
||||||
@ -408,6 +408,7 @@ check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
interpreter->write_element_offset = 0;
|
||||||
} else {
|
} else {
|
||||||
if (interpreter->writecode.length) {
|
if (interpreter->writecode.length) {
|
||||||
fromstart:
|
fromstart:
|
||||||
|
@ -110,6 +110,7 @@ struct ecmascript_interpreter {
|
|||||||
#endif
|
#endif
|
||||||
bool changed;
|
bool changed;
|
||||||
int element_offset;
|
int element_offset;
|
||||||
|
int write_element_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ecmascript_timeout {
|
struct ecmascript_timeout {
|
||||||
|
@ -4,6 +4,6 @@ INCLUDES += $(MUJS_CFLAGS)
|
|||||||
|
|
||||||
OBJS = attr.obj attributes.obj collection.obj console.obj document.obj element.obj form.obj \
|
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 \
|
forms.obj history.obj implementation.obj input.obj keyboard.obj location.obj \
|
||||||
localstorage.obj navigator.obj nodelist.obj screen.obj unibar.obj window.obj xhr.obj
|
localstorage.obj message.obj navigator.obj nodelist.obj screen.obj unibar.obj window.obj xhr.obj
|
||||||
|
|
||||||
include $(top_srcdir)/Makefile.lib
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
@ -1340,6 +1340,39 @@ mjs_element_getAttributeNode(js_State *J)
|
|||||||
mjs_push_attr(J, attr);
|
mjs_push_attr(J, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_element_getElementsByTagName(js_State *J)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
xmlpp::Element *el = static_cast<xmlpp::Element *>(mjs_getprivate(J, 0));
|
||||||
|
|
||||||
|
if (!el) {
|
||||||
|
js_pushundefined(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *str = js_tostring(J, 1);
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xmlpp::ustring id = str;
|
||||||
|
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
|
||||||
|
xmlpp::ustring xpath = "//";
|
||||||
|
xpath += id;
|
||||||
|
xmlpp::Node::NodeSet *elements = new(std::nothrow) xmlpp::Node::NodeSet;
|
||||||
|
|
||||||
|
if (!elements) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*elements = el->find(xpath);
|
||||||
|
mjs_push_collection(J, elements);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mjs_element_hasAttribute(js_State *J)
|
mjs_element_hasAttribute(js_State *J)
|
||||||
{
|
{
|
||||||
@ -1752,6 +1785,7 @@ mjs_push_element(js_State *J, void *node)
|
|||||||
addmethod(J, "contains", mjs_element_contains, 1);
|
addmethod(J, "contains", mjs_element_contains, 1);
|
||||||
addmethod(J, "getAttribute", mjs_element_getAttribute, 1);
|
addmethod(J, "getAttribute", mjs_element_getAttribute, 1);
|
||||||
addmethod(J, "getAttributeNode", mjs_element_getAttributeNode, 1);
|
addmethod(J, "getAttributeNode", mjs_element_getAttributeNode, 1);
|
||||||
|
addmethod(J, "getElementsByTagName", mjs_element_getElementsByTagName, 1);
|
||||||
addmethod(J, "hasAttribute", mjs_element_hasAttribute, 1);
|
addmethod(J, "hasAttribute", mjs_element_hasAttribute, 1);
|
||||||
addmethod(J, "hasAttributes", mjs_element_hasAttributes, 0);
|
addmethod(J, "hasAttributes", mjs_element_hasAttributes, 0);
|
||||||
addmethod(J, "hasChildNodes", mjs_element_hasChildNodes, 0);
|
addmethod(J, "hasChildNodes", mjs_element_hasChildNodes, 0);
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'history.cpp', 'implementation.cpp',
|
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', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
'input.cpp', 'keyboard.cpp', 'localstorage.cpp', 'location.cpp', 'message.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
||||||
|
177
src/ecmascript/mujs/message.cpp
Normal file
177
src/ecmascript/mujs/message.cpp
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
/* 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>
|
||||||
|
|
||||||
|
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_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event->data = null_or_stracpy(data);
|
||||||
|
event->origin = null_or_stracpy(origin);
|
||||||
|
event->source = null_or_stracpy(source);
|
||||||
|
|
||||||
|
char id[32];
|
||||||
|
|
||||||
|
snprintf(id, "%d", 31, ++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);
|
||||||
|
}
|
8
src/ecmascript/mujs/message.h
Normal file
8
src/ecmascript/mujs/message.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef EL__ECMASCRIPT_MUJS_MESSAGE_H
|
||||||
|
#define EL__ECMASCRIPT_MUJS_MESSAGE_H
|
||||||
|
|
||||||
|
#include <mujs.h>
|
||||||
|
|
||||||
|
void mjs_push_messageEvent(js_State *J, char *data, char *origin, char *source);
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,4 @@
|
|||||||
/* The Quickjs window object implementation. */
|
/* The MuJS window object implementation. */
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -21,6 +21,7 @@
|
|||||||
#include "document/view.h"
|
#include "document/view.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
#include "ecmascript/mujs.h"
|
#include "ecmascript/mujs.h"
|
||||||
|
#include "ecmascript/mujs/message.h"
|
||||||
#include "ecmascript/mujs/window.h"
|
#include "ecmascript/mujs/window.h"
|
||||||
#include "ecmascript/timer.h"
|
#include "ecmascript/timer.h"
|
||||||
#include "intl/libintl.h"
|
#include "intl/libintl.h"
|
||||||
@ -44,6 +45,43 @@
|
|||||||
#include "viewer/text/link.h"
|
#include "viewer/text/link.h"
|
||||||
#include "viewer/text/vs.h"
|
#include "viewer/text/vs.h"
|
||||||
|
|
||||||
|
struct listener {
|
||||||
|
LIST_HEAD(struct listener);
|
||||||
|
char *typ;
|
||||||
|
char *fun;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct el_window {
|
||||||
|
struct ecmascript_interpreter *interpreter;
|
||||||
|
char *thisval;
|
||||||
|
LIST_OF(struct listener) listeners;
|
||||||
|
char *onmessage;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct el_message {
|
||||||
|
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
|
static void
|
||||||
mjs_window_get_property_closed(js_State *J)
|
mjs_window_get_property_closed(js_State *J)
|
||||||
{
|
{
|
||||||
@ -387,14 +425,211 @@ mjs_window_toString(js_State *J)
|
|||||||
js_pushstring(J, "[window object]");
|
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_pushnull(J);
|
||||||
|
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_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char *method = stracpy(str);
|
||||||
|
|
||||||
|
if (!method) {
|
||||||
|
js_pushnull(J);
|
||||||
|
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 ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||||
|
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_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char *method = stracpy(str);
|
||||||
|
|
||||||
|
if (!method) {
|
||||||
|
js_pushnull(J);
|
||||||
|
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 ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||||
|
struct el_window *elwin = (struct el_window *)js_touserdata(J, 0, "window");
|
||||||
|
|
||||||
|
const char *str = js_tostring(J, 1);
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char *data = stracpy(str);
|
||||||
|
|
||||||
|
const char *str2 = js_tostring(J, 2);
|
||||||
|
|
||||||
|
if (!str2) {
|
||||||
|
mem_free_if(data);
|
||||||
|
js_pushnull(J);
|
||||||
|
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);
|
||||||
|
char *val = js_ref(J);
|
||||||
|
|
||||||
|
struct el_message *mess = (struct el_message *)mem_calloc(1, sizeof(*mess));
|
||||||
|
if (!mess) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mess->messageObject = val;
|
||||||
|
mess->elwin = elwin;
|
||||||
|
register_bottom_half(onmessage_run, mess);
|
||||||
|
|
||||||
|
js_pushundefined(J);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mjs_window_init(js_State *J)
|
mjs_window_init(js_State *J)
|
||||||
{
|
{
|
||||||
js_newobject(J);
|
js_newobject(J);
|
||||||
{
|
{
|
||||||
|
addmethod(J, "addEventListener", mjs_window_addEventListener, 3);
|
||||||
addmethod(J, "alert", mjs_window_alert, 1);
|
addmethod(J, "alert", mjs_window_alert, 1);
|
||||||
addmethod(J, "clearTimeout", mjs_window_clearTimeout, 1);
|
addmethod(J, "clearTimeout", mjs_window_clearTimeout, 1);
|
||||||
addmethod(J, "open", mjs_window_open, 3);
|
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, "setTimeout", mjs_window_setTimeout, 2);
|
||||||
addmethod(J, "toString", mjs_window_toString, 0);
|
addmethod(J, "toString", mjs_window_toString, 0);
|
||||||
|
|
||||||
|
@ -3,6 +3,6 @@ include $(top_builddir)/Makefile.config
|
|||||||
|
|
||||||
OBJS = attr.obj attributes.obj collection.obj console.obj document.obj element.obj form.obj \
|
OBJS = attr.obj attributes.obj collection.obj console.obj document.obj element.obj form.obj \
|
||||||
forms.obj heartbeat.obj history.obj implementation.obj input.obj keyboard.obj location.obj \
|
forms.obj heartbeat.obj history.obj implementation.obj input.obj keyboard.obj location.obj \
|
||||||
localstorage.obj navigator.obj nodelist.obj screen.obj unibar.obj window.obj xhr.obj
|
localstorage.obj message.obj navigator.obj nodelist.obj screen.obj unibar.obj window.obj xhr.obj
|
||||||
|
|
||||||
include $(top_srcdir)/Makefile.lib
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
@ -1396,6 +1396,45 @@ js_element_getAttributeNode(JSContext *ctx, JSValueConst this_val, int argc, JSV
|
|||||||
return getAttr(ctx, attr);
|
return getAttr(ctx, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue
|
||||||
|
js_element_getElementsByTagName(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
if (argc != 1) {
|
||||||
|
return JS_FALSE;
|
||||||
|
}
|
||||||
|
xmlpp::Element *el = static_cast<xmlpp::Element *>(js_getopaque(this_val, js_element_class_id));
|
||||||
|
|
||||||
|
if (!el) {
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
const char *str;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
str = JS_ToCStringLen(ctx, &len, argv[0]);
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
xmlpp::ustring id = str;
|
||||||
|
JS_FreeCString(ctx, str);
|
||||||
|
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
|
||||||
|
|
||||||
|
xmlpp::ustring xpath = "//";
|
||||||
|
xpath += id;
|
||||||
|
xmlpp::Node::NodeSet *elements = new(std::nothrow) xmlpp::Node::NodeSet;
|
||||||
|
|
||||||
|
if (!elements) {
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*elements = el->find(xpath);
|
||||||
|
|
||||||
|
return getCollection(ctx, elements);
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue
|
static JSValue
|
||||||
js_element_hasAttribute(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
js_element_hasAttribute(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||||
{
|
{
|
||||||
@ -1883,6 +1922,7 @@ static const JSCFunctionListEntry js_element_proto_funcs[] = {
|
|||||||
JS_CFUNC_DEF("contains", 1, js_element_contains),
|
JS_CFUNC_DEF("contains", 1, js_element_contains),
|
||||||
JS_CFUNC_DEF("getAttribute", 1, js_element_getAttribute),
|
JS_CFUNC_DEF("getAttribute", 1, js_element_getAttribute),
|
||||||
JS_CFUNC_DEF("getAttributeNode",1, js_element_getAttributeNode),
|
JS_CFUNC_DEF("getAttributeNode",1, js_element_getAttributeNode),
|
||||||
|
JS_CFUNC_DEF("getElementsByTagName", 1, js_element_getElementsByTagName),
|
||||||
JS_CFUNC_DEF("hasAttribute", 1, js_element_hasAttribute),
|
JS_CFUNC_DEF("hasAttribute", 1, js_element_hasAttribute),
|
||||||
JS_CFUNC_DEF("hasAttributes", 0, js_element_hasAttributes),
|
JS_CFUNC_DEF("hasAttributes", 0, js_element_hasAttributes),
|
||||||
JS_CFUNC_DEF("hasChildNodes", 0, js_element_hasChildNodes),
|
JS_CFUNC_DEF("hasChildNodes", 0, js_element_hasChildNodes),
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp',
|
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp',
|
||||||
'input.cpp', 'keyboard.cpp', 'localstorage.cpp', 'location.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
'input.cpp', 'keyboard.cpp', 'localstorage.cpp', 'location.cpp', 'message.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
||||||
|
240
src/ecmascript/quickjs/message.cpp
Normal file
240
src/ecmascript/quickjs/message.cpp
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
/* The QuickJS MessageEvent object implementation. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "elinks.h"
|
||||||
|
|
||||||
|
#include "bfu/dialog.h"
|
||||||
|
#include "cache/cache.h"
|
||||||
|
#include "cookies/cookies.h"
|
||||||
|
#include "dialogs/menu.h"
|
||||||
|
#include "dialogs/status.h"
|
||||||
|
#include "document/html/frames.h"
|
||||||
|
#include "document/document.h"
|
||||||
|
#include "document/forms.h"
|
||||||
|
#include "document/view.h"
|
||||||
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/quickjs.h"
|
||||||
|
#include "ecmascript/quickjs/heartbeat.h"
|
||||||
|
#include "ecmascript/quickjs/message.h"
|
||||||
|
#include "ecmascript/timer.h"
|
||||||
|
#include "intl/libintl.h"
|
||||||
|
#include "main/select.h"
|
||||||
|
#include "main/timer.h"
|
||||||
|
#include "network/connection.h"
|
||||||
|
#include "osdep/newwin.h"
|
||||||
|
#include "osdep/sysname.h"
|
||||||
|
#include "protocol/http/http.h"
|
||||||
|
#include "protocol/uri.h"
|
||||||
|
#include "session/download.h"
|
||||||
|
#include "session/history.h"
|
||||||
|
#include "session/location.h"
|
||||||
|
#include "session/session.h"
|
||||||
|
#include "session/task.h"
|
||||||
|
#include "terminal/tab.h"
|
||||||
|
#include "terminal/terminal.h"
|
||||||
|
#include "util/conv.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
#include "viewer/text/draw.h"
|
||||||
|
#include "viewer/text/form.h"
|
||||||
|
#include "viewer/text/link.h"
|
||||||
|
#include "viewer/text/vs.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
#include <utility>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
|
static JSClassID js_messageEvent_class_id;
|
||||||
|
|
||||||
|
static JSValue js_messageEvent_get_property_data(JSContext *cx, JSValueConst this_val);
|
||||||
|
static JSValue js_messageEvent_get_property_lastEventId(JSContext *cx, JSValueConst this_val);
|
||||||
|
static JSValue js_messageEvent_get_property_origin(JSContext *cx, JSValueConst this_val);
|
||||||
|
static JSValue js_messageEvent_get_property_source(JSContext *cx, JSValueConst this_val);
|
||||||
|
|
||||||
|
struct message_event {
|
||||||
|
char *data;
|
||||||
|
char *lastEventId;
|
||||||
|
char *origin;
|
||||||
|
char *source;
|
||||||
|
};
|
||||||
|
|
||||||
|
static
|
||||||
|
void js_messageEvent_finalizer(JSRuntime *rt, JSValue val)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct message_event *event = (struct message_event *)JS_GetOpaque(val, js_messageEvent_class_id);
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
mem_free_if(event->data);
|
||||||
|
mem_free_if(event->lastEventId);
|
||||||
|
mem_free_if(event->origin);
|
||||||
|
mem_free_if(event->source);
|
||||||
|
mem_free(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSClassDef js_messageEvent_class = {
|
||||||
|
"MessageEvent",
|
||||||
|
js_messageEvent_finalizer
|
||||||
|
};
|
||||||
|
|
||||||
|
static JSValue
|
||||||
|
js_messageEvent_ctor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JSValue obj = JS_UNDEFINED;
|
||||||
|
JSValue proto;
|
||||||
|
|
||||||
|
struct message_event *event = (struct message_event *)mem_calloc(1, sizeof(*event));
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* using new_target to get the prototype is necessary when the
|
||||||
|
class is extended. */
|
||||||
|
proto = JS_GetPropertyStr(ctx, new_target, "prototype");
|
||||||
|
|
||||||
|
if (JS_IsException(proto)) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
obj = JS_NewObjectProtoClass(ctx, proto, js_messageEvent_class_id);
|
||||||
|
JS_FreeValue(ctx, proto);
|
||||||
|
|
||||||
|
if (JS_IsException(obj)) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
JS_SetOpaque(obj, event);
|
||||||
|
|
||||||
|
RETURN_JS(obj);
|
||||||
|
|
||||||
|
fail:
|
||||||
|
JS_FreeValue(ctx, obj);
|
||||||
|
mem_free(event);
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const JSCFunctionListEntry js_messageEvent_proto_funcs[] = {
|
||||||
|
JS_CGETSET_DEF("data", js_messageEvent_get_property_data, nullptr),
|
||||||
|
JS_CGETSET_DEF("lastEventId", js_messageEvent_get_property_lastEventId, nullptr),
|
||||||
|
JS_CGETSET_DEF("origin", js_messageEvent_get_property_origin, nullptr),
|
||||||
|
JS_CGETSET_DEF("source", js_messageEvent_get_property_source, nullptr)
|
||||||
|
};
|
||||||
|
|
||||||
|
static JSValue
|
||||||
|
js_messageEvent_get_property_data(JSContext *ctx, JSValueConst this_val)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct message_event *event = static_cast<struct message_event *>(JS_GetOpaque(this_val, js_messageEvent_class_id));
|
||||||
|
|
||||||
|
if (!event || !event->data) {
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
JSValue r = JS_NewString(ctx, event->data);
|
||||||
|
|
||||||
|
RETURN_JS(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue
|
||||||
|
js_messageEvent_get_property_lastEventId(JSContext *ctx, JSValueConst this_val)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct message_event *event = static_cast<struct message_event *>(JS_GetOpaque(this_val, js_messageEvent_class_id));
|
||||||
|
|
||||||
|
if (!event || !event->lastEventId) {
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
JSValue r = JS_NewString(ctx, event->lastEventId);
|
||||||
|
|
||||||
|
RETURN_JS(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue
|
||||||
|
js_messageEvent_get_property_origin(JSContext *ctx, JSValueConst this_val)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct message_event *event = static_cast<struct message_event *>(JS_GetOpaque(this_val, js_messageEvent_class_id));
|
||||||
|
|
||||||
|
if (!event || !event->origin) {
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
JSValue r = JS_NewString(ctx, event->origin);
|
||||||
|
|
||||||
|
RETURN_JS(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue
|
||||||
|
js_messageEvent_get_property_source(JSContext *ctx, JSValueConst this_val)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct message_event *event = static_cast<struct message_event *>(JS_GetOpaque(this_val, js_messageEvent_class_id));
|
||||||
|
|
||||||
|
if (!event || !event->source) {
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
JSValue r = JS_NewString(ctx, event->source);
|
||||||
|
|
||||||
|
RETURN_JS(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lastEventId;
|
||||||
|
|
||||||
|
JSValue
|
||||||
|
get_messageEvent(JSContext *ctx, char *data, char *origin, char *source)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
static int initialized;
|
||||||
|
/* create the element class */
|
||||||
|
if (!initialized) {
|
||||||
|
JS_NewClassID(&js_messageEvent_class_id);
|
||||||
|
JS_NewClass(JS_GetRuntime(ctx), js_messageEvent_class_id, &js_messageEvent_class);
|
||||||
|
initialized = 1;
|
||||||
|
}
|
||||||
|
struct message_event *event = (struct message_event *)mem_calloc(1, sizeof(*event));
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
event->data = null_or_stracpy(data);
|
||||||
|
event->origin = null_or_stracpy(origin);
|
||||||
|
event->source = null_or_stracpy(source);
|
||||||
|
|
||||||
|
char id[32];
|
||||||
|
|
||||||
|
snprintf(id, "%d", 31, ++lastEventId);
|
||||||
|
event->lastEventId = stracpy(id);
|
||||||
|
|
||||||
|
JSValue event_obj = JS_NewObjectClass(ctx, js_messageEvent_class_id);
|
||||||
|
JS_SetPropertyFunctionList(ctx, event_obj, js_messageEvent_proto_funcs, countof(js_messageEvent_proto_funcs));
|
||||||
|
JS_SetClassProto(ctx, js_messageEvent_class_id, event_obj);
|
||||||
|
JS_SetOpaque(event_obj, event);
|
||||||
|
|
||||||
|
JSValue rr = JS_DupValue(ctx, event_obj);
|
||||||
|
RETURN_JS(rr);
|
||||||
|
}
|
8
src/ecmascript/quickjs/message.h
Normal file
8
src/ecmascript/quickjs/message.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef EL__ECMASCRIPT_QUICKJS_MESSAGE_H
|
||||||
|
#define EL__ECMASCRIPT_QUICKJS_MESSAGE_H
|
||||||
|
|
||||||
|
#include <quickjs/quickjs.h>
|
||||||
|
|
||||||
|
JSValue get_messageEvent(JSContext *ctx, char *data, char *origin, char *source);
|
||||||
|
|
||||||
|
#endif
|
@ -21,6 +21,8 @@
|
|||||||
#include "document/view.h"
|
#include "document/view.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
#include "ecmascript/quickjs.h"
|
#include "ecmascript/quickjs.h"
|
||||||
|
#include "ecmascript/quickjs/heartbeat.h"
|
||||||
|
#include "ecmascript/quickjs/message.h"
|
||||||
#include "ecmascript/quickjs/window.h"
|
#include "ecmascript/quickjs/window.h"
|
||||||
#include "ecmascript/timer.h"
|
#include "ecmascript/timer.h"
|
||||||
#include "intl/libintl.h"
|
#include "intl/libintl.h"
|
||||||
@ -48,6 +50,43 @@
|
|||||||
|
|
||||||
static JSClassID js_window_class_id;
|
static JSClassID js_window_class_id;
|
||||||
|
|
||||||
|
struct listener {
|
||||||
|
LIST_HEAD(struct listener);
|
||||||
|
char *typ;
|
||||||
|
JSValue fun;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct el_window {
|
||||||
|
struct ecmascript_interpreter *interpreter;
|
||||||
|
JSValue thisval;
|
||||||
|
LIST_OF(struct listener) listeners;
|
||||||
|
JSValue onmessage;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct el_message {
|
||||||
|
JSValue messageObject;
|
||||||
|
struct el_window *elwin;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
js_window_finalize(JSRuntime *rt, JSValue val)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct el_window *elwin = (struct el_window *)JS_GetOpaque(val, js_window_class_id);
|
||||||
|
|
||||||
|
if (elwin) {
|
||||||
|
struct listener *l;
|
||||||
|
|
||||||
|
foreach(l, elwin->listeners) {
|
||||||
|
mem_free_set(&l->typ, NULL);
|
||||||
|
}
|
||||||
|
free_list(elwin->listeners);
|
||||||
|
mem_free(elwin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* @window_funcs{"open"} */
|
/* @window_funcs{"open"} */
|
||||||
JSValue
|
JSValue
|
||||||
js_window_open(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
js_window_open(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||||
@ -422,6 +461,208 @@ js_window_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst
|
|||||||
return JS_NewString(ctx, "[window object]");
|
return JS_NewString(ctx, "[window object]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue
|
||||||
|
js_window_addEventListener(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||||
|
struct el_window *elwin = (struct el_window *)(JS_GetOpaque(this_val, js_window_class_id));
|
||||||
|
|
||||||
|
if (!elwin) {
|
||||||
|
elwin = (struct el_window *)mem_calloc(1, sizeof(*elwin));
|
||||||
|
|
||||||
|
if (!elwin) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
init_list(elwin->listeners);
|
||||||
|
elwin->interpreter = interpreter;
|
||||||
|
elwin->thisval = JS_DupValue(ctx, this_val);
|
||||||
|
JS_SetOpaque(this_val, elwin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
const char *str;
|
||||||
|
size_t len;
|
||||||
|
str = JS_ToCStringLen(ctx, &len, argv[0]);
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
char *method = stracpy(str);
|
||||||
|
JS_FreeCString(ctx, str);
|
||||||
|
|
||||||
|
if (!method) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSValue fun = argv[1];
|
||||||
|
struct listener *l;
|
||||||
|
|
||||||
|
foreach(l, elwin->listeners) {
|
||||||
|
if (strcmp(l->typ, method)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (JS_VALUE_GET_PTR(l->fun) == JS_VALUE_GET_PTR(fun)) {
|
||||||
|
mem_free(method);
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
struct listener *n = (struct listener *)mem_calloc(1, sizeof(*n));
|
||||||
|
|
||||||
|
if (n) {
|
||||||
|
n->typ = method;
|
||||||
|
n->fun = JS_DupValue(ctx, argv[1]);
|
||||||
|
add_to_list_end(elwin->listeners, n);
|
||||||
|
}
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue
|
||||||
|
js_window_removeEventListener(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||||
|
struct el_window *elwin = (struct el_window *)(JS_GetOpaque(this_val, js_window_class_id));
|
||||||
|
|
||||||
|
if (!elwin) {
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
const char *str;
|
||||||
|
size_t len;
|
||||||
|
str = JS_ToCStringLen(ctx, &len, argv[0]);
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
char *method = stracpy(str);
|
||||||
|
JS_FreeCString(ctx, str);
|
||||||
|
|
||||||
|
if (!method) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
JSValue fun = argv[1];
|
||||||
|
struct listener *l;
|
||||||
|
|
||||||
|
foreach(l, elwin->listeners) {
|
||||||
|
if (strcmp(l->typ, method)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (JS_VALUE_GET_PTR(l->fun) == JS_VALUE_GET_PTR(fun)) {
|
||||||
|
del_from_list(l);
|
||||||
|
mem_free_set(&l->typ, NULL);
|
||||||
|
mem_free(l);
|
||||||
|
mem_free(method);
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mem_free(method);
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
onmessage_run(void *data)
|
||||||
|
{
|
||||||
|
struct el_message *mess = (struct el_message *)data;
|
||||||
|
|
||||||
|
if (mess) {
|
||||||
|
struct el_window *elwin = mess->elwin;
|
||||||
|
|
||||||
|
if (!elwin) {
|
||||||
|
mem_free(mess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ecmascript_interpreter *interpreter = elwin->interpreter;
|
||||||
|
JSContext *ctx = (JSContext *)interpreter->backend_data;
|
||||||
|
interpreter->heartbeat = add_heartbeat(interpreter);
|
||||||
|
|
||||||
|
struct listener *l;
|
||||||
|
|
||||||
|
foreach(l, elwin->listeners) {
|
||||||
|
if (strcmp(l->typ, "message")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSValue func = JS_DupValue(ctx, l->fun);
|
||||||
|
JSValue arg = JS_DupValue(ctx, mess->messageObject);
|
||||||
|
JSValue ret = JS_Call(ctx, func, elwin->thisval, 1, (JSValueConst *) &arg);
|
||||||
|
JS_FreeValue(ctx, ret);
|
||||||
|
JS_FreeValue(ctx, func);
|
||||||
|
JS_FreeValue(ctx, arg);
|
||||||
|
}
|
||||||
|
if (JS_IsFunction(ctx, elwin->onmessage)) {
|
||||||
|
JSValue func = JS_DupValue(ctx, elwin->onmessage);
|
||||||
|
JSValue arg = JS_DupValue(ctx, mess->messageObject);
|
||||||
|
JSValue ret = JS_Call(ctx, func, elwin->thisval, 1, (JSValueConst *) &arg);
|
||||||
|
JS_FreeValue(ctx, ret);
|
||||||
|
JS_FreeValue(ctx, func);
|
||||||
|
JS_FreeValue(ctx, arg);
|
||||||
|
}
|
||||||
|
done_heartbeat(interpreter->heartbeat);
|
||||||
|
check_for_rerender(interpreter, "window_message");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue
|
||||||
|
js_window_postMessage(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||||
|
struct el_window *elwin = (struct el_window *)(JS_GetOpaque(this_val, js_window_class_id));
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
const char *str;
|
||||||
|
size_t len;
|
||||||
|
str = JS_ToCStringLen(ctx, &len, argv[0]);
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
char *data = stracpy(str);
|
||||||
|
JS_FreeCString(ctx, str);
|
||||||
|
|
||||||
|
str = JS_ToCStringLen(ctx, &len, argv[1]);
|
||||||
|
if (!str) {
|
||||||
|
mem_free_if(data);
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
char *targetOrigin = stracpy(str);
|
||||||
|
JS_FreeCString(ctx, str);
|
||||||
|
char *source = stracpy("TODO");
|
||||||
|
|
||||||
|
JSValue val = get_messageEvent(ctx, data, targetOrigin, source);
|
||||||
|
|
||||||
|
mem_free_if(data);
|
||||||
|
mem_free_if(targetOrigin);
|
||||||
|
mem_free_if(source);
|
||||||
|
|
||||||
|
if (JS_IsNull(val) || !elwin) {
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
struct el_message *mess = (struct el_message *)mem_calloc(1, sizeof(*mess));
|
||||||
|
if (!mess) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
mess->messageObject = JS_DupValue(ctx, val);
|
||||||
|
mess->elwin = elwin;
|
||||||
|
register_bottom_half(onmessage_run, mess);
|
||||||
|
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_window_proto_funcs[] = {
|
static const JSCFunctionListEntry js_window_proto_funcs[] = {
|
||||||
JS_CGETSET_DEF("closed", js_window_get_property_closed, nullptr),
|
JS_CGETSET_DEF("closed", js_window_get_property_closed, nullptr),
|
||||||
JS_CGETSET_DEF("parent", js_window_get_property_parent, nullptr),
|
JS_CGETSET_DEF("parent", js_window_get_property_parent, nullptr),
|
||||||
@ -429,15 +670,19 @@ static const JSCFunctionListEntry js_window_proto_funcs[] = {
|
|||||||
JS_CGETSET_DEF("status", js_window_get_property_status, js_window_set_property_status),
|
JS_CGETSET_DEF("status", js_window_get_property_status, js_window_set_property_status),
|
||||||
JS_CGETSET_DEF("top", js_window_get_property_top, nullptr),
|
JS_CGETSET_DEF("top", js_window_get_property_top, nullptr),
|
||||||
JS_CGETSET_DEF("window", js_window_get_property_self, nullptr),
|
JS_CGETSET_DEF("window", js_window_get_property_self, nullptr),
|
||||||
|
JS_CFUNC_DEF("addEventListener", js_window_addEventListener, 3),
|
||||||
JS_CFUNC_DEF("alert", 1, js_window_alert),
|
JS_CFUNC_DEF("alert", 1, js_window_alert),
|
||||||
JS_CFUNC_DEF("clearTimeout", 1, js_window_clearTimeout),
|
JS_CFUNC_DEF("clearTimeout", 1, js_window_clearTimeout),
|
||||||
JS_CFUNC_DEF("open", 3, js_window_open),
|
JS_CFUNC_DEF("open", 3, js_window_open),
|
||||||
|
JS_CFUNC_DEF("postMessage", js_window_postMessage, 3),
|
||||||
|
JS_CFUNC_DEF("removeEventListener", js_window_removeEventListener, 3),
|
||||||
JS_CFUNC_DEF("setTimeout", 2, js_window_setTimeout),
|
JS_CFUNC_DEF("setTimeout", 2, js_window_setTimeout),
|
||||||
JS_CFUNC_DEF("toString", 0, js_window_toString)
|
JS_CFUNC_DEF("toString", 0, js_window_toString)
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSClassDef js_window_class = {
|
static JSClassDef js_window_class = {
|
||||||
"window",
|
"window",
|
||||||
|
js_window_finalize
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -3,6 +3,6 @@ include $(top_builddir)/Makefile.config
|
|||||||
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||||
|
|
||||||
OBJS = attr.obj attributes.obj collection.obj console.obj document.obj element.obj form.obj forms.obj heartbeat.obj history.obj implementation.obj input.obj \
|
OBJS = attr.obj attributes.obj collection.obj console.obj document.obj element.obj form.obj forms.obj heartbeat.obj history.obj implementation.obj input.obj \
|
||||||
keyboard.obj location.obj localstorage.obj navigator.obj nodelist.obj screen.obj unibar.obj window.obj xhr.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
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
@ -1307,6 +1307,7 @@ document_write_do(JSContext *ctx, unsigned int argc, JS::Value *rval, int newlin
|
|||||||
|
|
||||||
if (argc >= 1)
|
if (argc >= 1)
|
||||||
{
|
{
|
||||||
|
interpreter->write_element_offset = interpreter->element_offset;
|
||||||
for (unsigned int i = 0; i < argc; ++i)
|
for (unsigned int i = 0; i < argc; ++i)
|
||||||
{
|
{
|
||||||
char *str = jsval_to_string(ctx, args[i]);
|
char *str = jsval_to_string(ctx, args[i]);
|
||||||
|
@ -2331,6 +2331,7 @@ static bool element_closest(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
|||||||
static bool element_contains(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_contains(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool element_getAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_getAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool element_getAttributeNode(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_getAttributeNode(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool element_getElementsByTagName(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool element_hasAttributes(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_hasAttributes(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool element_hasChildNodes(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_hasChildNodes(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
@ -2354,6 +2355,7 @@ const spidermonkeyFunctionSpec element_funcs[] = {
|
|||||||
{ "contains", element_contains, 1 },
|
{ "contains", element_contains, 1 },
|
||||||
{ "getAttribute", element_getAttribute, 1 },
|
{ "getAttribute", element_getAttribute, 1 },
|
||||||
{ "getAttributeNode", element_getAttributeNode, 1 },
|
{ "getAttributeNode", element_getAttributeNode, 1 },
|
||||||
|
{ "getElementsByTagName", element_getElementsByTagName, 1 },
|
||||||
{ "hasAttribute", element_hasAttribute, 1 },
|
{ "hasAttribute", element_hasAttribute, 1 },
|
||||||
{ "hasAttributes", element_hasAttributes, 0 },
|
{ "hasAttributes", element_hasAttributes, 0 },
|
||||||
{ "hasChildNodes", element_hasChildNodes, 0 },
|
{ "hasChildNodes", element_hasChildNodes, 0 },
|
||||||
@ -2880,6 +2882,50 @@ element_getAttributeNode(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
element_getElementsByTagName(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
|
if (argc != 1) {
|
||||||
|
args.rval().setBoolean(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
xmlpp::Element *el = JS::GetMaybePtrFromReservedSlot<xmlpp::Element>(hobj, 0);
|
||||||
|
|
||||||
|
struct string idstr;
|
||||||
|
|
||||||
|
if (!init_string(&idstr)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
jshandle_value_to_char_string(&idstr, ctx, args[0]);
|
||||||
|
xmlpp::ustring id = idstr.source;
|
||||||
|
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
|
||||||
|
|
||||||
|
xmlpp::ustring xpath = "//";
|
||||||
|
xpath += id;
|
||||||
|
|
||||||
|
done_string(&idstr);
|
||||||
|
|
||||||
|
xmlpp::Node::NodeSet *elements = new xmlpp::Node::NodeSet;
|
||||||
|
|
||||||
|
*elements = el->find(xpath);
|
||||||
|
|
||||||
|
JSObject *elem = getCollection(ctx, elements);
|
||||||
|
|
||||||
|
if (elem) {
|
||||||
|
args.rval().setObject(*elem);
|
||||||
|
} else {
|
||||||
|
args.rval().setNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
#INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||||
|
|
||||||
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp', 'input.cpp',
|
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp', 'input.cpp',
|
||||||
'keyboard.cpp', 'location.cpp', 'localstorage.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
'keyboard.cpp', 'location.cpp', 'localstorage.cpp', 'message.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
||||||
|
309
src/ecmascript/spidermonkey/message.cpp
Normal file
309
src/ecmascript/spidermonkey/message.cpp
Normal file
@ -0,0 +1,309 @@
|
|||||||
|
/* The SpiderMonkey MessageEvent object implementation. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "elinks.h"
|
||||||
|
|
||||||
|
#include "ecmascript/spidermonkey/util.h"
|
||||||
|
#include <js/BigInt.h>
|
||||||
|
#include <js/Conversions.h>
|
||||||
|
|
||||||
|
#include "bfu/dialog.h"
|
||||||
|
#include "cache/cache.h"
|
||||||
|
#include "cookies/cookies.h"
|
||||||
|
#include "dialogs/menu.h"
|
||||||
|
#include "dialogs/status.h"
|
||||||
|
#include "document/html/frames.h"
|
||||||
|
#include "document/document.h"
|
||||||
|
#include "document/forms.h"
|
||||||
|
#include "document/view.h"
|
||||||
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/spidermonkey.h"
|
||||||
|
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||||
|
#include "ecmascript/spidermonkey/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>
|
||||||
|
|
||||||
|
|
||||||
|
static bool messageEvent_get_property_data(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool messageEvent_get_property_lastEventId(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool messageEvent_get_property_origin(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool messageEvent_get_property_source(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
|
struct message_event {
|
||||||
|
char *data;
|
||||||
|
char *lastEventId;
|
||||||
|
char *origin;
|
||||||
|
char *source;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
messageEvent_finalize(JS::GCContext *op, JSObject *obj)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct message_event *event = JS::GetMaybePtrFromReservedSlot<struct message_event>(obj, 0);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JSClassOps messageEvent_ops = {
|
||||||
|
nullptr, // addProperty
|
||||||
|
nullptr, // deleteProperty
|
||||||
|
nullptr, // enumerate
|
||||||
|
nullptr, // newEnumerate
|
||||||
|
nullptr, // resolve
|
||||||
|
nullptr, // mayResolve
|
||||||
|
messageEvent_finalize, // finalize
|
||||||
|
nullptr, // call
|
||||||
|
nullptr, // construct
|
||||||
|
JS_GlobalObjectTraceHook // trace
|
||||||
|
};
|
||||||
|
|
||||||
|
JSClass messageEvent_class = {
|
||||||
|
"MessageEvent",
|
||||||
|
JSCLASS_HAS_RESERVED_SLOTS(1),
|
||||||
|
&messageEvent_ops
|
||||||
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
messageEvent_constructor(JSContext* ctx, unsigned argc, JS::Value* vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject newObj(ctx, JS_NewObjectForConstructor(ctx, &messageEvent_class, args));
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
|
||||||
|
if (!newObj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct message_event *event = (struct message_event *)mem_calloc(1, sizeof(*event));
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::SetReservedSlot(newObj, 0, JS::PrivateValue(event));
|
||||||
|
args.rval().setObject(*newObj);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSPropertySpec messageEvent_props[] = {
|
||||||
|
JS_PSG("data", messageEvent_get_property_data, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("lastEventId", messageEvent_get_property_lastEventId, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("origin", messageEvent_get_property_origin, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("source", messageEvent_get_property_source, JSPROP_ENUMERATE),
|
||||||
|
JS_PS_END
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool
|
||||||
|
messageEvent_get_property_data(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
struct message_event *event = JS::GetMaybePtrFromReservedSlot<struct message_event>(hobj, 0);
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event->data) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, event->data));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
messageEvent_get_property_lastEventId(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
struct message_event *event = JS::GetMaybePtrFromReservedSlot<struct message_event>(hobj, 0);
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event->lastEventId) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, event->lastEventId));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
messageEvent_get_property_origin(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
struct message_event *event = JS::GetMaybePtrFromReservedSlot<struct message_event>(hobj, 0);
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event->origin) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, event->origin));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
messageEvent_get_property_source(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
struct message_event *event = JS::GetMaybePtrFromReservedSlot<struct message_event>(hobj, 0);
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO proper type
|
||||||
|
if (!event->source) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, event->source));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lastEventId;
|
||||||
|
|
||||||
|
JSObject *
|
||||||
|
get_messageEvent(JSContext *ctx, char *data, char *origin, char *source)
|
||||||
|
{
|
||||||
|
JSObject *e = JS_NewObject(ctx, &messageEvent_class);
|
||||||
|
|
||||||
|
if (!e) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS::RootedObject r_event(ctx, e);
|
||||||
|
JS_DefineProperties(ctx, r_event, (JSPropertySpec *) messageEvent_props);
|
||||||
|
|
||||||
|
struct message_event *event = (struct message_event *)mem_calloc(1, sizeof(*event));
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
event->data = null_or_stracpy(data);
|
||||||
|
event->origin = null_or_stracpy(origin);
|
||||||
|
event->source = null_or_stracpy(source);
|
||||||
|
|
||||||
|
char id[32];
|
||||||
|
|
||||||
|
snprintf(id, "%d", 31, ++lastEventId);
|
||||||
|
event->lastEventId = stracpy(id);
|
||||||
|
JS::SetReservedSlot(e, 0, JS::PrivateValue(event));
|
||||||
|
|
||||||
|
return e;
|
||||||
|
}
|
12
src/ecmascript/spidermonkey/message.h
Normal file
12
src/ecmascript/spidermonkey/message.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef EL__ECMASCRIPT_SPIDERMONKEY_MESSAGE_H
|
||||||
|
#define EL__ECMASCRIPT_SPIDERMONKEY_MESSAGE_H
|
||||||
|
|
||||||
|
#include "ecmascript/spidermonkey/util.h"
|
||||||
|
|
||||||
|
extern JSClass messageEvent_class;
|
||||||
|
extern JSPropertySpec messageEvent_props[];
|
||||||
|
bool messageEvent_constructor(JSContext* ctx, unsigned argc, JS::Value* vp);
|
||||||
|
|
||||||
|
JSObject *get_messageEvent(JSContext *ctx, char *data, char *origin, char *source);
|
||||||
|
|
||||||
|
#endif
|
@ -24,6 +24,8 @@
|
|||||||
#include "document/forms.h"
|
#include "document/forms.h"
|
||||||
#include "document/view.h"
|
#include "document/view.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||||
|
#include "ecmascript/spidermonkey/message.h"
|
||||||
#include "ecmascript/spidermonkey/window.h"
|
#include "ecmascript/spidermonkey/window.h"
|
||||||
#include "ecmascript/timer.h"
|
#include "ecmascript/timer.h"
|
||||||
#include "intl/libintl.h"
|
#include "intl/libintl.h"
|
||||||
@ -55,14 +57,42 @@ static bool window_get_property_status(JSContext *ctx, unsigned int argc, JS::Va
|
|||||||
static bool window_set_property_status(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool window_set_property_status(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool window_get_property_top(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool window_get_property_top(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
|
struct listener {
|
||||||
|
LIST_HEAD(struct listener);
|
||||||
|
char *typ;
|
||||||
|
JS::RootedValue fun;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct el_window {
|
||||||
|
struct ecmascript_interpreter *interpreter;
|
||||||
|
JS::RootedObject thisval;
|
||||||
|
LIST_OF(struct listener) listeners;
|
||||||
|
JS::RootedValue onmessage;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct el_message {
|
||||||
|
JS::RootedObject messageObject;
|
||||||
|
struct el_window *elwin;
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_finalize(JS::GCContext *op, JSObject *obj)
|
window_finalize(JS::GCContext *op, JSObject *obj)
|
||||||
{
|
{
|
||||||
#ifdef ECMASCRIPT_DEBUG
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
}
|
struct el_window *elwin = JS::GetMaybePtrFromReservedSlot<struct el_window>(obj, 0);
|
||||||
|
|
||||||
|
if (elwin) {
|
||||||
|
struct listener *l;
|
||||||
|
|
||||||
|
foreach(l, elwin->listeners) {
|
||||||
|
mem_free_set(&l->typ, NULL);
|
||||||
|
}
|
||||||
|
free_list(elwin->listeners);
|
||||||
|
mem_free(elwin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JSClassOps window_ops = {
|
JSClassOps window_ops = {
|
||||||
nullptr, // addProperty
|
nullptr, // addProperty
|
||||||
@ -139,19 +169,226 @@ find_child_frame(struct document_view *doc_view, struct frame_desc *tframe)
|
|||||||
|
|
||||||
void location_goto(struct document_view *doc_view, char *url);
|
void location_goto(struct document_view *doc_view, char *url);
|
||||||
|
|
||||||
|
static bool window_addEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool window_alert(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool window_alert(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool window_clearTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool window_clearTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool window_open(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool window_open(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool window_postMessage(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool window_removeEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
|
||||||
const spidermonkeyFunctionSpec window_funcs[] = {
|
const spidermonkeyFunctionSpec window_funcs[] = {
|
||||||
|
{ "addEventListener", window_addEventListener, 3 },
|
||||||
{ "alert", window_alert, 1 },
|
{ "alert", window_alert, 1 },
|
||||||
{ "clearTimeout", window_clearTimeout, 1 },
|
{ "clearTimeout", window_clearTimeout, 1 },
|
||||||
{ "open", window_open, 3 },
|
{ "open", window_open, 3 },
|
||||||
|
{ "postMessage", window_postMessage, 3 },
|
||||||
|
{ "removeEventListener", window_removeEventListener, 3 },
|
||||||
{ "setTimeout", window_setTimeout, 2 },
|
{ "setTimeout", window_setTimeout, 2 },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
onmessage_run(void *data)
|
||||||
|
{
|
||||||
|
struct el_message *mess = (struct el_message *)data;
|
||||||
|
|
||||||
|
if (mess) {
|
||||||
|
struct el_window *elwin = mess->elwin;
|
||||||
|
|
||||||
|
if (!elwin) {
|
||||||
|
mem_free(mess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ecmascript_interpreter *interpreter = elwin->interpreter;
|
||||||
|
JSContext *ctx = (JSContext *)interpreter->backend_data;
|
||||||
|
JS::Realm *comp = JS::EnterRealm(ctx, (JSObject *)interpreter->ac);
|
||||||
|
JS::RootedValue r_val(ctx);
|
||||||
|
interpreter->heartbeat = add_heartbeat(interpreter);
|
||||||
|
|
||||||
|
JS::RootedValueVector argv(ctx);
|
||||||
|
if (!argv.resize(1)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
argv[0].setObject(*(mess->messageObject));
|
||||||
|
|
||||||
|
struct listener *l;
|
||||||
|
|
||||||
|
foreach(l, elwin->listeners) {
|
||||||
|
if (strcmp(l->typ, "message")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JS_CallFunctionValue(ctx, elwin->thisval, l->fun, argv, &r_val);
|
||||||
|
}
|
||||||
|
JS_CallFunctionValue(ctx, elwin->thisval, elwin->onmessage, argv, &r_val);
|
||||||
|
done_heartbeat(interpreter->heartbeat);
|
||||||
|
JS::LeaveRealm(ctx, comp);
|
||||||
|
mem_free(mess);
|
||||||
|
check_for_rerender(interpreter, "window_onmessage");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
window_addEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
struct el_window *elwin = JS::GetMaybePtrFromReservedSlot<struct el_window>(hobj, 0);
|
||||||
|
|
||||||
|
if (!elwin) {
|
||||||
|
elwin = (struct el_window *)mem_calloc(1, sizeof(*elwin));
|
||||||
|
|
||||||
|
if (!elwin) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
init_list(elwin->listeners);
|
||||||
|
elwin->interpreter = interpreter;
|
||||||
|
elwin->thisval = hobj;
|
||||||
|
JS::SetReservedSlot(hobj, 0, JS::PrivateValue(elwin));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
char *method = jsval_to_string(ctx, args[0]);
|
||||||
|
JS::RootedValue fun(ctx, args[1]);
|
||||||
|
|
||||||
|
struct listener *l;
|
||||||
|
|
||||||
|
foreach(l, elwin->listeners) {
|
||||||
|
if (strcmp(l->typ, method)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (l->fun == fun) {
|
||||||
|
args.rval().setUndefined();
|
||||||
|
mem_free(method);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
window_removeEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
struct el_window *elwin = JS::GetMaybePtrFromReservedSlot<struct el_window>(hobj, 0);
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
char *method = jsval_to_string(ctx, args[0]);
|
||||||
|
|
||||||
|
if (!method) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::RootedValue fun(ctx, args[1]);
|
||||||
|
|
||||||
|
struct listener *l;
|
||||||
|
|
||||||
|
foreach(l, elwin->listeners) {
|
||||||
|
if (strcmp(l->typ, method)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (l->fun == fun) {
|
||||||
|
del_from_list(l);
|
||||||
|
mem_free_set(&l->typ, NULL);
|
||||||
|
mem_free(l);
|
||||||
|
mem_free(method);
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mem_free(method);
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
window_postMessage(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
struct el_window *elwin = JS::GetMaybePtrFromReservedSlot<struct el_window>(hobj, 0);
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
char *data = jsval_to_string(ctx, args[0]);
|
||||||
|
char *targetOrigin = jsval_to_string(ctx, args[1]);
|
||||||
|
char *source = stracpy("TODO");
|
||||||
|
|
||||||
|
JSObject *val = get_messageEvent(ctx, data, targetOrigin, source);
|
||||||
|
|
||||||
|
mem_free_if(data);
|
||||||
|
mem_free_if(targetOrigin);
|
||||||
|
mem_free_if(source);
|
||||||
|
|
||||||
|
if (!val || !elwin) {
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
struct el_message *mess = (struct el_message *)mem_calloc(1, sizeof(*mess));
|
||||||
|
if (!mess) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::RootedObject messageObject(ctx, val);
|
||||||
|
mess->messageObject = messageObject;
|
||||||
|
mess->elwin = elwin;
|
||||||
|
register_bottom_half(onmessage_run, mess);
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* @window_funcs{"alert"} */
|
/* @window_funcs{"alert"} */
|
||||||
static bool
|
static bool
|
||||||
window_alert(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
window_alert(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
@ -489,6 +489,15 @@ set_handlers(int fd, select_handler_T read_func, select_handler_T write_func,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static timer_id_T periodic_redraw_timer = TIMER_ID_UNDEF;
|
||||||
|
|
||||||
|
static void
|
||||||
|
periodic_redraw_all_terminals(void *data)
|
||||||
|
{
|
||||||
|
redraw_all_terminals();
|
||||||
|
install_timer(&periodic_redraw_timer, DISPLAY_TIME_REFRESH, periodic_redraw_all_terminals, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
select_loop(void (*init)(void))
|
select_loop(void (*init)(void))
|
||||||
{
|
{
|
||||||
@ -514,13 +523,14 @@ select_loop(void (*init)(void))
|
|||||||
restrict_fds();
|
restrict_fds();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
periodic_redraw_all_terminals(NULL);
|
||||||
|
|
||||||
if (event_enabled) {
|
if (event_enabled) {
|
||||||
while (!program.terminate) {
|
while (!program.terminate) {
|
||||||
check_signals();
|
check_signals();
|
||||||
if (1 /*(!F)*/) {
|
if (1 /*(!F)*/) {
|
||||||
do_event_loop(EVLOOP_NONBLOCK);
|
do_event_loop(EVLOOP_NONBLOCK);
|
||||||
check_signals();
|
check_signals();
|
||||||
redraw_all_terminals();
|
|
||||||
}
|
}
|
||||||
if (program.terminate) break;
|
if (program.terminate) break;
|
||||||
do_event_loop(EVLOOP_ONCE);
|
do_event_loop(EVLOOP_ONCE);
|
||||||
@ -535,7 +545,6 @@ select_loop(void (*init)(void))
|
|||||||
|
|
||||||
check_signals();
|
check_signals();
|
||||||
check_timers(&last_time);
|
check_timers(&last_time);
|
||||||
redraw_all_terminals();
|
|
||||||
|
|
||||||
memcpy(&x_read, &w_read, sizeof(fd_set));
|
memcpy(&x_read, &w_read, sizeof(fd_set));
|
||||||
memcpy(&x_write, &w_write, sizeof(fd_set));
|
memcpy(&x_write, &w_write, sizeof(fd_set));
|
||||||
|
@ -141,8 +141,12 @@ abort_download(struct file_download *file_download)
|
|||||||
if (file_download->ses)
|
if (file_download->ses)
|
||||||
check_questions_queue(file_download->ses);
|
check_questions_queue(file_download->ses);
|
||||||
|
|
||||||
if (file_download->dlg_data)
|
if (file_download->dlg_data) {
|
||||||
|
if (file_download->dlg_data->dlg && file_download->dlg_data->dlg->refresh) {
|
||||||
|
kill_timer(&file_download->dlg_data->dlg->refresh->timer);
|
||||||
|
}
|
||||||
cancel_dialog(file_download->dlg_data, NULL);
|
cancel_dialog(file_download->dlg_data, NULL);
|
||||||
|
}
|
||||||
cancel_download(&file_download->download, file_download->stop);
|
cancel_download(&file_download->download, file_download->stop);
|
||||||
if (file_download->uri) done_uri(file_download->uri);
|
if (file_download->uri) done_uri(file_download->uri);
|
||||||
|
|
||||||
@ -481,8 +485,6 @@ download_data_store(struct download *download, struct file_download *file_downlo
|
|||||||
if_assert_failed term = file_download->term = NULL;
|
if_assert_failed term = file_download->term = NULL;
|
||||||
|
|
||||||
if (is_in_progress_state(download->state)) {
|
if (is_in_progress_state(download->state)) {
|
||||||
if (file_download->dlg_data)
|
|
||||||
redraw_dialog(file_download->dlg_data, 1);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,9 +602,6 @@ download_data(struct download *download, struct file_download *file_download)
|
|||||||
file_download->uri = get_uri_reference(cached->redirect);
|
file_download->uri = get_uri_reference(cached->redirect);
|
||||||
file_download->download.state = connection_state(S_WAIT_REDIR);
|
file_download->download.state = connection_state(S_WAIT_REDIR);
|
||||||
|
|
||||||
if (file_download->dlg_data)
|
|
||||||
redraw_dialog(file_download->dlg_data, 1);
|
|
||||||
|
|
||||||
load_uri(file_download->uri, cached->uri, &file_download->download,
|
load_uri(file_download->uri, cached->uri, &file_download->download,
|
||||||
PRI_DOWNLOAD, CACHE_MODE_NORMAL,
|
PRI_DOWNLOAD, CACHE_MODE_NORMAL,
|
||||||
download->progress ? download->progress->start : 0);
|
download->progress ? download->progress->start : 0);
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
|
|
||||||
#define DISPLAY_TIME_MIN ((milliseconds_T) 200)
|
#define DISPLAY_TIME_MIN ((milliseconds_T) 200)
|
||||||
#define DISPLAY_TIME 20
|
#define DISPLAY_TIME 20
|
||||||
|
#define DISPLAY_TIME_REFRESH ((milliseconds_T) 50)
|
||||||
|
|
||||||
#define HTML_LEFT_MARGIN 3
|
#define HTML_LEFT_MARGIN 3
|
||||||
#define HTML_MAX_TABLE_LEVEL 10
|
#define HTML_MAX_TABLE_LEVEL 10
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#ifdef CONFIG_TERMINFO
|
#ifdef CONFIG_TERMINFO
|
||||||
#include "terminal/terminfo.h"
|
#include "terminal/terminfo.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "util/bitfield.h"
|
||||||
#include "util/conv.h"
|
#include "util/conv.h"
|
||||||
#include "util/error.h"
|
#include "util/error.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
@ -442,6 +443,15 @@ static const struct screen_driver_opt *const screen_driver_opts[] = {
|
|||||||
|
|
||||||
static INIT_LIST_OF(struct screen_driver, active_screen_drivers);
|
static INIT_LIST_OF(struct screen_driver, active_screen_drivers);
|
||||||
|
|
||||||
|
void
|
||||||
|
set_screen_dirty(struct terminal_screen *screen, int from, int to)
|
||||||
|
{
|
||||||
|
for (unsigned int i = from; i <= to; i++) {
|
||||||
|
set_bitfield_bit(screen->dirty, i);
|
||||||
|
}
|
||||||
|
screen->was_dirty = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/** Set screen_driver.opt according to screen_driver.type and @a term_spec.
|
/** Set screen_driver.opt according to screen_driver.type and @a term_spec.
|
||||||
* Other members of @a *driver need not have been initialized.
|
* Other members of @a *driver need not have been initialized.
|
||||||
*
|
*
|
||||||
@ -1305,13 +1315,12 @@ add_char_true(struct string *screen, struct screen_driver *driver,
|
|||||||
#define add_chars(image_, term_, driver_, state_, ADD_CHAR, compare_bg_color, compare_fg_color) \
|
#define add_chars(image_, term_, driver_, state_, ADD_CHAR, compare_bg_color, compare_fg_color) \
|
||||||
{ \
|
{ \
|
||||||
struct terminal_screen *screen = (term_)->screen; \
|
struct terminal_screen *screen = (term_)->screen; \
|
||||||
int y = screen->dirty_from; \
|
int y = 0; \
|
||||||
int xmax = (term_)->width - 1; \
|
int xmax = (term_)->width - 1; \
|
||||||
int ymax = (term_)->height - 1; \
|
int ymax = (term_)->height - 1; \
|
||||||
\
|
\
|
||||||
int_upper_bound(&screen->dirty_to, ymax); \
|
for (; y <= ymax; y++) { \
|
||||||
\
|
if (!test_bitfield_bit(screen->dirty, y)) continue; \
|
||||||
for (; y <= screen->dirty_to; y++) { \
|
|
||||||
int ypos = y * (term_)->width; \
|
int ypos = y * (term_)->width; \
|
||||||
struct screen_char *current = &screen->last_image[ypos]; \
|
struct screen_char *current = &screen->last_image[ypos]; \
|
||||||
struct screen_char *pos = &screen->image[ypos]; \
|
struct screen_char *pos = &screen->image[ypos]; \
|
||||||
@ -1319,6 +1328,7 @@ add_char_true(struct string *screen, struct screen_driver *driver,
|
|||||||
int is_last_line = (y == ymax); \
|
int is_last_line = (y == ymax); \
|
||||||
int x = 0; \
|
int x = 0; \
|
||||||
int dirty = 0; \
|
int dirty = 0; \
|
||||||
|
clear_bitfield_bit(screen->dirty, y); \
|
||||||
\
|
\
|
||||||
for (; x <= xmax; x++, current++, pos++) { \
|
for (; x <= xmax; x++, current++, pos++) { \
|
||||||
/* Workaround for terminals without
|
/* Workaround for terminals without
|
||||||
@ -1370,7 +1380,7 @@ redraw_screen(struct terminal *term)
|
|||||||
struct screen_state state = INIT_SCREEN_STATE;
|
struct screen_state state = INIT_SCREEN_STATE;
|
||||||
struct terminal_screen *screen = term->screen;
|
struct terminal_screen *screen = term->screen;
|
||||||
|
|
||||||
if (!screen || screen->dirty_from > screen->dirty_to) return;
|
if (!screen || !screen->was_dirty) return;
|
||||||
if (term->master && is_blocked()) return;
|
if (term->master && is_blocked()) return;
|
||||||
|
|
||||||
driver = get_screen_driver(term);
|
driver = get_screen_driver(term);
|
||||||
@ -1440,8 +1450,7 @@ redraw_screen(struct terminal *term)
|
|||||||
done_string(&image);
|
done_string(&image);
|
||||||
|
|
||||||
copy_screen_chars(screen->last_image, screen->image, term->width * term->height);
|
copy_screen_chars(screen->last_image, screen->image, term->width * term->height);
|
||||||
screen->dirty_from = term->height;
|
screen->was_dirty = 0;
|
||||||
screen->dirty_to = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1506,6 +1515,12 @@ resize_screen(struct terminal *term, int width, int height)
|
|||||||
size = width * height;
|
size = width * height;
|
||||||
if (size <= 0) return;
|
if (size <= 0) return;
|
||||||
|
|
||||||
|
if (term->height != height) {
|
||||||
|
struct bitfield *new_dirty = init_bitfield(height);
|
||||||
|
if (!new_dirty) return;
|
||||||
|
mem_free_set(&screen->dirty, new_dirty);
|
||||||
|
}
|
||||||
|
|
||||||
bsize = size * sizeof(*image);
|
bsize = size * sizeof(*image);
|
||||||
|
|
||||||
image = (struct screen_char *)mem_realloc(screen->image, bsize * 2);
|
image = (struct screen_char *)mem_realloc(screen->image, bsize * 2);
|
||||||
@ -1519,6 +1534,7 @@ resize_screen(struct terminal *term, int width, int height)
|
|||||||
|
|
||||||
term->width = width;
|
term->width = width;
|
||||||
term->height = height;
|
term->height = height;
|
||||||
|
|
||||||
set_screen_dirty(screen, 0, height);
|
set_screen_dirty(screen, 0, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1526,6 +1542,7 @@ void
|
|||||||
done_screen(struct terminal_screen *screen)
|
done_screen(struct terminal_screen *screen)
|
||||||
{
|
{
|
||||||
mem_free_if(screen->image);
|
mem_free_if(screen->image);
|
||||||
|
mem_free(screen->dirty);
|
||||||
mem_free(screen);
|
mem_free(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct bitfield;
|
||||||
struct module;
|
struct module;
|
||||||
struct screen_char;
|
struct screen_char;
|
||||||
struct terminal;
|
struct terminal;
|
||||||
@ -21,18 +22,14 @@ struct terminal_screen {
|
|||||||
int cx, cy;
|
int cx, cy;
|
||||||
int lcx, lcy;
|
int lcx, lcy;
|
||||||
|
|
||||||
/** The range of line numbers that are out of sync with the physical
|
/** Whether to redraw screen */
|
||||||
* screen. #dirty_from > #dirty_to means not dirty. */
|
unsigned int was_dirty:1;
|
||||||
int dirty_from, dirty_to;
|
|
||||||
|
struct bitfield *dirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Mark the screen ready for redrawing. */
|
/** Mark the screen ready for redrawing. */
|
||||||
static inline void
|
void set_screen_dirty(struct terminal_screen *screen, int from, int to);
|
||||||
set_screen_dirty(struct terminal_screen *screen, int from, int to)
|
|
||||||
{
|
|
||||||
int_upper_bound(&screen->dirty_from, from);
|
|
||||||
int_lower_bound(&screen->dirty_to, to);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes a screen. Returns NULL upon allocation failure. */
|
/** Initializes a screen. Returns NULL upon allocation failure. */
|
||||||
struct terminal_screen *init_screen(void);
|
struct terminal_screen *init_screen(void);
|
||||||
|
22
test/ecmascript/element_getElementsByTagName.html
Normal file
22
test/ecmascript/element_getElementsByTagName.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body id="body">
|
||||||
|
|
||||||
|
First Name: <input name="fname" type="text" value="Michael"><br>
|
||||||
|
First Name: <input name="fname" type="text" value="Doug">
|
||||||
|
|
||||||
|
<p>Click the button to get the tag name of the first element in the body that has tag P.</p>
|
||||||
|
|
||||||
|
<button onclick="myFunction()">Try it</button>
|
||||||
|
|
||||||
|
<p id="demo"></p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function myFunction() {
|
||||||
|
var x = document.getElementById('body').getElementsByTagName("P").item(0).outerHTML;
|
||||||
|
window.alert(x);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user