1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00

[quickjs] event.preventDefault()

This commit is contained in:
Witold Filipczyk 2024-03-10 18:06:56 +01:00
parent 3ccb7e664b
commit da7a525c99

View File

@ -26,6 +26,8 @@ static JSValue js_event_get_property_composed(JSContext *ctx, JSValueConst this_
static JSValue js_event_get_property_defaultPrevented(JSContext *ctx, JSValueConst this_val);
static JSValue js_event_get_property_type(JSContext *ctx, JSValueConst this_val);
static JSValue js_event_preventDefault(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
struct eljs_event {
char *type_;
unsigned int bubbles:1;
@ -57,7 +59,8 @@ static const JSCFunctionListEntry js_event_proto_funcs[] = {
JS_CGETSET_DEF("cancelable", js_event_get_property_cancelable, NULL),
JS_CGETSET_DEF("composed", js_event_get_property_composed, NULL),
JS_CGETSET_DEF("defaultPrevented", js_event_get_property_defaultPrevented, NULL),
JS_CGETSET_DEF("type", js_event_get_property_type, NULL)
JS_CGETSET_DEF("type", js_event_get_property_type, NULL),
JS_CFUNC_DEF("preventDefault", 0, js_event_preventDefault),
};
static JSValue
@ -154,6 +157,25 @@ js_event_get_property_type(JSContext *ctx, JSValueConst this_val)
RETURN_JS(r);
}
static JSValue
js_event_preventDefault(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct eljs_event *event = (struct eljs_event *)(JS_GetOpaque(this_val, js_event_class_id));
if (!event) {
return JS_NULL;
}
if (event->cancelable) {
event->defaultPrevented = 1;
}
return JS_UNDEFINED;
}
static JSValue
js_event_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
{