mirror of
https://github.com/rkd77/elinks.git
synced 2024-09-28 03:06:20 -04:00
Compare commits
5 Commits
b9d266c52c
...
6b053637b3
Author | SHA1 | Date | |
---|---|---|---|
|
6b053637b3 | ||
|
d529265f02 | ||
|
fec5bd561d | ||
|
4932a689c8 | ||
|
b67d41bd82 |
@ -10,6 +10,7 @@ extern "C" {
|
|||||||
#ifdef CONFIG_LIBDOM
|
#ifdef CONFIG_LIBDOM
|
||||||
#include <dom/dom.h>
|
#include <dom/dom.h>
|
||||||
#include <dom/bindings/hubbub/parser.h>
|
#include <dom/bindings/hubbub/parser.h>
|
||||||
|
#include <dom/events/custom_event.h>
|
||||||
#include <dom/events/event.h>
|
#include <dom/events/event.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -10,54 +10,87 @@
|
|||||||
|
|
||||||
#include "elinks.h"
|
#include "elinks.h"
|
||||||
|
|
||||||
|
#include "document/document.h"
|
||||||
|
#include "document/view.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/libdom/dom.h"
|
||||||
#include "ecmascript/mujs.h"
|
#include "ecmascript/mujs.h"
|
||||||
#include "ecmascript/mujs/customevent.h"
|
#include "ecmascript/mujs/customevent.h"
|
||||||
#include "intl/charsets.h"
|
#include "intl/charsets.h"
|
||||||
#include "terminal/event.h"
|
#include "terminal/event.h"
|
||||||
|
#include "viewer/text/vs.h"
|
||||||
|
|
||||||
static void mjs_customEvent_get_property_bubbles(js_State *J);
|
static void mjs_customEvent_get_property_bubbles(js_State *J);
|
||||||
static void mjs_customEvent_get_property_cancelable(js_State *J);
|
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_composed(js_State *J);
|
||||||
static void mjs_customEvent_get_property_defaultPrevented(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_detail(js_State *J);
|
||||||
static void mjs_customEvent_get_property_type(js_State *J);
|
static void mjs_customEvent_get_property_type(js_State *J);
|
||||||
|
|
||||||
static void mjs_customEvent_preventDefault(js_State *J);
|
static void mjs_customEvent_preventDefault(js_State *J);
|
||||||
|
|
||||||
struct eljscustom_event {
|
|
||||||
const char *detail;
|
|
||||||
char *type_;
|
|
||||||
unsigned int bubbles:1;
|
|
||||||
unsigned int cancelable:1;
|
|
||||||
unsigned int composed:1;
|
|
||||||
unsigned int defaultPrevented:1;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mjs_customEvent_finalizer(js_State *J, void *val)
|
mjs_customEvent_finalizer(js_State *J, void *val)
|
||||||
{
|
{
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)val;
|
dom_custom_event *event = (dom_custom_event *)val;
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
if (event->detail) {
|
const char *detail = NULL;
|
||||||
js_unref(J, event->detail);
|
dom_exception exc = dom_custom_event_get_detail(event, &detail);
|
||||||
|
|
||||||
|
if (detail) {
|
||||||
|
js_unref(J, detail);
|
||||||
}
|
}
|
||||||
mem_free_if(event->type_);
|
dom_event_unref(event);
|
||||||
mem_free(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mjs_push_customEvent(js_State *J, char *type_)
|
mjs_push_customEvent(js_State *J, char *type_)
|
||||||
{
|
{
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)mem_calloc(1, sizeof(*event));
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||||
|
struct view_state *vs = interpreter->vs;
|
||||||
|
|
||||||
if (!event) {
|
if (!vs) {
|
||||||
|
js_error(J, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct document_view *doc_view = vs->doc_view;
|
||||||
|
struct document *document = doc_view->document;
|
||||||
|
|
||||||
|
if (!document->dom) {
|
||||||
|
js_error(J, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dom_custom_event *event = NULL;
|
||||||
|
dom_string *CustomEventStr = NULL;
|
||||||
|
dom_exception exc = dom_string_create("CustomEvent", sizeof("CustomEvent") - 1, &CustomEventStr);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !CustomEventStr) {
|
||||||
|
js_error(J, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
exc = dom_document_event_create_event(document->dom, CustomEventStr, &event);
|
||||||
|
dom_string_unref(CustomEventStr);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
js_error(J, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dom_string *typ = NULL;
|
||||||
|
|
||||||
|
if (type_) {
|
||||||
|
exc = dom_string_create((const uint8_t *)type_, strlen(type_), &typ);
|
||||||
|
}
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
js_error(J, "out of memory");
|
js_error(J, "out of memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event->type_ = null_or_stracpy(type_);
|
dom_custom_event_init_ns(event, NULL, typ, false, false, NULL);
|
||||||
|
|
||||||
|
if (typ) {
|
||||||
|
dom_string_unref(typ);
|
||||||
|
}
|
||||||
|
|
||||||
js_newobject(J);
|
js_newobject(J);
|
||||||
{
|
{
|
||||||
@ -65,7 +98,7 @@ mjs_push_customEvent(js_State *J, char *type_)
|
|||||||
addmethod(J, "preventDefault", mjs_customEvent_preventDefault, 0);
|
addmethod(J, "preventDefault", mjs_customEvent_preventDefault, 0);
|
||||||
addproperty(J, "bubbles", mjs_customEvent_get_property_bubbles, NULL);
|
addproperty(J, "bubbles", mjs_customEvent_get_property_bubbles, NULL);
|
||||||
addproperty(J, "cancelable", mjs_customEvent_get_property_cancelable, NULL);
|
addproperty(J, "cancelable", mjs_customEvent_get_property_cancelable, NULL);
|
||||||
addproperty(J, "composed", mjs_customEvent_get_property_composed, NULL);
|
// addproperty(J, "composed", mjs_customEvent_get_property_composed, NULL);
|
||||||
addproperty(J, "defaultPrevented", mjs_customEvent_get_property_defaultPrevented, NULL);
|
addproperty(J, "defaultPrevented", mjs_customEvent_get_property_defaultPrevented, NULL);
|
||||||
addproperty(J, "detail", mjs_customEvent_get_property_detail, NULL);
|
addproperty(J, "detail", mjs_customEvent_get_property_detail, NULL);
|
||||||
addproperty(J, "type", mjs_customEvent_get_property_type, NULL);
|
addproperty(J, "type", mjs_customEvent_get_property_type, NULL);
|
||||||
@ -78,13 +111,15 @@ mjs_customEvent_get_property_bubbles(js_State *J)
|
|||||||
#ifdef ECMASCRIPT_DEBUG
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)js_touserdata(J, 0, "event");
|
dom_custom_event *event = (dom_custom_event *)js_touserdata(J, 0, "event");
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
js_pushnull(J);
|
js_pushnull(J);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
js_pushboolean(J, event->bubbles);
|
bool bubbles = false;
|
||||||
|
dom_exception exc = dom_event_get_bubbles(event, &bubbles);
|
||||||
|
js_pushboolean(J, bubbles);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -93,15 +128,18 @@ mjs_customEvent_get_property_cancelable(js_State *J)
|
|||||||
#ifdef ECMASCRIPT_DEBUG
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)js_touserdata(J, 0, "event");
|
dom_custom_event *event = (dom_custom_event *)js_touserdata(J, 0, "event");
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
js_pushnull(J);
|
js_pushnull(J);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
js_pushboolean(J, event->cancelable);
|
bool cancelable = false;
|
||||||
|
dom_exception exc = dom_event_get_cancelable(event, &cancelable);
|
||||||
|
js_pushboolean(J, cancelable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static void
|
static void
|
||||||
mjs_customEvent_get_property_composed(js_State *J)
|
mjs_customEvent_get_property_composed(js_State *J)
|
||||||
{
|
{
|
||||||
@ -116,6 +154,7 @@ mjs_customEvent_get_property_composed(js_State *J)
|
|||||||
}
|
}
|
||||||
js_pushboolean(J, event->composed);
|
js_pushboolean(J, event->composed);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mjs_customEvent_get_property_defaultPrevented(js_State *J)
|
mjs_customEvent_get_property_defaultPrevented(js_State *J)
|
||||||
@ -123,13 +162,15 @@ mjs_customEvent_get_property_defaultPrevented(js_State *J)
|
|||||||
#ifdef ECMASCRIPT_DEBUG
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)js_touserdata(J, 0, "event");
|
dom_custom_event *event = (dom_custom_event *)js_touserdata(J, 0, "event");
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
js_pushnull(J);
|
js_pushnull(J);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
js_pushboolean(J, event->defaultPrevented);
|
bool prevented = false;
|
||||||
|
dom_exception exc = dom_event_is_default_prevented(event, &prevented);
|
||||||
|
js_pushboolean(J, prevented);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -138,13 +179,20 @@ mjs_customEvent_get_property_detail(js_State *J)
|
|||||||
#ifdef ECMASCRIPT_DEBUG
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)js_touserdata(J, 0, "event");
|
dom_custom_event *event = (dom_custom_event *)js_touserdata(J, 0, "event");
|
||||||
|
|
||||||
if (!event || !event->detail) {
|
if (!event) {
|
||||||
js_pushnull(J);
|
js_pushnull(J);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
js_getregistry(J, event->detail);
|
const char *detail = NULL;
|
||||||
|
dom_exception exc = dom_custom_event_get_detail(event, &detail);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !detail) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
js_getregistry(J, detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -153,13 +201,21 @@ mjs_customEvent_get_property_type(js_State *J)
|
|||||||
#ifdef ECMASCRIPT_DEBUG
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)js_touserdata(J, 0, "event");
|
dom_custom_event *event = (dom_custom_event *)js_touserdata(J, 0, "event");
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
js_pushnull(J);
|
js_pushnull(J);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
js_pushstring(J, event->type_ ?: "");
|
dom_string *typ = NULL;
|
||||||
|
dom_exception exc = dom_event_get_type(event, &typ);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !typ) {
|
||||||
|
js_pushstring(J, "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
js_pushstring(J, dom_string_data(typ));
|
||||||
|
dom_string_unref(typ);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -168,15 +224,13 @@ mjs_customEvent_preventDefault(js_State *J)
|
|||||||
#ifdef ECMASCRIPT_DEBUG
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)js_touserdata(J, 0, "event");
|
dom_custom_event *event = (dom_custom_event *)js_touserdata(J, 0, "event");
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
js_pushnull(J);
|
js_pushnull(J);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event->cancelable) {
|
dom_event_prevent_default(event);
|
||||||
event->defaultPrevented = 1;
|
|
||||||
}
|
|
||||||
js_pushundefined(J);
|
js_pushundefined(J);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,33 +249,69 @@ mjs_customEvent_constructor(js_State *J)
|
|||||||
#ifdef ECMASCRIPT_DEBUG
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)mem_calloc(1, sizeof(*event));
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||||
|
struct view_state *vs = interpreter->vs;
|
||||||
if (!event) {
|
if (!vs) {
|
||||||
|
js_error(J, "error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event->type_ = null_or_stracpy(js_tostring(J, 1));
|
struct document_view *doc_view = vs->doc_view;
|
||||||
|
struct document *document = doc_view->document;
|
||||||
|
|
||||||
|
if (!document->dom) {
|
||||||
|
js_error(J, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dom_custom_event *event = NULL;
|
||||||
|
dom_string *CustomEventStr = NULL;
|
||||||
|
dom_exception exc = dom_string_create("CustomEvent", sizeof("CustomEvent") - 1, &CustomEventStr);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !CustomEventStr) {
|
||||||
|
js_error(J, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
exc = dom_document_event_create_event(document->dom, CustomEventStr, &event);
|
||||||
|
dom_string_unref(CustomEventStr);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
js_error(J, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dom_string *typ = NULL;
|
||||||
|
const char *tt = js_tostring(J, 1);
|
||||||
|
|
||||||
|
if (!tt) {
|
||||||
|
js_error(J, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
exc = dom_string_create((const uint8_t *)tt, strlen(tt), &typ);
|
||||||
|
bool bubbles = false;
|
||||||
|
bool cancelable = false;
|
||||||
|
|
||||||
|
const char *detail = NULL;
|
||||||
|
|
||||||
js_getproperty(J, 2, "bubbles");
|
js_getproperty(J, 2, "bubbles");
|
||||||
event->bubbles = js_toboolean(J, -1);
|
bubbles = js_toboolean(J, -1);
|
||||||
js_pop(J, 1);
|
js_pop(J, 1);
|
||||||
js_getproperty(J, 2, "cancelable");
|
js_getproperty(J, 2, "cancelable");
|
||||||
event->cancelable = js_toboolean(J, -1);
|
cancelable = js_toboolean(J, -1);
|
||||||
js_pop(J, 1);
|
js_pop(J, 1);
|
||||||
js_getproperty(J, 2, "composed");
|
|
||||||
event->composed = js_toboolean(J, -1);
|
|
||||||
js_pop(J, 1);
|
|
||||||
if (js_hasproperty(J, 2, "detail")) {
|
|
||||||
event->detail = js_ref(J);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (js_hasproperty(J, 2, "detail")) {
|
||||||
|
detail = js_ref(J);
|
||||||
|
}
|
||||||
|
exc = dom_custom_event_init_ns(event, NULL, typ, bubbles, cancelable, detail);
|
||||||
|
|
||||||
|
if (typ) {
|
||||||
|
dom_string_unref(typ);
|
||||||
|
}
|
||||||
js_newobject(J);
|
js_newobject(J);
|
||||||
{
|
{
|
||||||
js_newuserdata(J, "event", event, mjs_customEvent_finalizer);
|
js_newuserdata(J, "event", event, mjs_customEvent_finalizer);
|
||||||
addmethod(J, "preventDefault", mjs_customEvent_preventDefault, 0);
|
addmethod(J, "preventDefault", mjs_customEvent_preventDefault, 0);
|
||||||
addproperty(J, "bubbles", mjs_customEvent_get_property_bubbles, NULL);
|
addproperty(J, "bubbles", mjs_customEvent_get_property_bubbles, NULL);
|
||||||
addproperty(J, "cancelable", mjs_customEvent_get_property_cancelable, NULL);
|
addproperty(J, "cancelable", mjs_customEvent_get_property_cancelable, NULL);
|
||||||
addproperty(J, "composed", mjs_customEvent_get_property_composed, NULL);
|
// addproperty(J, "composed", mjs_customEvent_get_property_composed, NULL);
|
||||||
addproperty(J, "defaultPrevented", mjs_customEvent_get_property_defaultPrevented, NULL);
|
addproperty(J, "defaultPrevented", mjs_customEvent_get_property_defaultPrevented, NULL);
|
||||||
addproperty(J, "detail", mjs_customEvent_get_property_detail, NULL);
|
addproperty(J, "detail", mjs_customEvent_get_property_detail, NULL);
|
||||||
addproperty(J, "type", mjs_customEvent_get_property_type, NULL);
|
addproperty(J, "type", mjs_customEvent_get_property_type, NULL);
|
||||||
|
@ -2824,7 +2824,7 @@ mjs_element_matches(js_State *J)
|
|||||||
}
|
}
|
||||||
void *res = el_match_selector(selector, el);
|
void *res = el_match_selector(selector, el);
|
||||||
|
|
||||||
js_pushboolean(J, res);
|
js_pushboolean(J, res != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -10,11 +10,15 @@
|
|||||||
|
|
||||||
#include "elinks.h"
|
#include "elinks.h"
|
||||||
|
|
||||||
|
#include "document/document.h"
|
||||||
|
#include "document/view.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/libdom/dom.h"
|
||||||
#include "ecmascript/quickjs.h"
|
#include "ecmascript/quickjs.h"
|
||||||
#include "ecmascript/quickjs/event.h"
|
#include "ecmascript/quickjs/event.h"
|
||||||
#include "intl/charsets.h"
|
#include "intl/charsets.h"
|
||||||
#include "terminal/event.h"
|
#include "terminal/event.h"
|
||||||
|
#include "viewer/text/vs.h"
|
||||||
|
|
||||||
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
@ -22,33 +26,29 @@ static JSClassID js_customEvent_class_id;
|
|||||||
|
|
||||||
static JSValue js_customEvent_get_property_bubbles(JSContext *ctx, JSValueConst this_val);
|
static JSValue js_customEvent_get_property_bubbles(JSContext *ctx, JSValueConst this_val);
|
||||||
static JSValue js_customEvent_get_property_cancelable(JSContext *ctx, JSValueConst this_val);
|
static JSValue js_customEvent_get_property_cancelable(JSContext *ctx, JSValueConst this_val);
|
||||||
static JSValue js_customEvent_get_property_composed(JSContext *ctx, JSValueConst this_val);
|
//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_defaultPrevented(JSContext *ctx, JSValueConst this_val);
|
||||||
static JSValue js_customEvent_get_property_detail(JSContext *ctx, JSValueConst this_val);
|
static JSValue js_customEvent_get_property_detail(JSContext *ctx, JSValueConst this_val);
|
||||||
static JSValue js_customEvent_get_property_type(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);
|
static JSValue js_customEvent_preventDefault(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
|
||||||
|
|
||||||
struct eljscustom_event {
|
|
||||||
JSValue detail;
|
|
||||||
char *type_;
|
|
||||||
unsigned int bubbles:1;
|
|
||||||
unsigned int cancelable:1;
|
|
||||||
unsigned int composed:1;
|
|
||||||
unsigned int defaultPrevented:1;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
static
|
||||||
void js_customEvent_finalizer(JSRuntime *rt, JSValue val)
|
void js_customEvent_finalizer(JSRuntime *rt, JSValue val)
|
||||||
{
|
{
|
||||||
REF_JS(val);
|
REF_JS(val);
|
||||||
|
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)JS_GetOpaque(val, js_customEvent_class_id);
|
dom_custom_event *event = (dom_custom_event *)JS_GetOpaque(val, js_customEvent_class_id);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
JS_FreeValueRT(rt, event->detail);
|
JSValue *detail = NULL;
|
||||||
mem_free_if(event->type_);
|
dom_exception exc = dom_custom_event_get_detail(event, &detail);
|
||||||
mem_free(event);
|
|
||||||
|
if (detail) {
|
||||||
|
free(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
dom_event_unref(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ static JSClassDef js_customEvent_class = {
|
|||||||
static const JSCFunctionListEntry js_customEvent_proto_funcs[] = {
|
static const JSCFunctionListEntry js_customEvent_proto_funcs[] = {
|
||||||
JS_CGETSET_DEF("bubbles", js_customEvent_get_property_bubbles, NULL),
|
JS_CGETSET_DEF("bubbles", js_customEvent_get_property_bubbles, NULL),
|
||||||
JS_CGETSET_DEF("cancelable", js_customEvent_get_property_cancelable, NULL),
|
JS_CGETSET_DEF("cancelable", js_customEvent_get_property_cancelable, NULL),
|
||||||
JS_CGETSET_DEF("composed", js_customEvent_get_property_composed, NULL),
|
// JS_CGETSET_DEF("composed", js_customEvent_get_property_composed, NULL),
|
||||||
JS_CGETSET_DEF("defaultPrevented", js_customEvent_get_property_defaultPrevented, NULL),
|
JS_CGETSET_DEF("defaultPrevented", js_customEvent_get_property_defaultPrevented, NULL),
|
||||||
JS_CGETSET_DEF("detail", js_customEvent_get_property_detail, NULL),
|
JS_CGETSET_DEF("detail", js_customEvent_get_property_detail, NULL),
|
||||||
JS_CGETSET_DEF("type", js_customEvent_get_property_type, NULL),
|
JS_CGETSET_DEF("type", js_customEvent_get_property_type, NULL),
|
||||||
@ -75,12 +75,14 @@ js_customEvent_get_property_bubbles(JSContext *ctx, JSValueConst this_val)
|
|||||||
#endif
|
#endif
|
||||||
REF_JS(this_val);
|
REF_JS(this_val);
|
||||||
|
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
dom_custom_event *event = (dom_custom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return JS_NULL;
|
return JS_NULL;
|
||||||
}
|
}
|
||||||
JSValue r = JS_NewBool(ctx, event->bubbles);
|
bool bubbles = false;
|
||||||
|
dom_exception exc = dom_event_get_bubbles(event, &bubbles);
|
||||||
|
JSValue r = JS_NewBool(ctx, bubbles);
|
||||||
|
|
||||||
RETURN_JS(r);
|
RETURN_JS(r);
|
||||||
}
|
}
|
||||||
@ -93,16 +95,19 @@ js_customEvent_get_property_cancelable(JSContext *ctx, JSValueConst this_val)
|
|||||||
#endif
|
#endif
|
||||||
REF_JS(this_val);
|
REF_JS(this_val);
|
||||||
|
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
dom_custom_event *event = (dom_custom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return JS_NULL;
|
return JS_NULL;
|
||||||
}
|
}
|
||||||
JSValue r = JS_NewBool(ctx, event->cancelable);
|
bool cancelable = false;
|
||||||
|
dom_exception exc = dom_event_get_cancelable(event, &cancelable);
|
||||||
|
JSValue r = JS_NewBool(ctx, cancelable);
|
||||||
|
|
||||||
RETURN_JS(r);
|
RETURN_JS(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static JSValue
|
static JSValue
|
||||||
js_customEvent_get_property_composed(JSContext *ctx, JSValueConst this_val)
|
js_customEvent_get_property_composed(JSContext *ctx, JSValueConst this_val)
|
||||||
{
|
{
|
||||||
@ -120,6 +125,7 @@ js_customEvent_get_property_composed(JSContext *ctx, JSValueConst this_val)
|
|||||||
|
|
||||||
RETURN_JS(r);
|
RETURN_JS(r);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static JSValue
|
static JSValue
|
||||||
js_customEvent_get_property_defaultPrevented(JSContext *ctx, JSValueConst this_val)
|
js_customEvent_get_property_defaultPrevented(JSContext *ctx, JSValueConst this_val)
|
||||||
@ -129,12 +135,14 @@ js_customEvent_get_property_defaultPrevented(JSContext *ctx, JSValueConst this_v
|
|||||||
#endif
|
#endif
|
||||||
REF_JS(this_val);
|
REF_JS(this_val);
|
||||||
|
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
dom_custom_event *event = (dom_custom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return JS_NULL;
|
return JS_NULL;
|
||||||
}
|
}
|
||||||
JSValue r = JS_NewBool(ctx, event->defaultPrevented);
|
bool prevented = false;
|
||||||
|
dom_exception exc = dom_event_is_default_prevented(event, &prevented);
|
||||||
|
JSValue r = JS_NewBool(ctx, prevented);
|
||||||
|
|
||||||
RETURN_JS(r);
|
RETURN_JS(r);
|
||||||
}
|
}
|
||||||
@ -147,18 +155,18 @@ js_customEvent_get_property_detail(JSContext *ctx, JSValueConst this_val)
|
|||||||
#endif
|
#endif
|
||||||
REF_JS(this_val);
|
REF_JS(this_val);
|
||||||
|
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
dom_custom_event *event = (dom_custom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return JS_NULL;
|
return JS_NULL;
|
||||||
}
|
}
|
||||||
|
JSValue *detail = NULL;
|
||||||
|
dom_exception exc = dom_custom_event_get_detail(event, &detail);
|
||||||
|
|
||||||
if (JS_IsNull(event->detail)) {
|
if (exc != DOM_NO_ERR || !detail) {
|
||||||
return JS_NULL;
|
return JS_NULL;
|
||||||
}
|
}
|
||||||
JSValue r = event->detail;
|
RETURN_JS(*detail);
|
||||||
|
|
||||||
RETURN_JS(r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -169,17 +177,20 @@ js_customEvent_get_property_type(JSContext *ctx, JSValueConst this_val)
|
|||||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
REF_JS(this_val);
|
REF_JS(this_val);
|
||||||
|
struct dom_custom_event *event = (dom_custom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return JS_NULL;
|
return JS_NULL;
|
||||||
}
|
}
|
||||||
if (!event->type_) {
|
dom_string *typ = NULL;
|
||||||
|
dom_exception exc = dom_event_get_type(event, &typ);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !typ) {
|
||||||
JSValue r = JS_NewString(ctx, "");
|
JSValue r = JS_NewString(ctx, "");
|
||||||
RETURN_JS(r);
|
RETURN_JS(r);
|
||||||
}
|
}
|
||||||
JSValue r = JS_NewString(ctx, event->type_);
|
JSValue r = JS_NewString(ctx, dom_string_data(typ));
|
||||||
|
dom_string_unref(typ);
|
||||||
|
|
||||||
RETURN_JS(r);
|
RETURN_JS(r);
|
||||||
}
|
}
|
||||||
@ -192,14 +203,13 @@ js_customEvent_preventDefault(JSContext *ctx, JSValueConst this_val, int argc, J
|
|||||||
#endif
|
#endif
|
||||||
REF_JS(this_val);
|
REF_JS(this_val);
|
||||||
|
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
dom_custom_event *event = (dom_custom_event *)(JS_GetOpaque(this_val, js_customEvent_class_id));
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return JS_NULL;
|
return JS_NULL;
|
||||||
}
|
}
|
||||||
if (event->cancelable) {
|
dom_event_prevent_default(event);
|
||||||
event->defaultPrevented = 1;
|
|
||||||
}
|
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,36 +227,65 @@ js_customEvent_constructor(JSContext *ctx, JSValueConst new_target, int argc, JS
|
|||||||
if (JS_IsException(obj)) {
|
if (JS_IsException(obj)) {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)mem_calloc(1, sizeof(*event));
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||||
|
struct view_state *vs = interpreter->vs;
|
||||||
if (!event) {
|
if (!vs) {
|
||||||
JS_FreeValue(ctx, obj);
|
|
||||||
return JS_EXCEPTION;
|
return JS_EXCEPTION;
|
||||||
}
|
}
|
||||||
event->detail = JS_NULL;
|
struct document_view *doc_view = vs->doc_view;
|
||||||
|
struct document *document = doc_view->document;
|
||||||
|
|
||||||
|
if (!document->dom) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
dom_custom_event *event = NULL;
|
||||||
|
dom_string *CustomEventStr = NULL;
|
||||||
|
dom_exception exc = dom_string_create("CustomEvent", sizeof("CustomEvent") - 1, &CustomEventStr);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !CustomEventStr) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
exc = dom_document_event_create_event(document->dom, CustomEventStr, &event);
|
||||||
|
dom_string_unref(CustomEventStr);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
dom_string *typ = NULL;
|
||||||
|
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
const char *str;
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
const char *tt = JS_ToCStringLen(ctx, &len, argv[0]);
|
||||||
|
|
||||||
str = JS_ToCStringLen(ctx, &len, argv[0]);
|
if (!tt) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
if (str) {
|
|
||||||
event->type_ = memacpy(str, len);
|
|
||||||
JS_FreeCString(ctx, str);
|
|
||||||
}
|
}
|
||||||
|
exc = dom_string_create((const uint8_t *)tt, strlen(tt), &typ);
|
||||||
|
JS_FreeCString(ctx, tt);
|
||||||
}
|
}
|
||||||
|
bool bubbles = false;
|
||||||
|
bool cancelable = false;
|
||||||
|
|
||||||
|
JSValue *detail = NULL;
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
JSValue r = JS_GetPropertyStr(ctx, argv[1], "bubbles");
|
JSValue r = JS_GetPropertyStr(ctx, argv[1], "bubbles");
|
||||||
event->bubbles = JS_ToBool(ctx, r);
|
bubbles = JS_ToBool(ctx, r);
|
||||||
r = JS_GetPropertyStr(ctx, argv[1], "cancelable");
|
r = JS_GetPropertyStr(ctx, argv[1], "cancelable");
|
||||||
event->cancelable = JS_ToBool(ctx, r);
|
cancelable = JS_ToBool(ctx, r);
|
||||||
r = JS_GetPropertyStr(ctx, argv[1], "composed");
|
//r = JS_GetPropertyStr(ctx, argv[1], "composed");
|
||||||
event->composed = JS_ToBool(ctx, r);
|
//composed = JS_ToBool(ctx, r);
|
||||||
event->detail = JS_GetPropertyStr(ctx, argv[1], "detail");
|
detail = calloc(1, sizeof(*detail));
|
||||||
}
|
|
||||||
|
|
||||||
|
if (detail) {
|
||||||
|
*detail = JS_GetPropertyStr(ctx, argv[1], "detail");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exc = dom_custom_event_init_ns(event, NULL, typ, bubbles, cancelable, detail);
|
||||||
|
|
||||||
|
if (typ) {
|
||||||
|
dom_string_unref(typ);
|
||||||
|
}
|
||||||
JS_SetOpaque(obj, event);
|
JS_SetOpaque(obj, event);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -2947,7 +2947,7 @@ js_element_matches(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst
|
|||||||
void *res = el_match_selector(selector, el);
|
void *res = el_match_selector(selector, el);
|
||||||
JS_FreeCString(ctx, selector);
|
JS_FreeCString(ctx, selector);
|
||||||
|
|
||||||
return JS_NewBool(ctx, res);
|
return JS_NewBool(ctx, res != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSValue
|
static JSValue
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#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/libdom/dom.h"
|
||||||
#include "ecmascript/spidermonkey.h"
|
#include "ecmascript/spidermonkey.h"
|
||||||
#include "ecmascript/spidermonkey/customevent.h"
|
#include "ecmascript/spidermonkey/customevent.h"
|
||||||
#include "ecmascript/spidermonkey/heartbeat.h"
|
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||||
@ -58,15 +59,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct eljscustom_event {
|
|
||||||
JS::RootedObject detail;
|
|
||||||
char *type_;
|
|
||||||
unsigned int bubbles:1;
|
|
||||||
unsigned int cancelable:1;
|
|
||||||
unsigned int composed:1;
|
|
||||||
unsigned int defaultPrevented:1;
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool customEvent_get_property_bubbles(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool customEvent_get_property_bubbles(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool customEvent_get_property_cancelable(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool customEvent_get_property_cancelable(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool customEvent_get_property_composed(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool customEvent_get_property_composed(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
@ -82,12 +74,10 @@ customEvent_finalize(JS::GCContext *op, JSObject *customEvent_obj)
|
|||||||
#ifdef ECMASCRIPT_DEBUG
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
|
dom_custom_event *event = JS::GetMaybePtrFromReservedSlot<dom_custom_event>(customEvent_obj, 0);
|
||||||
struct eljscustom_event *event = JS::GetMaybePtrFromReservedSlot<struct eljscustom_event>(customEvent_obj, 0);
|
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
mem_free_if(event->type_);
|
dom_event_unref(event);
|
||||||
mem_free(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,35 +119,67 @@ customEvent_constructor(JSContext* ctx, unsigned argc, JS::Value* vp)
|
|||||||
if (!newObj) {
|
if (!newObj) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)mem_calloc(1, sizeof(*event));
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
struct view_state *vs = interpreter->vs;
|
||||||
|
if (!vs) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct document_view *doc_view = vs->doc_view;
|
||||||
|
struct document *document = doc_view->document;
|
||||||
|
|
||||||
if (!event) {
|
if (!document->dom) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
dom_custom_event *event = NULL;
|
||||||
|
dom_string *CustomEventStr = NULL;
|
||||||
|
dom_exception exc = dom_string_create("CustomEvent", sizeof("CustomEvent") - 1, &CustomEventStr);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !CustomEventStr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
exc = dom_document_event_create_event(document->dom, CustomEventStr, &event);
|
||||||
|
dom_string_unref(CustomEventStr);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
JS::SetReservedSlot(newObj, 0, JS::PrivateValue(event));
|
JS::SetReservedSlot(newObj, 0, JS::PrivateValue(event));
|
||||||
|
dom_string *typ = NULL;
|
||||||
|
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
event->type_ = jsval_to_string(ctx, args[0]);
|
char *tt = jsval_to_string(ctx, args[0]);
|
||||||
|
|
||||||
|
if (tt) {
|
||||||
|
exc = dom_string_create((const uint8_t *)tt, strlen(tt), &typ);
|
||||||
|
mem_free(tt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
bool bubbles = false;
|
||||||
|
bool cancelable = false;
|
||||||
|
JSObject *detail = NULL;
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
JS::RootedValue v(ctx);
|
JS::RootedValue v(ctx);
|
||||||
JS::RootedObject v_obj(ctx, &args[1].toObject());
|
JS::RootedObject v_obj(ctx, &args[1].toObject());
|
||||||
|
|
||||||
if (JS_GetProperty(ctx, v_obj, "bubbles", &v)) {
|
if (JS_GetProperty(ctx, v_obj, "bubbles", &v)) {
|
||||||
event->bubbles = (unsigned int)v.toBoolean();
|
bubbles = (unsigned int)v.toBoolean();
|
||||||
}
|
}
|
||||||
if (JS_GetProperty(ctx, v_obj, "cancelable", &v)) {
|
if (JS_GetProperty(ctx, v_obj, "cancelable", &v)) {
|
||||||
event->cancelable = (unsigned int)v.toBoolean();
|
cancelable = (unsigned int)v.toBoolean();
|
||||||
}
|
|
||||||
if (JS_GetProperty(ctx, v_obj, "composed", &v)) {
|
|
||||||
event->composed = (unsigned int)v.toBoolean();
|
|
||||||
}
|
}
|
||||||
|
// if (JS_GetProperty(ctx, v_obj, "composed", &v)) {
|
||||||
|
// event->composed = (unsigned int)v.toBoolean();
|
||||||
|
// }
|
||||||
if (JS_GetProperty(ctx, v_obj, "detail", &v)) {
|
if (JS_GetProperty(ctx, v_obj, "detail", &v)) {
|
||||||
JS::RootedObject vv(ctx, &v.toObject());
|
JS::RootedObject vv(ctx, &v.toObject());
|
||||||
event->detail = vv;
|
detail = vv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exc = dom_custom_event_init_ns(event, NULL, typ, bubbles, cancelable, detail);
|
||||||
|
if (typ) {
|
||||||
|
dom_string_unref(typ);
|
||||||
|
}
|
||||||
args.rval().setObject(*newObj);
|
args.rval().setObject(*newObj);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -166,7 +188,7 @@ customEvent_constructor(JSContext* ctx, unsigned argc, JS::Value* vp)
|
|||||||
JSPropertySpec customEvent_props[] = {
|
JSPropertySpec customEvent_props[] = {
|
||||||
JS_PSG("bubbles", customEvent_get_property_bubbles, JSPROP_ENUMERATE),
|
JS_PSG("bubbles", customEvent_get_property_bubbles, JSPROP_ENUMERATE),
|
||||||
JS_PSG("cancelable", customEvent_get_property_cancelable, JSPROP_ENUMERATE),
|
JS_PSG("cancelable", customEvent_get_property_cancelable, JSPROP_ENUMERATE),
|
||||||
JS_PSG("composed", customEvent_get_property_composed, JSPROP_ENUMERATE),
|
// JS_PSG("composed", customEvent_get_property_composed, JSPROP_ENUMERATE),
|
||||||
JS_PSG("defaultPrevented", customEvent_get_property_defaultPrevented, JSPROP_ENUMERATE),
|
JS_PSG("defaultPrevented", customEvent_get_property_defaultPrevented, JSPROP_ENUMERATE),
|
||||||
JS_PSG("detail", customEvent_get_property_detail, JSPROP_ENUMERATE),
|
JS_PSG("detail", customEvent_get_property_detail, JSPROP_ENUMERATE),
|
||||||
JS_PSG("type", customEvent_get_property_type, JSPROP_ENUMERATE),
|
JS_PSG("type", customEvent_get_property_type, JSPROP_ENUMERATE),
|
||||||
@ -194,12 +216,14 @@ customEvent_get_property_bubbles(JSContext *ctx, unsigned int argc, JS::Value *v
|
|||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
struct eljscustom_event *event = JS::GetMaybePtrFromReservedSlot<struct eljscustom_event>(hobj, 0);
|
dom_custom_event *event = JS::GetMaybePtrFromReservedSlot<dom_custom_event>(hobj, 0);
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
args.rval().setBoolean(event->bubbles);
|
bool bubbles = false;
|
||||||
|
dom_exception exc = dom_event_get_bubbles(event, &bubbles);
|
||||||
|
args.rval().setBoolean(bubbles);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -220,16 +244,19 @@ customEvent_get_property_cancelable(JSContext *ctx, unsigned int argc, JS::Value
|
|||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
struct eljscustom_event *event = JS::GetMaybePtrFromReservedSlot<struct eljscustom_event>(hobj, 0);
|
dom_custom_event *event = JS::GetMaybePtrFromReservedSlot<dom_custom_event>(hobj, 0);
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
args.rval().setBoolean(event->cancelable);
|
bool cancelable = false;
|
||||||
|
dom_exception exc = dom_event_get_cancelable(event, &cancelable);
|
||||||
|
args.rval().setBoolean(cancelable);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static bool
|
static bool
|
||||||
customEvent_get_property_composed(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
customEvent_get_property_composed(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
@ -255,6 +282,7 @@ customEvent_get_property_composed(JSContext *ctx, unsigned int argc, JS::Value *
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
customEvent_get_property_defaultPrevented(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
customEvent_get_property_defaultPrevented(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
@ -272,12 +300,14 @@ customEvent_get_property_defaultPrevented(JSContext *ctx, unsigned int argc, JS:
|
|||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
struct eljscustom_event *event = JS::GetMaybePtrFromReservedSlot<struct eljscustom_event>(hobj, 0);
|
dom_custom_event *event = JS::GetMaybePtrFromReservedSlot<dom_custom_event>(hobj, 0);
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
args.rval().setBoolean(event->defaultPrevented);
|
bool prevented = false;
|
||||||
|
dom_exception exc = dom_event_is_default_prevented(event, &prevented);
|
||||||
|
args.rval().setBoolean(prevented);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -298,16 +328,18 @@ customEvent_get_property_detail(JSContext *ctx, unsigned int argc, JS::Value *vp
|
|||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
struct eljscustom_event *event = JS::GetMaybePtrFromReservedSlot<struct eljscustom_event>(hobj, 0);
|
dom_custom_event *event = JS::GetMaybePtrFromReservedSlot<dom_custom_event>(hobj, 0);
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!event->detail) {
|
void *detail = NULL;
|
||||||
args.rval().setNull();
|
dom_exception exc = dom_custom_event_get_detail(event, &detail);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !detail) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
args.rval().setObject(*event->detail);
|
args.rval().setObject(*(JSObject *)detail);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -328,14 +360,12 @@ customEvent_preventDefault(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
struct eljscustom_event *event = JS::GetMaybePtrFromReservedSlot<struct eljscustom_event>(hobj, 0);
|
dom_custom_event *event = JS::GetMaybePtrFromReservedSlot<dom_custom_event>(hobj, 0);
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (event->cancelable) {
|
dom_event_prevent_default(event);
|
||||||
event->defaultPrevented = 1;
|
|
||||||
}
|
|
||||||
args.rval().setUndefined();
|
args.rval().setUndefined();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -357,17 +387,20 @@ customEvent_get_property_type(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
struct eljscustom_event *event = JS::GetMaybePtrFromReservedSlot<struct eljscustom_event>(hobj, 0);
|
dom_custom_event *event = JS::GetMaybePtrFromReservedSlot<dom_custom_event>(hobj, 0);
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
dom_string *typ = NULL;
|
||||||
|
dom_exception exc = dom_event_get_type(event, &typ);
|
||||||
|
|
||||||
if (!event->type_) {
|
if (exc != DOM_NO_ERR || !typ) {
|
||||||
args.rval().setString(JS_NewStringCopyZ(ctx, ""));
|
args.rval().setString(JS_NewStringCopyZ(ctx, ""));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
args.rval().setString(JS_NewStringCopyZ(ctx, event->type_));
|
args.rval().setString(JS_NewStringCopyZ(ctx, dom_string_data(typ)));
|
||||||
|
dom_string_unref(typ);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -383,9 +416,10 @@ get_customEvent(JSContext *ctx)
|
|||||||
JS::RootedObject r_event(ctx, k);
|
JS::RootedObject r_event(ctx, k);
|
||||||
JS_DefineProperties(ctx, r_event, (JSPropertySpec *)customEvent_props);
|
JS_DefineProperties(ctx, r_event, (JSPropertySpec *)customEvent_props);
|
||||||
|
|
||||||
struct eljscustom_event *event = (struct eljscustom_event *)mem_calloc(1, sizeof(*event));
|
dom_custom_event *event = NULL;
|
||||||
|
dom_exception exc = dom_event_create(&event);
|
||||||
|
|
||||||
if (!event) {
|
if (exc != DOM_NO_ERR) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
JS::SetReservedSlot(k, 0, JS::PrivateValue(event));
|
JS::SetReservedSlot(k, 0, JS::PrivateValue(event));
|
||||||
|
@ -4823,7 +4823,7 @@ element_matches(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
void *res = el_match_selector(selector, el);
|
void *res = el_match_selector(selector, el);
|
||||||
mem_free(selector);
|
mem_free(selector);
|
||||||
|
|
||||||
args.rval().setBoolean(res);
|
args.rval().setBoolean(res != NULL);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
test/ecmascript/assert/customEvent.html
Normal file
12
test/ecmascript/assert/customEvent.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<script>
|
||||||
|
var e = new CustomEvent('message', { cancelable: true, detail: {name:"cat"}});
|
||||||
|
|
||||||
|
console.error('customEvent.html');
|
||||||
|
console.assert(e.cancelable, 'cancelable')
|
||||||
|
console.assert(!e.defaultPrevented, 'defaultPrevented false');
|
||||||
|
e.preventDefault();
|
||||||
|
console.assert(e.defaultPrevented, 'defaultPrevented true');
|
||||||
|
console.assert(e.type === 'message', 'message');
|
||||||
|
console.assert(e.detail.name === 'cat', 'cat');
|
||||||
|
console.exit(0);
|
||||||
|
</script>
|
Loading…
Reference in New Issue
Block a user