mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[js] location.hostname getter
This commit is contained in:
parent
7c618d3a6f
commit
4c4ea4bdd9
@ -154,6 +154,8 @@ history_go(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
return 2;
|
||||
}
|
||||
|
||||
static bool location_get_property_hostname(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool location_set_property_hostname(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_get_property_origin(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
@ -186,6 +188,7 @@ enum location_prop {
|
||||
JSP_LOC_HREF = -1,
|
||||
};
|
||||
JSPropertySpec location_props[] = {
|
||||
JS_PSGS("hostname", location_get_property_hostname, location_set_property_hostname, JSPROP_ENUMERATE),
|
||||
JS_PSGS("href", location_get_property_href, location_set_property_href, JSPROP_ENUMERATE),
|
||||
JS_PSG("origin", location_get_property_origin, JSPROP_ENUMERATE),
|
||||
JS_PSGS("pathname", location_get_property_pathname, location_set_property_pathname, JSPROP_ENUMERATE),
|
||||
@ -195,6 +198,44 @@ JSPropertySpec location_props[] = {
|
||||
JS_PS_END
|
||||
};
|
||||
|
||||
static bool
|
||||
location_get_property_hostname(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;
|
||||
}
|
||||
|
||||
char *str = get_uri_string(vs->uri, URI_HOST);
|
||||
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
|
||||
args.rval().setString(JS_NewStringCopyZ(ctx, str));
|
||||
mem_free(str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
location_get_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
@ -432,6 +473,38 @@ location_get_property_search(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
location_set_property_hostname(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_set_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
|
@ -1,3 +1,4 @@
|
||||
<p><button onclick="javascript:{ alert(location.hostname); }">Display location.hostname.</button></p>
|
||||
<p><button onclick="javascript:{ alert(location.origin); }">Display location.origin.</button></p>
|
||||
<p><button onclick="javascript:{ alert(location.pathname); }">Display location.pathname.</button></p>
|
||||
<p><button onclick="javascript:{ alert(location.port); }">Display location.port.</button></p>
|
||||
|
Loading…
Reference in New Issue
Block a user