mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[mujs] event placeholder
This commit is contained in:
parent
00b108f200
commit
cc0d93cfba
@ -28,6 +28,7 @@
|
||||
#include "ecmascript/mujs/console.h"
|
||||
#include "ecmascript/mujs/document.h"
|
||||
#include "ecmascript/mujs/element.h"
|
||||
#include "ecmascript/mujs/event.h"
|
||||
#include "ecmascript/mujs/history.h"
|
||||
#include "ecmascript/mujs/localstorage.h"
|
||||
#include "ecmascript/mujs/location.h"
|
||||
@ -135,6 +136,7 @@ mujs_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
mjs_location_init(J);
|
||||
mjs_document_init(J);
|
||||
mjs_xhr_init(J);
|
||||
mjs_event_init(J);
|
||||
|
||||
return J;
|
||||
#if 0
|
||||
|
@ -1,7 +1,7 @@
|
||||
top_builddir=../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
|
||||
OBJS = attr.o attributes.o collection.o console.o css.o document.o element.o form.o forms.o history.o implementation.o input.o \
|
||||
OBJS = attr.o attributes.o collection.o console.o css.o document.o element.o event.o form.o forms.o history.o implementation.o input.o \
|
||||
keyboard.o localstorage.o location.o mapa.o message.o navigator.o nodelist.o screen.o style.o unibar.o window.o xhr.o
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
105
src/ecmascript/mujs/event.c
Normal file
105
src/ecmascript/mujs/event.c
Normal file
@ -0,0 +1,105 @@
|
||||
/* The MuJS Event 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/event.h"
|
||||
#include "intl/charsets.h"
|
||||
#include "terminal/event.h"
|
||||
|
||||
static void mjs_event_get_property_type(js_State *J);
|
||||
|
||||
struct eljs_event {
|
||||
char *type_;
|
||||
};
|
||||
|
||||
static void
|
||||
mjs_event_finalizer(js_State *J, void *val)
|
||||
{
|
||||
struct eljs_event *event = (struct eljs_event *)val;
|
||||
|
||||
if (event) {
|
||||
mem_free_if(event->type_);
|
||||
mem_free(event);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mjs_push_event(js_State *J, char *type_)
|
||||
{
|
||||
struct eljs_event *event = (struct eljs_event *)mem_calloc(1, sizeof(*event));
|
||||
|
||||
if (!event) {
|
||||
js_error(J, "out of memory");
|
||||
return;
|
||||
}
|
||||
event->type_ = null_or_stracpy(type_);
|
||||
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newuserdata(J, "event", event, mjs_event_finalizer);
|
||||
addproperty(J, "type", mjs_event_get_property_type, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_event_get_property_type(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct eljs_event *event = (struct eljs_event *)js_touserdata(J, 0, "event");
|
||||
|
||||
if (!event) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
js_pushstring(J, event->type_ ?: "");
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_event_fun(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
js_pushundefined(J);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_event_constructor(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct eljs_event *event = (struct eljs_event *)mem_calloc(1, sizeof(*event));
|
||||
|
||||
if (!event) {
|
||||
return;
|
||||
}
|
||||
event->type_ = null_or_stracpy(js_tostring(J, 1));
|
||||
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newuserdata(J, "event", event, mjs_event_finalizer);
|
||||
addproperty(J, "type", mjs_event_get_property_type, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
mjs_event_init(js_State *J)
|
||||
{
|
||||
js_pushglobal(J);
|
||||
js_newcconstructor(J, mjs_event_fun, mjs_event_constructor, "Event", 0);
|
||||
js_defglobal(J, "Event", JS_DONTENUM);
|
||||
return 0;
|
||||
}
|
16
src/ecmascript/mujs/event.h
Normal file
16
src/ecmascript/mujs/event.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef EL__ECMASCRIPT_MUJS_EVENT_H
|
||||
#define EL__ECMASCRIPT_MUJS_EVENT_H
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int mjs_event_init(js_State *J);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,2 +1,2 @@
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'css.c', 'document.c', 'element.c', 'form.c', 'forms.c', 'history.c', 'implementation.c', 'input.c', 'keyboard.c',
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'css.c', 'document.c', 'element.c', 'event.c', 'form.c', 'forms.c', 'history.c', 'implementation.c', 'input.c', 'keyboard.c',
|
||||
'localstorage.c', 'location.c', 'mapa.c', 'message.c', 'navigator.c', 'nodelist.c', 'screen.c', 'style.c', 'unibar.c', 'window.c', 'xhr.c')
|
||||
|
Loading…
x
Reference in New Issue
Block a user