implement document.URL and document.documentURI

This commit is contained in:
Vincent Sanders 2012-12-07 15:50:24 +00:00
parent 99f93da0f3
commit 04825c62df
4 changed files with 63 additions and 6 deletions

View File

@ -45,8 +45,8 @@ JSObject *jsapi_InitClass_Location(JSContext *cx, JSObject *parent);
JSObject *jsapi_new_Location(JSContext *cx,
JSObject *window,
JSObject *parent,
struct browser_window *bw,
nsurl *url);
nsurl *url,
html_content *htmlc);
JSObject *jsapi_InitClass_Document(JSContext *cx, JSObject *parent);

View File

@ -56,6 +56,7 @@ api finalise %{
}
%}
getter location %{
if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx,vp))) {
/* already created - return it */
@ -64,10 +65,27 @@ getter location %{
jsret = jsapi_new_Location(cx,
NULL,
NULL,
private->htmlc->bw,
llcache_handle_get_url(private->htmlc->base.llcache));
llcache_handle_get_url(private->htmlc->base.llcache),
private->htmlc);
%}
getter URL %{
jsval loc;
jsval jsstr = JSVAL_NULL;
if (JS_GetProperty(cx, obj, "location", &loc) == JS_TRUE) {
JS_GetProperty(cx, JSVAL_TO_OBJECT(loc), "href", &jsstr);
}
jsret = JSVAL_TO_STRING(jsstr);
%}
getter documentURI %{
jsval loc;
jsval jsstr = JSVAL_NULL;
if (JS_GetProperty(cx, obj, "location", &loc) == JS_TRUE) {
JS_GetProperty(cx, JSVAL_TO_OBJECT(loc), "href", &jsstr);
}
jsret = JSVAL_TO_STRING(jsstr);
%}
getter cookie %{
char *cookie_str;

View File

@ -32,19 +32,27 @@ binding location {
interface Location; /* Web IDL interface to generate */
private "struct browser_window *" bw;
private "nsurl *" url;
private "struct html_content *" htmlc;
property unshared href;
}
operation reload %{
browser_window_reload(private->bw, false);
browser_window_reload(private->htmlc->bw, false);
%}
getter href %{
char *url_s = NULL;
size_t url_l;
if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx,vp))) {
/* already created - return it */
return JS_TRUE;
}
nsurl_get(private->url, NSURL_COMPLETE, &url_s, &url_l);
if (url_s != NULL) {
jsret = JS_NewStringCopyN(cx, url_s, url_l);

31
test/js/document-url.html Normal file
View File

@ -0,0 +1,31 @@
<html>
<head>
<title>document location and URL interface</title>
<link rel="stylesheet" type="text/css" href="tst.css">
</head>
<body>
<h1>document location and URL interface</h1>
<h2>Document location enumeration</h2>
<script>
function output(x,y) {
document.body.appendChild(document.createTextNode(x));
document.body.appendChild(document.createTextNode("("));
if (y != undefined) {
document.body.appendChild(document.createTextNode(y.length));
}
document.body.appendChild(document.createTextNode(") = "));
document.body.appendChild(document.createTextNode(y));
document.body.appendChild(document.createElement('br'));
}
for(var key in document.location) {
output(key, document.location[key]);
}
</script>
<h2>Document URL</h2>
<script>output("document.URL", document.URL);</script>
<h2>DocumentURI</h2>
<script>output("document.documentURI", document.documentURI);</script>
</body>
</html>