1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-27 01:25:34 +00:00

[quickjs] document.readyState

This commit is contained in:
Witold Filipczyk 2024-06-06 21:41:43 +02:00
parent a4a8171d2a
commit 3178bb66a0

View File

@ -50,12 +50,19 @@ struct document_listener {
JSValue fun;
};
enum readyState {
LOADING = 0,
INTERACTIVE,
COMPLETE
};
struct js_document_private {
LIST_OF(struct document_listener) listeners;
struct ecmascript_interpreter *interpreter;
JSValue thisval;
dom_event_listener *listener;
void *node;
enum readyState state;
};
static void document_event_handler(dom_event *event, void *pw);
@ -576,6 +583,34 @@ js_document_set_property_location(JSContext *ctx, JSValueConst this_val, JSValue
return JS_UNDEFINED;
}
static JSValue
js_document_get_property_readyState(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
struct js_document_private *doc_private = (struct js_document_private *)(JS_GetOpaque(this_val, js_document_class_id));
if (!doc_private) {
return JS_NULL;
}
JSValue r;
switch (doc_private->state) {
case LOADING:
r = JS_NewString(ctx, "loading");
break;
case INTERACTIVE:
r = JS_NewString(ctx, "interactive");
break;
case COMPLETE:
r = JS_NewString(ctx, "complete");
break;
}
RETURN_JS(r);
}
static JSValue
js_document_get_property_referrer(JSContext *ctx, JSValueConst this_val)
{
@ -1696,6 +1731,7 @@ static const JSCFunctionListEntry js_document_proto_funcs[] = {
JS_CGETSET_DEF("links", js_document_get_property_links, NULL),
JS_CGETSET_DEF("location", js_document_get_property_location, js_document_set_property_location),
JS_CGETSET_DEF("nodeType", js_document_get_property_nodeType, NULL),
JS_CGETSET_DEF("readyState", js_document_get_property_readyState, NULL),
JS_CGETSET_DEF("referrer", js_document_get_property_referrer, NULL),
JS_CGETSET_DEF("scripts", js_document_get_property_scripts, NULL),
JS_CGETSET_DEF("title", js_document_get_property_title, js_document_set_property_title), /* TODO: Charset? */
@ -1905,6 +1941,10 @@ document_event_handler(dom_event *event, void *pw)
if (exc != DOM_NO_ERR || !typ) {
return;
}
if (!strcmp("DOMContentLoaded", dom_string_data(typ))) {
doc_private->state = COMPLETE;
}
// interpreter->heartbeat = add_heartbeat(interpreter);
struct document_listener *l, *next;