summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--javascript/jsapi/binding.h4
-rw-r--r--javascript/jsapi/htmldocument.bnd22
-rw-r--r--javascript/jsapi/location.bnd12
-rw-r--r--test/js/document-url.html31
4 files changed, 63 insertions, 6 deletions
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index f27493532..7b0f61428 100644
--- a/javascript/jsapi/binding.h
+++ b/javascript/jsapi/binding.h
@@ -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);
diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd
index 72bc81482..f17190d0c 100644
--- a/javascript/jsapi/htmldocument.bnd
+++ b/javascript/jsapi/htmldocument.bnd
@@ -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;
diff --git a/javascript/jsapi/location.bnd b/javascript/jsapi/location.bnd
index 32e38da93..32677d1b5 100644
--- a/javascript/jsapi/location.bnd
+++ b/javascript/jsapi/location.bnd
@@ -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);
diff --git a/test/js/document-url.html b/test/js/document-url.html
new file mode 100644
index 000000000..2299b5775
--- /dev/null
+++ b/test/js/document-url.html
@@ -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>