mirror of
https://github.com/rkd77/elinks.git
synced 2024-09-28 03:06:20 -04:00
[ecmascript] customEvent.target getter
This commit is contained in:
parent
67deceb07a
commit
6534c412c2
@ -16,6 +16,7 @@
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
#include "ecmascript/mujs.h"
|
||||
#include "ecmascript/mujs/customevent.h"
|
||||
#include "ecmascript/mujs/element.h"
|
||||
#include "intl/charsets.h"
|
||||
#include "terminal/event.h"
|
||||
#include "viewer/text/vs.h"
|
||||
@ -25,6 +26,7 @@ static void mjs_customEvent_get_property_cancelable(js_State *J);
|
||||
//static void mjs_customEvent_get_property_composed(js_State *J);
|
||||
static void mjs_customEvent_get_property_defaultPrevented(js_State *J);
|
||||
static void mjs_customEvent_get_property_detail(js_State *J);
|
||||
static void mjs_customEvent_get_property_target(js_State *J);
|
||||
static void mjs_customEvent_get_property_type(js_State *J);
|
||||
|
||||
static void mjs_customEvent_preventDefault(js_State *J);
|
||||
@ -101,6 +103,7 @@ mjs_push_customEvent(js_State *J, char *type_)
|
||||
// addproperty(J, "composed", mjs_customEvent_get_property_composed, NULL);
|
||||
addproperty(J, "defaultPrevented", mjs_customEvent_get_property_defaultPrevented, NULL);
|
||||
addproperty(J, "detail", mjs_customEvent_get_property_detail, NULL);
|
||||
addproperty(J, "target", mjs_customEvent_get_property_target, NULL);
|
||||
addproperty(J, "type", mjs_customEvent_get_property_type, NULL);
|
||||
}
|
||||
}
|
||||
@ -195,6 +198,29 @@ mjs_customEvent_get_property_detail(js_State *J)
|
||||
js_getregistry(J, detail);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_customEvent_get_property_target(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
dom_custom_event *event = (dom_custom_event *)js_touserdata(J, 0, "event");
|
||||
|
||||
if (!event) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
dom_event_target *target = NULL;
|
||||
dom_exception exc = dom_event_get_target(event, &target);
|
||||
|
||||
if (exc != DOM_NO_ERR || !target) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
mjs_push_element(J, target);
|
||||
dom_node_unref(target);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_customEvent_get_property_type(js_State *J)
|
||||
{
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
#include "ecmascript/quickjs.h"
|
||||
#include "ecmascript/quickjs/element.h"
|
||||
#include "ecmascript/quickjs/event.h"
|
||||
#include "intl/charsets.h"
|
||||
#include "terminal/event.h"
|
||||
@ -29,6 +30,7 @@ static JSValue js_customEvent_get_property_cancelable(JSContext *ctx, JSValueCon
|
||||
//static JSValue js_customEvent_get_property_composed(JSContext *ctx, JSValueConst this_val);
|
||||
static JSValue js_customEvent_get_property_defaultPrevented(JSContext *ctx, JSValueConst this_val);
|
||||
static JSValue js_customEvent_get_property_detail(JSContext *ctx, JSValueConst this_val);
|
||||
static JSValue js_customEvent_get_property_target(JSContext *ctx, JSValueConst this_val);
|
||||
static JSValue js_customEvent_get_property_type(JSContext *ctx, JSValueConst this_val);
|
||||
|
||||
static JSValue js_customEvent_preventDefault(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
|
||||
@ -63,6 +65,7 @@ static const JSCFunctionListEntry js_customEvent_proto_funcs[] = {
|
||||
// JS_CGETSET_DEF("composed", js_customEvent_get_property_composed, NULL),
|
||||
JS_CGETSET_DEF("defaultPrevented", js_customEvent_get_property_defaultPrevented, NULL),
|
||||
JS_CGETSET_DEF("detail", js_customEvent_get_property_detail, NULL),
|
||||
JS_CGETSET_DEF("target", js_customEvent_get_property_target, NULL),
|
||||
JS_CGETSET_DEF("type", js_customEvent_get_property_type, NULL),
|
||||
JS_CFUNC_DEF("preventDefault", 0, js_customEvent_preventDefault),
|
||||
};
|
||||
@ -169,6 +172,29 @@ js_customEvent_get_property_detail(JSContext *ctx, JSValueConst this_val)
|
||||
RETURN_JS(*detail);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_customEvent_get_property_target(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
struct dom_custom_event *event = (dom_custom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
||||
|
||||
if (!event) {
|
||||
return JS_NULL;
|
||||
}
|
||||
dom_event_target *target = NULL;
|
||||
dom_exception exc = dom_event_get_target(event, &target);
|
||||
|
||||
if (exc != DOM_NO_ERR || !target) {
|
||||
return JS_NULL;
|
||||
}
|
||||
JSValue r = getElement(ctx, target);
|
||||
dom_string_unref(target);
|
||||
|
||||
RETURN_JS(r);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_customEvent_get_property_type(JSContext *ctx, JSValueConst this_val)
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
#include "ecmascript/spidermonkey.h"
|
||||
#include "ecmascript/spidermonkey/customevent.h"
|
||||
#include "ecmascript/spidermonkey/element.h"
|
||||
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||
#include "ecmascript/timer.h"
|
||||
#include "intl/libintl.h"
|
||||
@ -64,6 +65,7 @@ static bool customEvent_get_property_cancelable(JSContext *ctx, unsigned int arg
|
||||
static bool customEvent_get_property_composed(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool customEvent_get_property_defaultPrevented(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool customEvent_get_property_detail(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool customEvent_get_property_target(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool customEvent_get_property_type(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
|
||||
static bool customEvent_preventDefault(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
@ -191,6 +193,7 @@ JSPropertySpec customEvent_props[] = {
|
||||
// JS_PSG("composed", customEvent_get_property_composed, JSPROP_ENUMERATE),
|
||||
JS_PSG("defaultPrevented", customEvent_get_property_defaultPrevented, JSPROP_ENUMERATE),
|
||||
JS_PSG("detail", customEvent_get_property_detail, JSPROP_ENUMERATE),
|
||||
JS_PSG("target", customEvent_get_property_target, JSPROP_ENUMERATE),
|
||||
JS_PSG("type", customEvent_get_property_type, JSPROP_ENUMERATE),
|
||||
JS_PS_END
|
||||
};
|
||||
@ -371,6 +374,41 @@ customEvent_preventDefault(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
customEvent_get_property_target(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;
|
||||
}
|
||||
dom_custom_event *event = JS::GetMaybePtrFromReservedSlot<dom_custom_event>(hobj, 0);
|
||||
|
||||
if (!event) {
|
||||
return false;
|
||||
}
|
||||
dom_event_target *target = NULL;
|
||||
dom_exception exc = dom_event_get_target(event, &target);
|
||||
|
||||
if (exc != DOM_NO_ERR || !target) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
JSObject *obj = getElement(ctx, target);
|
||||
args.rval().setObject(*obj);
|
||||
dom_node_unref(target);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
customEvent_get_property_type(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user