mirror of
https://github.com/rkd77/elinks.git
synced 2024-09-06 23:44:43 -04:00
Merge branch 'master' into write
This commit is contained in:
commit
7d8e92703b
@ -1,4 +1,4 @@
|
||||
/* The QuickJS html element objects implementation. */
|
||||
/* The MuJS html element objects implementation. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@ -1153,7 +1153,7 @@ mjs_element_appendChild(js_State *J)
|
||||
return;
|
||||
}
|
||||
xmlpp::Node *el2 = static_cast<xmlpp::Node *>(mjs_getprivate(J, 1));
|
||||
el->import_node(el2);
|
||||
el2 = el->import_node(el2);
|
||||
interpreter->changed = true;
|
||||
|
||||
mjs_push_element(J, el2);
|
||||
@ -1632,6 +1632,27 @@ mjs_element_removeChild(js_State *J)
|
||||
js_pushnull(J);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_element_replaceWith(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
xmlpp::Element *el = static_cast<xmlpp::Element *>(mjs_getprivate(J, 0));
|
||||
xmlpp::Node *rep = static_cast<xmlpp::Node *>(mjs_getprivate(J, 1));
|
||||
|
||||
if (!el || !rep) {
|
||||
js_pushundefined(J);
|
||||
return;
|
||||
}
|
||||
xmlAddPrevSibling(el->cobj(), rep->cobj());
|
||||
xmlpp::Node::remove_node(el);
|
||||
interpreter->changed = true;
|
||||
|
||||
js_pushundefined(J);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_element_setAttribute(js_State *J)
|
||||
{
|
||||
@ -1742,6 +1763,7 @@ mjs_push_element(js_State *J, void *node)
|
||||
addmethod(J, "remove", mjs_element_remove, 0);
|
||||
addmethod(J, "removeChild", mjs_element_removeChild, 1);
|
||||
addmethod(J, "removeEventListener", mjs_element_removeEventListener, 3);
|
||||
addmethod(J, "replaceWith", mjs_element_replaceWith, 1);
|
||||
addmethod(J, "setAttribute", mjs_element_setAttribute, 2);
|
||||
addmethod(J, "toString", mjs_element_toString, 0);
|
||||
|
||||
|
@ -1181,7 +1181,7 @@ js_element_appendChild(JSContext *ctx, JSValueConst this_val, int argc, JSValueC
|
||||
return JS_NULL;
|
||||
}
|
||||
xmlpp::Node *el2 = static_cast<xmlpp::Node *>(js_getopaque(argv[0], js_element_class_id));
|
||||
el->import_node(el2);
|
||||
el2 = el->import_node(el2);
|
||||
interpreter->changed = true;
|
||||
|
||||
return getElement(ctx, el2);
|
||||
@ -1767,6 +1767,33 @@ js_element_removeChild(JSContext *ctx, JSValueConst this_val, int argc, JSValueC
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_element_replaceWith(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
if (argc < 1) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
xmlpp::Element *el = static_cast<xmlpp::Element *>(js_getopaque(this_val, js_element_class_id));
|
||||
|
||||
if (!el || !JS_IsObject(argv[0])) {
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
JSValue replacement = argv[0];
|
||||
xmlpp::Node *rep = static_cast<xmlpp::Node *>(js_getopaque(replacement, js_element_class_id));
|
||||
xmlAddPrevSibling(el->cobj(), rep->cobj());
|
||||
xmlpp::Node::remove_node(el);
|
||||
interpreter->changed = true;
|
||||
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_element_setAttribute(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||
{
|
||||
@ -1867,6 +1894,7 @@ static const JSCFunctionListEntry js_element_proto_funcs[] = {
|
||||
JS_CFUNC_DEF("remove", 0, js_element_remove),
|
||||
JS_CFUNC_DEF("removeChild",1, js_element_removeChild),
|
||||
JS_CFUNC_DEF("removeEventListener", 3, js_element_removeEventListener),
|
||||
JS_CFUNC_DEF("replaceWith",1, js_element_replaceWith),
|
||||
JS_CFUNC_DEF("setAttribute",2, js_element_setAttribute),
|
||||
|
||||
JS_CFUNC_DEF("toString", 0, js_element_toString)
|
||||
|
@ -2343,6 +2343,7 @@ static bool element_querySelectorAll(JSContext *ctx, unsigned int argc, JS::Valu
|
||||
static bool element_remove(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
static bool element_removeChild(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
static bool element_removeEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
static bool element_replaceWith(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
static bool element_setAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
|
||||
const spidermonkeyFunctionSpec element_funcs[] = {
|
||||
@ -2365,6 +2366,7 @@ const spidermonkeyFunctionSpec element_funcs[] = {
|
||||
{ "remove", element_remove, 0 },
|
||||
{ "removeChild", element_removeChild, 1 },
|
||||
{ "removeEventListener", element_removeEventListener, 3 },
|
||||
{ "replaceWith", element_replaceWith, 1 },
|
||||
{ "setAttribute", element_setAttribute, 2 },
|
||||
{ NULL }
|
||||
};
|
||||
@ -2570,7 +2572,8 @@ element_appendChild(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
|
||||
JS::RootedObject node(ctx, &args[0].toObject());
|
||||
xmlpp::Node *el2 = JS::GetMaybePtrFromReservedSlot<xmlpp::Node>(node, 0);
|
||||
el->import_node(el2);
|
||||
|
||||
el2 = el->import_node(el2);
|
||||
interpreter->changed = true;
|
||||
|
||||
JSObject *obj = getElement(ctx, el2);
|
||||
@ -3418,6 +3421,50 @@ element_removeChild(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
element_replaceWith(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp || argc < 1) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
|
||||
if (!JS_InstanceOf(ctx, hobj, &element_class, NULL)) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
xmlpp::Element *el = JS::GetMaybePtrFromReservedSlot<xmlpp::Element>(hobj, 0);
|
||||
|
||||
if (!el || !args[0].isObject()) {
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
JS::RootedObject replacement(ctx, &args[0].toObject());
|
||||
xmlpp::Node *rep = JS::GetMaybePtrFromReservedSlot<xmlpp::Node>(replacement, 0);
|
||||
xmlAddPrevSibling(el->cobj(), rep->cobj());
|
||||
xmlpp::Node::remove_node(el);
|
||||
interpreter->changed = true;
|
||||
args.rval().setUndefined();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
element_setAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
{
|
||||
|
9
test/ecmascript/replaceWith.html
Normal file
9
test/ecmascript/replaceWith.html
Normal file
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
var div = document.createElement("div");
|
||||
var p = document.createElement("p");
|
||||
p = div.appendChild(p); // TODO without assignment
|
||||
var span = document.createElement("span");
|
||||
p.replaceWith(span);
|
||||
alert(div.outerHTML); //'<div><span></span></div>'
|
||||
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user