mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
[quickjs] Image constructor
This commit is contained in:
parent
4892a07463
commit
acf5abd4b7
@ -34,6 +34,7 @@
|
|||||||
#include "js/quickjs/fragment.h"
|
#include "js/quickjs/fragment.h"
|
||||||
#include "js/quickjs/heartbeat.h"
|
#include "js/quickjs/heartbeat.h"
|
||||||
#include "js/quickjs/history.h"
|
#include "js/quickjs/history.h"
|
||||||
|
#include "js/quickjs/image.h"
|
||||||
#include "js/quickjs/keyboard.h"
|
#include "js/quickjs/keyboard.h"
|
||||||
#include "js/quickjs/localstorage.h"
|
#include "js/quickjs/localstorage.h"
|
||||||
#include "js/quickjs/location.h"
|
#include "js/quickjs/location.h"
|
||||||
@ -354,6 +355,7 @@ quickjs_get_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
js_domparser_init(ctx);
|
js_domparser_init(ctx);
|
||||||
js_node_init(ctx);
|
js_node_init(ctx);
|
||||||
js_fragment_init(ctx);
|
js_fragment_init(ctx);
|
||||||
|
js_image_init(ctx);
|
||||||
|
|
||||||
interpreter->document_obj = getDocument(ctx, document->dom);
|
interpreter->document_obj = getDocument(ctx, document->dom);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
top_builddir=../../..
|
top_builddir=../../..
|
||||||
include $(top_builddir)/Makefile.config
|
include $(top_builddir)/Makefile.config
|
||||||
|
|
||||||
OBJS = attr.o attributes.o collection.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 \
|
OBJS = attr.o attributes.o collection.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 image.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 text.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
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
158
src/js/quickjs/image.c
Normal file
158
src/js/quickjs/image.c
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
/* The QuickJS Image object implementation. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_LIBDOM
|
||||||
|
#include <dom/dom.h>
|
||||||
|
#include <dom/bindings/hubbub/parser.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "elinks.h"
|
||||||
|
|
||||||
|
#include "bfu/dialog.h"
|
||||||
|
#include "cache/cache.h"
|
||||||
|
#include "cookies/cookies.h"
|
||||||
|
#include "dialogs/menu.h"
|
||||||
|
#include "dialogs/status.h"
|
||||||
|
#include "document/html/frames.h"
|
||||||
|
#include "document/document.h"
|
||||||
|
#include "document/forms.h"
|
||||||
|
#include "document/view.h"
|
||||||
|
#include "js/ecmascript.h"
|
||||||
|
#include "js/quickjs.h"
|
||||||
|
#include "js/quickjs/document.h"
|
||||||
|
#include "js/quickjs/heartbeat.h"
|
||||||
|
#include "js/quickjs/image.h"
|
||||||
|
#include "js/quickjs/node.h"
|
||||||
|
#include "js/timer.h"
|
||||||
|
#include "intl/libintl.h"
|
||||||
|
#include "main/select.h"
|
||||||
|
#include "main/timer.h"
|
||||||
|
#include "network/connection.h"
|
||||||
|
#include "osdep/newwin.h"
|
||||||
|
#include "osdep/sysname.h"
|
||||||
|
#include "protocol/http/http.h"
|
||||||
|
#include "protocol/uri.h"
|
||||||
|
#include "session/download.h"
|
||||||
|
#include "session/history.h"
|
||||||
|
#include "session/location.h"
|
||||||
|
#include "session/session.h"
|
||||||
|
#include "session/task.h"
|
||||||
|
#include "terminal/tab.h"
|
||||||
|
#include "terminal/terminal.h"
|
||||||
|
#include "util/conv.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
#include "util/qs_parse/qs_parse.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
#include "viewer/text/draw.h"
|
||||||
|
#include "viewer/text/form.h"
|
||||||
|
#include "viewer/text/link.h"
|
||||||
|
#include "viewer/text/vs.h"
|
||||||
|
|
||||||
|
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
|
static JSClassID js_image_class_id;
|
||||||
|
|
||||||
|
static JSValue
|
||||||
|
js_image_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||||
|
JSValue document_obj = interpreter->document_obj;
|
||||||
|
dom_html_document *doc = (struct dom_html_document *)js_doc_getopaque(document_obj);
|
||||||
|
|
||||||
|
if (!doc) {
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dom_string *tag_name = NULL;
|
||||||
|
dom_exception exc = dom_string_create((const uint8_t *)"img", 3, &tag_name);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !tag_name) {
|
||||||
|
//dom_node_unref(doc);
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
dom_element *element = NULL;
|
||||||
|
exc = dom_document_create_element(doc, tag_name, &element);
|
||||||
|
dom_string_unref(tag_name);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !element) {
|
||||||
|
//dom_node_unref(doc);
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
//dom_node_unref(doc);
|
||||||
|
JSValue rr = getNode(ctx, element);
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
dom_node_unref(element);
|
||||||
|
|
||||||
|
return rr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
JS_NewGlobalCConstructor2(JSContext *ctx, JSValue func_obj, const char *name, JSValueConst proto)
|
||||||
|
{
|
||||||
|
REF_JS(func_obj);
|
||||||
|
REF_JS(proto);
|
||||||
|
|
||||||
|
JSValue global_object = JS_GetGlobalObject(ctx);
|
||||||
|
|
||||||
|
JS_DefinePropertyValueStr(ctx, global_object, name,
|
||||||
|
JS_DupValue(ctx, func_obj), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
|
||||||
|
JS_SetConstructor(ctx, func_obj, proto);
|
||||||
|
JS_FreeValue(ctx, func_obj);
|
||||||
|
JS_FreeValue(ctx, global_object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValueConst
|
||||||
|
JS_NewGlobalCConstructor(JSContext *ctx, const char *name, JSCFunction *func, int length, JSValueConst proto)
|
||||||
|
{
|
||||||
|
JSValue func_obj;
|
||||||
|
func_obj = JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_constructor_or_func, 0);
|
||||||
|
REF_JS(func_obj);
|
||||||
|
REF_JS(proto);
|
||||||
|
|
||||||
|
JS_NewGlobalCConstructor2(ctx, func_obj, name, proto);
|
||||||
|
|
||||||
|
return func_obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSClassDef js_image_class = {
|
||||||
|
"Image",
|
||||||
|
};
|
||||||
|
|
||||||
|
static const JSCFunctionListEntry js_image_proto_funcs[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
js_image_init(JSContext *ctx)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JSValue proto;
|
||||||
|
|
||||||
|
/* urlSearchParams class */
|
||||||
|
JS_NewClassID(&js_image_class_id);
|
||||||
|
JS_NewClass(JS_GetRuntime(ctx), js_image_class_id, &js_image_class);
|
||||||
|
proto = JS_NewObject(ctx);
|
||||||
|
REF_JS(proto);
|
||||||
|
|
||||||
|
JS_SetPropertyFunctionList(ctx, proto, js_image_proto_funcs, countof(js_image_proto_funcs));
|
||||||
|
JS_SetClassProto(ctx, js_image_class_id, proto);
|
||||||
|
|
||||||
|
/* Image object */
|
||||||
|
(void)JS_NewGlobalCConstructor(ctx, "Image", js_image_constructor, 1, proto);
|
||||||
|
//REF_JS(obj);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
16
src/js/quickjs/image.h
Normal file
16
src/js/quickjs/image.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef EL__JS_QUICKJS_IMAGE_H
|
||||||
|
#define EL__JS_QUICKJS_IMAGE_H
|
||||||
|
|
||||||
|
#include <quickjs/quickjs.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int js_image_init(JSContext *ctx);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,4 @@
|
|||||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'css.c', 'customevent.c', 'dataset.c', 'document.c', 'domparser.c', 'domrect.c',
|
srcs += files('attr.c', 'attributes.c', 'collection.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',
|
'element.c', 'event.c', 'form.c', 'forms.c', 'fragment.c', 'heartbeat.c', 'history.c',
|
||||||
'implementation.c', 'input.c', 'keyboard.c', 'localstorage.c', 'location.c',
|
'image.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', 'text.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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user