mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
[libdom] dom.h with redefinition of namespace and attr.cpp
namespace is used in function declaration of dom_string.
This commit is contained in:
parent
b5fa0be5e2
commit
7e0a9f47b5
21
src/ecmascript/libdom/dom.h
Normal file
21
src/ecmascript/libdom/dom.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef EL__DOCUMENT_ECMASCRIPT_LIBDOM_DOM_H
|
||||
#define EL__DOCUMENT_ECMASCRIPT_LIBDOM_DOM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define namespace namespace_elinks
|
||||
|
||||
#ifdef CONFIG_LIBDOM
|
||||
#include <dom/dom.h>
|
||||
#include <dom/bindings/hubbub/parser.h>
|
||||
#endif
|
||||
|
||||
#undef namespace
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -2,6 +2,6 @@ top_builddir=../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||
|
||||
OBJS = console.obj heartbeat.obj history.obj keyboard.obj localstorage.obj location.obj message.obj navigator.obj screen.obj unibar.obj window.obj xhr.obj
|
||||
OBJS = attr.obj console.obj heartbeat.obj history.obj keyboard.obj localstorage.obj location.obj message.obj navigator.obj screen.obj unibar.obj window.obj xhr.obj
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
221
src/ecmascript/libdom/spidermonkey/attr.cpp
Normal file
221
src/ecmascript/libdom/spidermonkey/attr.cpp
Normal file
@ -0,0 +1,221 @@
|
||||
/* 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/libdom/dom.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 <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(JS::GCContext *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, // construct
|
||||
JS_GlobalObjectTraceHook
|
||||
};
|
||||
|
||||
JSClass attr_class = {
|
||||
"attr",
|
||||
JSCLASS_HAS_RESERVED_SLOTS(1),
|
||||
&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 = (struct ecmascript_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;
|
||||
}
|
||||
dom_attr *attr = (dom_attr *)JS::GetMaybePtrFromReservedSlot<dom_attr>(hobj, 0);
|
||||
dom_exception err;
|
||||
dom_string *name = NULL;
|
||||
|
||||
if (!attr) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
err = dom_attr_get_name(attr, &name);
|
||||
if (err != DOM_NO_ERR || name == NULL) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
args.rval().setString(JS_NewStringCopyZ(ctx, dom_string_data(name)));
|
||||
dom_string_unref(name);
|
||||
|
||||
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 = (struct ecmascript_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;
|
||||
}
|
||||
dom_attr *attr = (dom_attr *)JS::GetMaybePtrFromReservedSlot<dom_attr>(hobj, 0);
|
||||
dom_string *value = NULL;
|
||||
dom_exception err;
|
||||
|
||||
if (!attr) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
err = dom_attr_get_value(attr, &value);
|
||||
|
||||
if (err != DOM_NO_ERR || value == NULL) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
args.rval().setString(JS_NewStringCopyZ(ctx, dom_string_data(value)));
|
||||
dom_string_unref(value);
|
||||
|
||||
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::SetReservedSlot(el, 0, JS::PrivateValue(node));
|
||||
|
||||
return el;
|
||||
}
|
@ -1 +1 @@
|
||||
srcs += files('console.cpp', 'heartbeat.cpp', 'history.cpp', 'keyboard.cpp', 'localstorage.cpp', 'location.cpp', 'message.cpp', 'navigator.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
||||
srcs += files('attr.cpp', 'console.cpp', 'heartbeat.cpp', 'history.cpp', 'keyboard.cpp', 'localstorage.cpp', 'location.cpp', 'message.cpp', 'navigator.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
||||
|
@ -54,6 +54,8 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#ifndef CONFIG_LIBDOM
|
||||
|
||||
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);
|
||||
|
||||
@ -212,3 +214,4 @@ getAttr(JSContext *ctx, void *node)
|
||||
|
||||
return el;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user