mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
[js] location.search getter
This commit is contained in:
parent
07dba347ac
commit
9de0a934ff
@ -154,14 +154,14 @@ history_go(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool location_get_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool location_get_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool location_set_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool location_set_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool location_get_property_port(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool location_get_property_port(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool location_set_property_port(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool location_set_property_port(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool location_get_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool location_get_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool location_set_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool location_set_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool location_get_property_search(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool location_set_property_search(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
JSClassOps location_ops = {
|
JSClassOps location_ops = {
|
||||||
JS_PropertyStub, nullptr,
|
JS_PropertyStub, nullptr,
|
||||||
@ -186,6 +186,7 @@ JSPropertySpec location_props[] = {
|
|||||||
JS_PSGS("href", location_get_property_href, location_set_property_href, JSPROP_ENUMERATE),
|
JS_PSGS("href", location_get_property_href, location_set_property_href, JSPROP_ENUMERATE),
|
||||||
JS_PSGS("port", location_get_property_port, location_set_property_port, JSPROP_ENUMERATE),
|
JS_PSGS("port", location_get_property_port, location_set_property_port, JSPROP_ENUMERATE),
|
||||||
JS_PSGS("protocol", location_get_property_protocol, location_set_property_protocol, JSPROP_ENUMERATE),
|
JS_PSGS("protocol", location_get_property_protocol, location_set_property_protocol, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("search", location_get_property_search, location_set_property_search, JSPROP_ENUMERATE),
|
||||||
JS_PS_END
|
JS_PS_END
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -265,7 +266,6 @@ location_get_property_port(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
location_get_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
location_get_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
@ -309,6 +309,48 @@ location_get_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
location_get_property_search(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, &location_class, NULL))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vs = interpreter->vs;
|
||||||
|
if (!vs) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct string search;
|
||||||
|
init_string(&search);
|
||||||
|
|
||||||
|
const char *query = memchr(vs->uri->data, '?', vs->uri->datalen);
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
add_bytes_to_string(&search, query, strcspn(query, "#" POST_CHAR_S));
|
||||||
|
}
|
||||||
|
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, search.source));
|
||||||
|
done_string(&search);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
location_set_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
location_set_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
@ -405,6 +447,38 @@ location_set_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
location_set_property_search(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;
|
||||||
|
struct document_view *doc_view;
|
||||||
|
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, &location_class, NULL))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vs = interpreter->vs;
|
||||||
|
if (!vs) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
doc_view = vs->doc_view;
|
||||||
|
// location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool location_toString(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool location_toString(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
|
||||||
|
@ -1 +1,2 @@
|
|||||||
<p><button onclick="javascript:{ alert(location.port); }">Display location.port.</button></p>
|
<p><button onclick="javascript:{ alert(location.port); }">Display location.port.</button></p>
|
||||||
|
<p><button onclick="javascript:{ alert(location.search); }">Display location.search.</button></p>
|
||||||
|
Loading…
Reference in New Issue
Block a user