mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[spidermonkey] attr in separate file
This commit is contained in:
parent
d274eef77f
commit
935d81a08b
@ -2,7 +2,7 @@ top_builddir=../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||
|
||||
OBJS = console.o css2xpath.o document.o element.o form.o heartbeat.o implementation.o location.o \
|
||||
OBJS = attr.o console.o css2xpath.o document.o element.o form.o heartbeat.o implementation.o location.o \
|
||||
localstorage.o localstorage-db.o navigator.o screen.o unibar.o window.o
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
215
src/ecmascript/spidermonkey/attr.c
Normal file
215
src/ecmascript/spidermonkey/attr.c
Normal file
@ -0,0 +1,215 @@
|
||||
/* The SpiderMonkey attr object implementation. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "ecmascript/spidermonkey/util.h"
|
||||
#include <jsfriendapi.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 "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/spidermonkey/attr.h"
|
||||
#include "intl/libintl.h"
|
||||
#include "main/select.h"
|
||||
#include "osdep/newwin.h"
|
||||
#include "osdep/sysname.h"
|
||||
#include "protocol/http/http.h"
|
||||
#include "protocol/uri.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/string.h"
|
||||
#include "viewer/text/draw.h"
|
||||
#include "viewer/text/form.h"
|
||||
#include "viewer/text/link.h"
|
||||
#include "viewer/text/vs.h"
|
||||
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/HTMLparser.h>
|
||||
#include <libxml++/libxml++.h>
|
||||
#include <libxml++/attributenode.h>
|
||||
#include <libxml++/parsers/domparser.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
static bool attr_get_property_name(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool attr_get_property_value(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
|
||||
static void attr_finalize(JSFreeOp *op, JSObject *obj)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
JSClassOps attr_ops = {
|
||||
nullptr, // addProperty
|
||||
nullptr, // deleteProperty
|
||||
nullptr, // enumerate
|
||||
nullptr, // newEnumerate
|
||||
nullptr, // resolve
|
||||
nullptr, // mayResolve
|
||||
attr_finalize, // finalize
|
||||
nullptr, // call
|
||||
nullptr, // hasInstance
|
||||
nullptr, // construct
|
||||
JS_GlobalObjectTraceHook
|
||||
};
|
||||
|
||||
JSClass attr_class = {
|
||||
"attr",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
&attr_ops
|
||||
};
|
||||
|
||||
static JSPropertySpec attr_props[] = {
|
||||
JS_PSG("name", attr_get_property_name, JSPROP_ENUMERATE),
|
||||
JS_PSG("value", attr_get_property_value, JSPROP_ENUMERATE),
|
||||
JS_PS_END
|
||||
};
|
||||
|
||||
static bool
|
||||
attr_get_property_name(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
|
||||
struct view_state *vs;
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp);
|
||||
|
||||
/* This can be called if @obj if not itself an instance of the
|
||||
* appropriate class but has one in its prototype chain. Fail
|
||||
* such calls. */
|
||||
if (!JS_InstanceOf(ctx, hobj, &attr_class, NULL)) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
vs = interpreter->vs;
|
||||
if (!vs) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
xmlpp::AttributeNode *attr = JS_GetPrivate(hobj);
|
||||
|
||||
if (!attr) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
xmlpp::ustring v = attr->get_name();
|
||||
args.rval().setString(JS_NewStringCopyZ(ctx, v.c_str()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
attr_get_property_value(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
|
||||
struct view_state *vs;
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp);
|
||||
|
||||
/* This can be called if @obj if not itself an instance of the
|
||||
* appropriate class but has one in its prototype chain. Fail
|
||||
* such calls. */
|
||||
if (!JS_InstanceOf(ctx, hobj, &attr_class, NULL)) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
vs = interpreter->vs;
|
||||
if (!vs) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
xmlpp::AttributeNode *attr = JS_GetPrivate(hobj);
|
||||
|
||||
if (!attr) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
xmlpp::ustring v = attr->get_value();
|
||||
args.rval().setString(JS_NewStringCopyZ(ctx, v.c_str()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
JSObject *
|
||||
getAttr(JSContext *ctx, void *node)
|
||||
{
|
||||
JSObject *el = JS_NewObject(ctx, &attr_class);
|
||||
|
||||
if (!el) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JS::RootedObject r_el(ctx, el);
|
||||
|
||||
JS_DefineProperties(ctx, r_el, (JSPropertySpec *) attr_props);
|
||||
// spidermonkey_DefineFunctions(ctx, el, attributes_funcs);
|
||||
|
||||
JS_SetPrivate(el, node);
|
||||
|
||||
return el;
|
||||
}
|
8
src/ecmascript/spidermonkey/attr.h
Normal file
8
src/ecmascript/spidermonkey/attr.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef EL__ECMASCRIPT_SPIDERMONKEY_ATTR_H
|
||||
#define EL__ECMASCRIPT_SPIDERMONKEY_ATTR_H
|
||||
|
||||
#include "ecmascript/spidermonkey/util.h"
|
||||
|
||||
JSObject *getAttr(JSContext *ctx, void *node);
|
||||
|
||||
#endif
|
@ -23,6 +23,7 @@
|
||||
#include "document/forms.h"
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/spidermonkey/attr.h"
|
||||
#include "ecmascript/spidermonkey/css2xpath.h"
|
||||
#include "ecmascript/spidermonkey/element.h"
|
||||
#include "ecmascript/spidermonkey/window.h"
|
||||
@ -4226,163 +4227,3 @@ getAttributes(JSContext *ctx, void *node)
|
||||
|
||||
return el;
|
||||
}
|
||||
|
||||
static bool attr_get_property_name(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool attr_get_property_value(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
|
||||
static void attr_finalize(JSFreeOp *op, JSObject *obj)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
JSClassOps attr_ops = {
|
||||
nullptr, // addProperty
|
||||
nullptr, // deleteProperty
|
||||
nullptr, // enumerate
|
||||
nullptr, // newEnumerate
|
||||
nullptr, // resolve
|
||||
nullptr, // mayResolve
|
||||
attr_finalize, // finalize
|
||||
nullptr, // call
|
||||
nullptr, // hasInstance
|
||||
nullptr, // construct
|
||||
JS_GlobalObjectTraceHook
|
||||
};
|
||||
|
||||
JSClass attr_class = {
|
||||
"attr",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
&attr_ops
|
||||
};
|
||||
|
||||
static JSPropertySpec attr_props[] = {
|
||||
JS_PSG("name", attr_get_property_name, JSPROP_ENUMERATE),
|
||||
JS_PSG("value", attr_get_property_value, JSPROP_ENUMERATE),
|
||||
JS_PS_END
|
||||
};
|
||||
|
||||
static bool
|
||||
attr_get_property_name(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
|
||||
struct view_state *vs;
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp);
|
||||
|
||||
/* This can be called if @obj if not itself an instance of the
|
||||
* appropriate class but has one in its prototype chain. Fail
|
||||
* such calls. */
|
||||
if (!JS_InstanceOf(ctx, hobj, &attr_class, NULL)) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
vs = interpreter->vs;
|
||||
if (!vs) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
xmlpp::AttributeNode *attr = JS_GetPrivate(hobj);
|
||||
|
||||
if (!attr) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
xmlpp::ustring v = attr->get_name();
|
||||
args.rval().setString(JS_NewStringCopyZ(ctx, v.c_str()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
attr_get_property_value(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
|
||||
struct view_state *vs;
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp);
|
||||
|
||||
/* This can be called if @obj if not itself an instance of the
|
||||
* appropriate class but has one in its prototype chain. Fail
|
||||
* such calls. */
|
||||
if (!JS_InstanceOf(ctx, hobj, &attr_class, NULL)) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
vs = interpreter->vs;
|
||||
if (!vs) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
xmlpp::AttributeNode *attr = JS_GetPrivate(hobj);
|
||||
|
||||
if (!attr) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
xmlpp::ustring v = attr->get_value();
|
||||
args.rval().setString(JS_NewStringCopyZ(ctx, v.c_str()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
JSObject *
|
||||
getAttr(JSContext *ctx, void *node)
|
||||
{
|
||||
JSObject *el = JS_NewObject(ctx, &attr_class);
|
||||
|
||||
if (!el) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JS::RootedObject r_el(ctx, el);
|
||||
|
||||
JS_DefineProperties(ctx, r_el, (JSPropertySpec *) attr_props);
|
||||
// spidermonkey_DefineFunctions(ctx, el, attributes_funcs);
|
||||
|
||||
JS_SetPrivate(el, node);
|
||||
|
||||
return el;
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ extern JSPropertySpec element_props[];
|
||||
JSObject *getElement(JSContext *ctx, void *node);
|
||||
JSObject *getCollection(JSContext *ctx, void *node);
|
||||
JSObject *getAttributes(JSContext *ctx, void *node);
|
||||
JSObject *getAttr(JSContext *ctx, void *node);
|
||||
JSObject *getNodeList(JSContext *ctx, void *node);
|
||||
|
||||
void walk_tree(struct string *buf, void *nod, bool start = true, bool toSortAttrs = false);
|
||||
|
@ -1,3 +1,3 @@
|
||||
#INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||
|
||||
srcs += files('console.c', 'css2xpath.c', 'document.c', 'element.c', 'form.c', 'heartbeat.c', 'implementation.c', 'location.c', 'localstorage.c', 'localstorage-db.c', 'navigator.c', 'screen.c', 'unibar.c', 'window.c')
|
||||
srcs += files('attr.c', 'console.c', 'css2xpath.c', 'document.c', 'element.c', 'form.c', 'heartbeat.c', 'implementation.c', 'location.c', 'localstorage.c', 'localstorage-db.c', 'navigator.c', 'screen.c', 'unibar.c', 'window.c')
|
||||
|
Loading…
Reference in New Issue
Block a user