mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
[js] test commit. No idea yet how to transform forms into elements
This commit is contained in:
parent
e74fd3aa30
commit
fc076c3297
@ -214,7 +214,7 @@ void *
|
||||
spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
{
|
||||
JSContext *ctx;
|
||||
JSObject *console_obj, *document_obj, *forms_obj, *history_obj, *location_obj,
|
||||
JSObject *console_obj, *document_obj, /* *forms_obj,*/ *history_obj, *location_obj,
|
||||
*statusbar_obj, *menubar_obj, *navigator_obj, *localstorage_obj;
|
||||
|
||||
static int initialized = 0;
|
||||
@ -274,6 +274,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
|
||||
interpreter->document_obj = document_obj;
|
||||
|
||||
/*
|
||||
forms_obj = spidermonkey_InitClass(ctx, document_obj, NULL,
|
||||
&forms_class, NULL, 0,
|
||||
forms_props,
|
||||
@ -282,6 +283,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
if (!forms_obj) {
|
||||
goto release_and_fail;
|
||||
}
|
||||
*/
|
||||
|
||||
history_obj = spidermonkey_InitClass(ctx, window_obj, NULL,
|
||||
&history_class, NULL, 0,
|
||||
|
@ -270,6 +270,48 @@ document_get_property_documentElement(JSContext *ctx, unsigned int argc, JS::Val
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
document_get_property_forms(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
JSCompartment *comp = js::GetContextCompartment(ctx);
|
||||
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(comp);
|
||||
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||
struct document *document = doc_view->document;
|
||||
|
||||
if (!document->dom) {
|
||||
document->dom = document_parse(document);
|
||||
}
|
||||
|
||||
if (!document->dom) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
xmlpp::Element* root = (xmlpp::Element *)document->dom;
|
||||
|
||||
std::string xpath = "//form";
|
||||
xmlpp::Node::NodeSet *elements = new xmlpp::Node::NodeSet;
|
||||
|
||||
*elements = root->find(xpath);
|
||||
|
||||
if (elements->size() == 0) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
JSObject *elem = getForms(ctx, elements);
|
||||
|
||||
if (elem) {
|
||||
args.rval().setObject(*elem);
|
||||
} else {
|
||||
args.rval().setNull();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
document_get_property_head(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
@ -728,6 +770,7 @@ JSPropertySpec document_props[] = {
|
||||
JS_PSGS("cookie", document_get_property_cookie, document_set_property_cookie, JSPROP_ENUMERATE),
|
||||
#endif
|
||||
JS_PSG("documentElement", document_get_property_documentElement, JSPROP_ENUMERATE),
|
||||
JS_PSG("forms", document_get_property_forms, JSPROP_ENUMERATE),
|
||||
JS_PSG("head", document_get_property_head, JSPROP_ENUMERATE),
|
||||
JS_PSG("images", document_get_property_images, JSPROP_ENUMERATE),
|
||||
JS_PSG("links", document_get_property_links, JSPROP_ENUMERATE),
|
||||
@ -1087,6 +1130,7 @@ document_getElementById(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
auto node = elements[0];
|
||||
|
||||
JSObject *elem = getElement(ctx, node);
|
||||
|
||||
if (elem) {
|
||||
|
@ -1978,6 +1978,7 @@ htmlCollection_namedItem(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
JS::RootedValue rval(ctx, val);
|
||||
|
||||
char *str = JS_EncodeString(ctx, args[0].toString());
|
||||
rval.setNull();
|
||||
bool ret = htmlCollection_namedItem2(ctx, hobj, str, &rval);
|
||||
args.rval().set(rval);
|
||||
|
||||
@ -2037,8 +2038,6 @@ htmlCollection_namedItem2(JSContext *ctx, JS::HandleObject hobj, char *str, JS::
|
||||
|
||||
xmlpp::Node::NodeSet *ns = JS_GetPrivate(hobj);
|
||||
|
||||
hvp.setUndefined();
|
||||
|
||||
if (!ns) {
|
||||
return true;
|
||||
}
|
||||
|
@ -2966,3 +2966,22 @@ jsval_to_accesskey(JSContext *ctx, JS::MutableHandleValue hvp)
|
||||
JS_ReportErrorUTF8(ctx, "Invalid UTF-16 sequence");
|
||||
return UCS_NO_CHAR; /* which the caller will reject */
|
||||
}
|
||||
|
||||
JSObject *
|
||||
getForms(JSContext *ctx, void *node)
|
||||
{
|
||||
JSObject *el = JS_NewObject(ctx, &forms_class);
|
||||
|
||||
if (!el) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JS::RootedObject r_el(ctx, el);
|
||||
|
||||
JS_DefineProperties(ctx, r_el, (JSPropertySpec *) forms_props);
|
||||
spidermonkey_DefineFunctions(ctx, el, forms_funcs);
|
||||
|
||||
JS_SetPrivate(el, node);
|
||||
|
||||
return el;
|
||||
}
|
||||
|
@ -11,5 +11,6 @@ extern const spidermonkeyFunctionSpec forms_funcs[];
|
||||
extern JSPropertySpec forms_props[];
|
||||
|
||||
JSObject *get_form_object(JSContext *ctx, JSObject *jsdoc, struct form_view *fv);
|
||||
JSObject *getForms(JSContext *ctx, void *node);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user