mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[quickjs] text.c
This commit is contained in:
parent
19fc56f737
commit
1fac4b58c3
@ -31,6 +31,7 @@
|
||||
#include "ecmascript/quickjs/domparser.h"
|
||||
#include "ecmascript/quickjs/element.h"
|
||||
#include "ecmascript/quickjs/event.h"
|
||||
#include "ecmascript/quickjs/fragment.h"
|
||||
#include "ecmascript/quickjs/heartbeat.h"
|
||||
#include "ecmascript/quickjs/history.h"
|
||||
#include "ecmascript/quickjs/keyboard.h"
|
||||
@ -41,6 +42,7 @@
|
||||
#include "ecmascript/quickjs/navigator.h"
|
||||
#include "ecmascript/quickjs/node.h"
|
||||
#include "ecmascript/quickjs/screen.h"
|
||||
#include "ecmascript/quickjs/text.h"
|
||||
#include "ecmascript/quickjs/unibar.h"
|
||||
#include "ecmascript/quickjs/url.h"
|
||||
#include "ecmascript/quickjs/urlsearchparams.h"
|
||||
|
@ -2,6 +2,6 @@ top_builddir=../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
|
||||
OBJS = attr.o attributes.o collection.o collection2.o console.o css.o customevent.o dataset.o document.o domparser.o domrect.o element.o event.o form.o forms.o fragment.o heartbeat.o history.o implementation.o input.o \
|
||||
keyboard.o localstorage.o location.o mapa.o message.o navigator.o node.o nodelist.o nodelist2.o screen.o style.o tokenlist.o unibar.o url.o urlsearchparams.o window.o xhr.o
|
||||
keyboard.o localstorage.o location.o mapa.o message.o navigator.o node.o nodelist.o nodelist2.o screen.o style.o text.o tokenlist.o unibar.o url.o urlsearchparams.o window.o xhr.o
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "ecmascript/quickjs/element.h"
|
||||
#include "ecmascript/quickjs/nodelist.h"
|
||||
#include "ecmascript/quickjs/nodelist2.h"
|
||||
#include "ecmascript/quickjs/text.h"
|
||||
#include "ecmascript/quickjs/window.h"
|
||||
#include "session/session.h"
|
||||
#include "viewer/text/vs.h"
|
||||
@ -83,6 +84,12 @@ js_doc_getopaque(JSValueConst obj)
|
||||
return res->node;
|
||||
}
|
||||
|
||||
void *
|
||||
document_get_node(JSValueConst obj)
|
||||
{
|
||||
return js_doc_getopaque(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
js_document_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)
|
||||
{
|
||||
@ -1415,7 +1422,7 @@ js_document_createTextNode(JSContext *ctx, JSValueConst this_val, int argc, JSVa
|
||||
}
|
||||
//dom_node_unref(doc);
|
||||
|
||||
return getElement(ctx, text_node);
|
||||
return getText(ctx, text_node);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
|
@ -8,6 +8,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
void *js_doc_getopaque(JSValueConst obj);
|
||||
void *document_get_node(JSValueConst obj);
|
||||
JSValue getDocument(JSContext *ctx, void *doc);
|
||||
JSValue getDocument2(JSContext *ctx, void *doc);
|
||||
|
||||
|
@ -30,14 +30,17 @@
|
||||
#include "ecmascript/quickjs/attributes.h"
|
||||
#include "ecmascript/quickjs/collection.h"
|
||||
#include "ecmascript/quickjs/dataset.h"
|
||||
#include "ecmascript/quickjs/document.h"
|
||||
#include "ecmascript/quickjs/domrect.h"
|
||||
#include "ecmascript/quickjs/element.h"
|
||||
#include "ecmascript/quickjs/event.h"
|
||||
#include "ecmascript/quickjs/fragment.h"
|
||||
#include "ecmascript/quickjs/heartbeat.h"
|
||||
#include "ecmascript/quickjs/keyboard.h"
|
||||
#include "ecmascript/quickjs/nodelist.h"
|
||||
#include "ecmascript/quickjs/nodelist2.h"
|
||||
#include "ecmascript/quickjs/style.h"
|
||||
#include "ecmascript/quickjs/text.h"
|
||||
#include "ecmascript/quickjs/tokenlist.h"
|
||||
#include "ecmascript/quickjs/window.h"
|
||||
#include "session/session.h"
|
||||
@ -89,6 +92,28 @@ js_getopaque(JSValueConst obj, JSClassID class_id)
|
||||
return res->node;
|
||||
}
|
||||
|
||||
void *
|
||||
js_getopaque_any(JSValueConst obj)
|
||||
{
|
||||
REF_JS(obj);
|
||||
struct js_element_private *res = (struct js_element_private *)JS_GetOpaque(obj, js_element_class_id);
|
||||
|
||||
if (res) {
|
||||
return res->node;
|
||||
}
|
||||
void *n = document_get_node(obj);
|
||||
|
||||
if (n) {
|
||||
return n;
|
||||
}
|
||||
n = fragment_get_node(obj);
|
||||
|
||||
if (n) {
|
||||
return n;
|
||||
}
|
||||
return text_get_node(obj);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_element_get_property_attributes(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
@ -1015,6 +1040,42 @@ js_element_get_property_nodeValue(JSContext *ctx, JSValueConst this_val)
|
||||
RETURN_JS(r);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_element_set_property_nodeValue(JSContext *ctx, JSValueConst this_val, JSValue val)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
dom_node *node = (dom_node *)(js_getopaque(this_val, js_element_class_id));
|
||||
JSValue r;
|
||||
|
||||
if (!node) {
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
size_t len;
|
||||
const char *str = JS_ToCStringLen(ctx, &len, val);
|
||||
|
||||
if (!str) {
|
||||
//dom_node_unref(el);
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
dom_string *value = NULL;
|
||||
dom_exception exc = dom_string_create((const uint8_t *)str, len, &value);
|
||||
JS_FreeCString(ctx, str);
|
||||
|
||||
if (exc != DOM_NO_ERR || !value) {
|
||||
//dom_node_unref(el);
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
exc = dom_node_set_node_value(node, value);
|
||||
dom_string_unref(value);
|
||||
//dom_node_unref(el);
|
||||
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_element_get_property_nextSibling(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
@ -2559,7 +2620,7 @@ js_element_appendChild(JSContext *ctx, JSValueConst this_val, int argc, JSValueC
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
//dom_node_ref(el);
|
||||
dom_node *el2 = (dom_node *)(js_getopaque(argv[0], js_element_class_id));
|
||||
dom_node *el2 = (dom_node *)js_getopaque_any(argv[0]);
|
||||
|
||||
if (!el2) {
|
||||
//dom_node_unref(el);
|
||||
@ -3718,7 +3779,7 @@ static const JSCFunctionListEntry js_element_proto_funcs[] = {
|
||||
JS_CGETSET_DEF("nextSibling", js_element_get_property_nextSibling, NULL),
|
||||
JS_CGETSET_DEF("nodeName", js_element_get_property_nodeName, NULL), // Node
|
||||
JS_CGETSET_DEF("nodeType", js_element_get_property_nodeType, NULL), // Node
|
||||
JS_CGETSET_DEF("nodeValue", js_element_get_property_nodeValue, NULL), // Node
|
||||
JS_CGETSET_DEF("nodeValue", js_element_get_property_nodeValue, js_element_set_property_nodeValue), // Node
|
||||
// JS_CGETSET_DEF("offsetHeight", js_element_get_property_offsetHeight, NULL),
|
||||
// JS_CGETSET_DEF("offsetLeft", js_element_get_property_offsetLeft, NULL),
|
||||
JS_CGETSET_DEF("offsetParent", js_element_get_property_offsetParent, NULL),
|
||||
|
@ -73,7 +73,6 @@ void *
|
||||
js_getopaque_fragment(JSValueConst obj, JSClassID class_id)
|
||||
{
|
||||
REF_JS(obj);
|
||||
|
||||
struct js_fragment_private *res = (struct js_fragment_private *)JS_GetOpaque(obj, class_id);
|
||||
|
||||
if (!res) {
|
||||
@ -90,6 +89,11 @@ js_getopaque_fragment(JSValueConst obj, JSClassID class_id)
|
||||
return res->node;
|
||||
}
|
||||
|
||||
void *
|
||||
fragment_get_node(JSValueConst obj)
|
||||
{
|
||||
return js_getopaque_fragment(obj, js_fragment_class_id);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_fragment_get_property_children(JSContext *ctx, JSValueConst this_val)
|
||||
@ -1507,6 +1511,7 @@ static const JSCFunctionListEntry js_fragment_proto_funcs[] = {
|
||||
JS_CFUNC_DEF("toString", 0, js_fragment_toString)
|
||||
};
|
||||
|
||||
|
||||
static
|
||||
void js_fragment_finalizer(JSRuntime *rt, JSValue val)
|
||||
{
|
||||
@ -1515,12 +1520,21 @@ void js_fragment_finalizer(JSRuntime *rt, JSValue val)
|
||||
#endif
|
||||
REF_JS(val);
|
||||
|
||||
struct js_fragment_private *el_private = (struct js_fragment_private *)js_getopaque_fragment(val, js_fragment_class_id);
|
||||
struct js_fragment_private *el_private = (struct js_fragment_private *)JS_GetOpaque(val, js_fragment_class_id);
|
||||
|
||||
if (el_private) {
|
||||
struct fragment_listener *l;
|
||||
dom_node *el = (dom_node *)el_private->node;
|
||||
|
||||
if (el_private->listener) {
|
||||
dom_event_listener_unref(el_private->listener);
|
||||
}
|
||||
|
||||
if (el) {
|
||||
// void *old_node_data = NULL;
|
||||
// dom_node_set_user_data(el, corestring_dom___ns_key_html_content_data, NULL, js_html_document_user_data_handler,
|
||||
// (void *) &old_node_data);
|
||||
|
||||
if (el->refcnt > 0) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__);
|
||||
@ -1528,6 +1542,14 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__);
|
||||
dom_node_unref(el);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(l, el_private->listeners) {
|
||||
mem_free_set(&l->typ, NULL);
|
||||
JS_FreeValueRT(rt, l->fun);
|
||||
}
|
||||
free_list(el_private->listeners);
|
||||
JS_FreeValueRT(rt, el_private->thisval);
|
||||
|
||||
mem_free(el_private);
|
||||
}
|
||||
}
|
||||
@ -1540,7 +1562,7 @@ js_fragment_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)
|
||||
#endif
|
||||
REF_JS(val);
|
||||
|
||||
struct js_fragment_private *el_private = (struct js_fragment_private *)js_getopaque_fragment(val, js_fragment_class_id);
|
||||
struct js_fragment_private *el_private = (struct js_fragment_private *)JS_GetOpaque(val, js_fragment_class_id);
|
||||
|
||||
if (el_private) {
|
||||
JS_MarkValue(rt, el_private->thisval, mark_func);
|
||||
@ -1594,8 +1616,12 @@ getDocumentFragment(JSContext *ctx, void *node)
|
||||
if (!el_private) {
|
||||
return JS_NULL;
|
||||
}
|
||||
init_list(el_private->listeners);
|
||||
el_private->node = node;
|
||||
|
||||
JS_NewClassID(&js_fragment_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_fragment_class_id, &js_fragment_class);
|
||||
|
||||
JSValue fragment_obj = JS_NewObjectClass(ctx, js_fragment_class_id);
|
||||
REF_JS(fragment_obj);
|
||||
|
||||
|
@ -9,6 +9,9 @@ extern "C" {
|
||||
|
||||
extern JSClassID js_fragment_class_id;
|
||||
void *js_getopaque_fragment(JSValueConst obj, JSClassID class_id);
|
||||
void *fragment_get_node(JSValueConst obj);
|
||||
|
||||
int js_fragment_init(JSContext *ctx);
|
||||
|
||||
JSValue getDocumentFragment(JSContext *ctx, void *node);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'collection2.c', 'console.c', 'css.c', 'customevent.c', 'dataset.c', 'document.c', 'domparser.c', 'domrect.c',
|
||||
'element.c', 'event.c', 'form.c', 'forms.c', 'fragment.c', 'heartbeat.c', 'history.c',
|
||||
'implementation.c', 'input.c', 'keyboard.c', 'localstorage.c', 'location.c',
|
||||
'mapa.c', 'message.c', 'navigator.c', 'node.c', 'nodelist.c', 'nodelist2.c', 'screen.c', 'style.c', 'tokenlist.c', 'unibar.c', 'url.c', 'urlsearchparams.c', 'window.c', 'xhr.c')
|
||||
'mapa.c', 'message.c', 'navigator.c', 'node.c', 'nodelist.c', 'nodelist2.c', 'screen.c', 'style.c', 'text.c', 'tokenlist.c', 'unibar.c', 'url.c', 'urlsearchparams.c', 'window.c', 'xhr.c')
|
||||
|
1614
src/ecmascript/quickjs/text.c
Normal file
1614
src/ecmascript/quickjs/text.c
Normal file
File diff suppressed because it is too large
Load Diff
21
src/ecmascript/quickjs/text.h
Normal file
21
src/ecmascript/quickjs/text.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef EL__ECMASCRIPT_QUICKJS_TEXT_H
|
||||
#define EL__ECMASCRIPT_QUICKJS_TEXT_H
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern JSClassID js_text_class_id;
|
||||
void *js_getopaque_text(JSValueConst obj, JSClassID class_id);
|
||||
void *text_get_node(JSValueConst obj);
|
||||
int js_text_init(JSContext *ctx);
|
||||
|
||||
JSValue getText(JSContext *ctx, void *node);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user