mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[mujs] message.c
This commit is contained in:
parent
c4843f488a
commit
931cf0d4f3
@ -1,6 +1,6 @@
|
||||
top_builddir=../../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
|
||||
OBJS = attr.o attributes.o collection.o console.o forms.o history.o implementation.o keyboard.o localstorage.o mapa.obj
|
||||
OBJS = attr.o attributes.o collection.o console.o forms.o history.o implementation.o keyboard.o localstorage.o mapa.obj message.o
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
@ -1 +1 @@
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'forms.c', 'history.c', 'implementation.c', 'keyboard.c', 'localstorage.c', 'mapa.cpp')
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'forms.c', 'history.c', 'implementation.c', 'keyboard.c', 'localstorage.c', 'mapa.cpp', 'message.c')
|
||||
|
138
src/ecmascript/libdom/mujs/message.c
Normal file
138
src/ecmascript/libdom/mujs/message.c
Normal file
@ -0,0 +1,138 @@
|
||||
/* 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 "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/mujs.h"
|
||||
#include "ecmascript/mujs/message.h"
|
||||
|
||||
static void mjs_messageEvent_get_property_data(js_State *J);
|
||||
static void mjs_messageEvent_get_property_lastEventId(js_State *J);
|
||||
static void mjs_messageEvent_get_property_origin(js_State *J);
|
||||
static void mjs_messageEvent_get_property_source(js_State *J);
|
||||
|
||||
struct message_event {
|
||||
char *data;
|
||||
char *lastEventId;
|
||||
char *origin;
|
||||
char *source;
|
||||
};
|
||||
|
||||
static
|
||||
void mjs_messageEvent_finalizer(js_State *J, void *val)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct message_event *event = (struct message_event *)val;
|
||||
|
||||
if (event) {
|
||||
mem_free_if(event->data);
|
||||
mem_free_if(event->lastEventId);
|
||||
mem_free_if(event->origin);
|
||||
mem_free_if(event->source);
|
||||
mem_free(event);
|
||||
}
|
||||
}
|
||||
|
||||
static int lastEventId;
|
||||
|
||||
void
|
||||
mjs_push_messageEvent(js_State *J, char *data, char *origin, char *source)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct message_event *event = (struct message_event *)mem_calloc(1, sizeof(*event));
|
||||
|
||||
if (!event) {
|
||||
js_error(J, "out of memory");
|
||||
return;
|
||||
}
|
||||
event->data = null_or_stracpy(data);
|
||||
event->origin = null_or_stracpy(origin);
|
||||
event->source = null_or_stracpy(source);
|
||||
|
||||
char id[32];
|
||||
|
||||
snprintf(id, 31, "%d", ++lastEventId);
|
||||
event->lastEventId = stracpy(id);
|
||||
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newuserdata(J, "event", event, mjs_messageEvent_finalizer);
|
||||
|
||||
addproperty(J, "data", mjs_messageEvent_get_property_data, NULL);
|
||||
addproperty(J, "lastEventId", mjs_messageEvent_get_property_lastEventId, NULL);
|
||||
addproperty(J, "origin", mjs_messageEvent_get_property_origin, NULL);
|
||||
addproperty(J, "source", mjs_messageEvent_get_property_source, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_messageEvent_get_property_data(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct message_event *event = (struct message_event *)js_touserdata(J, 0, "event");
|
||||
|
||||
if (!event || !event->data) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
js_pushstring(J, event->data);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_messageEvent_get_property_lastEventId(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct message_event *event = (struct message_event *)js_touserdata(J, 0, "event");
|
||||
|
||||
if (!event || !event->lastEventId) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
js_pushstring(J, event->lastEventId);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_messageEvent_get_property_origin(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct message_event *event = (struct message_event *)js_touserdata(J, 0, "event");
|
||||
|
||||
if (!event || !event->origin) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
js_pushstring(J, event->origin);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_messageEvent_get_property_source(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct message_event *event = (struct message_event *)js_touserdata(J, 0, "event");
|
||||
|
||||
if (!event || !event->source) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
js_pushstring(J, event->source);
|
||||
}
|
@ -53,6 +53,8 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#ifndef CONFIG_LIBDOM
|
||||
|
||||
static void mjs_messageEvent_get_property_data(js_State *J);
|
||||
static void mjs_messageEvent_get_property_lastEventId(js_State *J);
|
||||
static void mjs_messageEvent_get_property_origin(js_State *J);
|
||||
@ -175,3 +177,4 @@ mjs_messageEvent_get_property_source(js_State *J)
|
||||
}
|
||||
js_pushstring(J, event->source);
|
||||
}
|
||||
#endif
|
||||
|
@ -3,6 +3,14 @@
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void mjs_push_messageEvent(js_State *J, char *data, char *origin, char *source);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user