mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
[js] element.ownerDocument
This commit is contained in:
parent
835d42e892
commit
1af9c9fc31
@ -63,6 +63,7 @@ struct ecmascript_interpreter {
|
|||||||
void *ac;
|
void *ac;
|
||||||
void *ac2;
|
void *ac2;
|
||||||
void *ar;
|
void *ar;
|
||||||
|
void *document_obj;
|
||||||
JS::RootedValue fun;
|
JS::RootedValue fun;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -272,6 +272,8 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
goto release_and_fail;
|
goto release_and_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interpreter->document_obj = document_obj;
|
||||||
|
|
||||||
forms_obj = spidermonkey_InitClass(ctx, document_obj, NULL,
|
forms_obj = spidermonkey_InitClass(ctx, document_obj, NULL,
|
||||||
&forms_class, NULL, 0,
|
&forms_class, NULL, 0,
|
||||||
forms_props,
|
forms_props,
|
||||||
|
@ -437,6 +437,23 @@ document_get_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
document_get_property_nodeType(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
|
JSCompartment *comp = js::GetContextCompartment(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setInt32(9);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
document_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
document_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
@ -715,6 +732,7 @@ JSPropertySpec document_props[] = {
|
|||||||
JS_PSG("images", document_get_property_images, JSPROP_ENUMERATE),
|
JS_PSG("images", document_get_property_images, JSPROP_ENUMERATE),
|
||||||
JS_PSG("links", document_get_property_links, JSPROP_ENUMERATE),
|
JS_PSG("links", document_get_property_links, JSPROP_ENUMERATE),
|
||||||
JS_PSGS("location", document_get_property_location, document_set_property_location, JSPROP_ENUMERATE),
|
JS_PSGS("location", document_get_property_location, document_set_property_location, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("nodeType", document_get_property_nodeType, JSPROP_ENUMERATE),
|
||||||
JS_PSG("referrer", document_get_property_referrer, JSPROP_ENUMERATE),
|
JS_PSG("referrer", document_get_property_referrer, JSPROP_ENUMERATE),
|
||||||
JS_PSG("scripts", document_get_property_scripts, JSPROP_ENUMERATE),
|
JS_PSG("scripts", document_get_property_scripts, JSPROP_ENUMERATE),
|
||||||
JS_PSGS("title", document_get_property_title, document_set_property_title, JSPROP_ENUMERATE), /* TODO: Charset? */
|
JS_PSGS("title", document_get_property_title, document_set_property_title, JSPROP_ENUMERATE), /* TODO: Charset? */
|
||||||
|
@ -76,6 +76,7 @@ static bool element_get_property_nodeType(JSContext *ctx, unsigned int argc, JS:
|
|||||||
static bool element_get_property_nodeValue(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_get_property_nodeValue(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool element_get_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_get_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool element_set_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_set_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool element_get_property_ownerDocument(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool element_get_property_parentElement(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_get_property_parentElement(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool element_get_property_parentNode(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_get_property_parentNode(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool element_get_property_previousElementSibling(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_get_property_previousElementSibling(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
@ -116,6 +117,7 @@ JSPropertySpec element_props[] = {
|
|||||||
JS_PSG("nodeType", element_get_property_nodeType, JSPROP_ENUMERATE),
|
JS_PSG("nodeType", element_get_property_nodeType, JSPROP_ENUMERATE),
|
||||||
JS_PSG("nodeValue", element_get_property_nodeValue, JSPROP_ENUMERATE),
|
JS_PSG("nodeValue", element_get_property_nodeValue, JSPROP_ENUMERATE),
|
||||||
JS_PSGS("outerHTML", element_get_property_outerHtml, element_set_property_outerHtml, JSPROP_ENUMERATE),
|
JS_PSGS("outerHTML", element_get_property_outerHtml, element_set_property_outerHtml, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("ownerDocument", element_get_property_ownerDocument, JSPROP_ENUMERATE),
|
||||||
JS_PSG("parentElement", element_get_property_parentElement, JSPROP_ENUMERATE),
|
JS_PSG("parentElement", element_get_property_parentElement, JSPROP_ENUMERATE),
|
||||||
JS_PSG("parentNode", element_get_property_parentNode, JSPROP_ENUMERATE),
|
JS_PSG("parentNode", element_get_property_parentNode, JSPROP_ENUMERATE),
|
||||||
JS_PSG("previousElementSibling", element_get_property_previousElementSibling, JSPROP_ENUMERATE),
|
JS_PSG("previousElementSibling", element_get_property_previousElementSibling, JSPROP_ENUMERATE),
|
||||||
@ -843,6 +845,36 @@ element_get_property_nextSibling(JSContext *ctx, unsigned int argc, JS::Value *v
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
element_get_property_ownerDocument(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
|
struct view_state *vs;
|
||||||
|
JSCompartment *comp = js::GetContextCompartment(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(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, &element_class, NULL))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vs = interpreter->vs;
|
||||||
|
if (!vs) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setObject(*(JSObject *)(interpreter->document_obj));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
element_get_property_parentElement(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
element_get_property_parentElement(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
|
19
test/ecmascript/ownerDocument.html
Normal file
19
test/ecmascript/ownerDocument.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p id="myP">Click the button get the node type of the owner document of this <p> element.</p>
|
||||||
|
|
||||||
|
<button onclick="myFunction()">Try it</button>
|
||||||
|
|
||||||
|
<p id="demo"></p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function myFunction() {
|
||||||
|
var x= document.getElementById("myP").ownerDocument.nodeType;
|
||||||
|
alert(x);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user