mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[mujs] Added mjs_push_document2
Difference is that this function does not add document to global object, and does not set thisval.
This commit is contained in:
parent
6552a3df8a
commit
2735f29b21
@ -1697,6 +1697,79 @@ mjs_push_document(js_State *J, void *doc)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mjs_push_document2(js_State *J, void *doc)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct mjs_document_private *doc_private = (struct mjs_document_private *)mem_calloc(1, sizeof(*doc_private));
|
||||
|
||||
if (!doc_private) {
|
||||
return;
|
||||
}
|
||||
js_newobject(J);
|
||||
{
|
||||
js_newuserdata(J, "document", doc_private, mjs_doc_private_finalizer);
|
||||
addmethod(J, "addEventListener", mjs_document_addEventListener, 3);
|
||||
addmethod(J, "createComment", mjs_document_createComment, 1);
|
||||
addmethod(J, "createDocumentFragment",mjs_document_createDocumentFragment, 0);
|
||||
addmethod(J, "createElement", mjs_document_createElement, 1);
|
||||
addmethod(J, "createTextNode", mjs_document_createTextNode, 1);
|
||||
addmethod(J, "dispatchEvent", mjs_document_dispatchEvent, 1);
|
||||
addmethod(J, "write", mjs_document_write, 1);
|
||||
addmethod(J, "writeln", mjs_document_writeln, 1);
|
||||
addmethod(J, "replace", mjs_document_replace, 2);
|
||||
addmethod(J, "getElementById", mjs_document_getElementById, 1);
|
||||
addmethod(J, "getElementsByClassName", mjs_document_getElementsByClassName, 1);
|
||||
// addmethod(J, "getElementsByName", mjs_document_getElementsByName, 1);
|
||||
addmethod(J, "getElementsByTagName", mjs_document_getElementsByTagName, 1);
|
||||
addmethod(J, "querySelector", mjs_document_querySelector, 1);
|
||||
addmethod(J, "querySelectorAll", mjs_document_querySelectorAll, 1);
|
||||
addmethod(J, "removeEventListener", mjs_document_removeEventListener, 3);
|
||||
addmethod(J, "toString", mjs_document_toString, 0);
|
||||
|
||||
addproperty(J, "anchors", mjs_document_get_property_anchors, NULL);
|
||||
addproperty(J, "baseURI", mjs_document_get_property_baseURI, NULL);
|
||||
addproperty(J, "body", mjs_document_get_property_body, mjs_document_set_property_body);
|
||||
#ifdef CONFIG_COOKIES
|
||||
addproperty(J, "cookie", mjs_document_get_property_cookie, mjs_document_set_property_cookie);
|
||||
#endif
|
||||
addproperty(J, "charset", mjs_document_get_property_charset, NULL);
|
||||
addproperty(J, "characterSet", mjs_document_get_property_charset, NULL);
|
||||
addproperty(J, "childNodes", mjs_document_get_property_childNodes, NULL);
|
||||
addproperty(J, "defaultView", mjs_document_get_property_defaultView, NULL);
|
||||
addproperty(J, "doctype", mjs_document_get_property_doctype, NULL);
|
||||
addproperty(J, "documentElement", mjs_document_get_property_documentElement, NULL);
|
||||
addproperty(J, "documentURI", mjs_document_get_property_documentURI, NULL);
|
||||
addproperty(J, "domain", mjs_document_get_property_domain, NULL);
|
||||
addproperty(J, "forms", mjs_document_get_property_forms, NULL);
|
||||
addproperty(J, "head", mjs_document_get_property_head, NULL);
|
||||
addproperty(J, "images", mjs_document_get_property_images, NULL);
|
||||
addproperty(J, "implementation", mjs_document_get_property_implementation, NULL);
|
||||
addproperty(J, "inputEncoding", mjs_document_get_property_charset, NULL);
|
||||
addproperty(J, "links", mjs_document_get_property_links, NULL);
|
||||
addproperty(J, "nodeType", mjs_document_get_property_nodeType, NULL);
|
||||
addproperty(J, "readyState", mjs_document_get_property_readyState, NULL);
|
||||
addproperty(J, "referrer", mjs_document_get_property_referrer, NULL);
|
||||
addproperty(J, "scripts", mjs_document_get_property_scripts, NULL);
|
||||
addproperty(J, "title", mjs_document_get_property_title, mjs_document_set_property_title); /* TODO: Charset? */
|
||||
addproperty(J, "URL", mjs_document_get_property_url, mjs_document_set_property_url);
|
||||
}
|
||||
//js_defglobal(J, "document", JS_DONTENUM);
|
||||
|
||||
init_list(doc_private->listeners);
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
doc_private->interpreter = interpreter;
|
||||
doc_private->node = doc;
|
||||
doc_private->ref_count = 1;
|
||||
//doc_private->thisval = js_ref(J);
|
||||
if (doc) {
|
||||
dom_node_ref((dom_node *)doc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
mjs_document_dispatchEvent(js_State *J)
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
void mjs_push_document(js_State *J, void *doc);
|
||||
void mjs_push_document2(js_State *J, void *doc);
|
||||
int mjs_document_init(js_State *J);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -39,7 +39,7 @@ mjs_domparser_parseFromString(js_State *J)
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
mjs_push_document(J, doc);
|
||||
mjs_push_document2(J, doc);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -69,5 +69,6 @@ mjs_domparser_init(js_State *J)
|
||||
js_pushglobal(J);
|
||||
js_newcconstructor(J, mjs_domparser_fun, mjs_domparser_constructor, "DOMParser", 0);
|
||||
js_defglobal(J, "DOMParser", JS_DONTENUM);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user