summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--javascript/jsapi/binding.h3
-rw-r--r--javascript/jsapi/location.bnd95
-rw-r--r--javascript/jsapi/window.bnd3
-rw-r--r--test/js/location-enumerate.html26
4 files changed, 123 insertions, 4 deletions
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index 6400217c8..6d069b973 100644
--- a/javascript/jsapi/binding.h
+++ b/javascript/jsapi/binding.h
@@ -45,7 +45,8 @@ JSObject *jsapi_InitClass_Location(JSContext *cx, JSObject *parent);
JSObject *jsapi_new_Location(JSContext *cx,
JSObject *window,
JSObject *parent,
- struct browser_window *bw);
+ struct browser_window *bw,
+ nsurl *url);
JSObject *jsapi_InitClass_Document(JSContext *cx, JSObject *parent);
diff --git a/javascript/jsapi/location.bnd b/javascript/jsapi/location.bnd
index db7a247bc..e91094f2d 100644
--- a/javascript/jsapi/location.bnd
+++ b/javascript/jsapi/location.bnd
@@ -8,8 +8,6 @@
* http://www.opensource.org/licenses/mit-license
*/
-#include "dom.bnd"
-
webidlfile "html.idl";
hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
@@ -35,8 +33,101 @@ binding location {
interface Location; /* Web IDL interface to generate */
private "struct browser_window *" bw;
+ private "nsurl *" url;
}
operation reload %{
browser_window_reload(private->bw, false);
%}
+
+
+getter href %{
+ char *url_s = NULL;
+ size_t url_l;
+ nsurl_get(private->url, NSURL_COMPLETE, &url_s, &url_l);
+ if (url_s != NULL) {
+ jsret = JS_NewStringCopyN(cx, url_s, url_l);
+ free(url_s);
+ }
+%}
+
+getter protocol %{
+ lwc_string *component;
+ component = nsurl_get_component(private->url, NSURL_SCHEME);
+ if (component != NULL) {
+ jsret = JS_NewStringCopyN(cx,
+ lwc_string_data(component),
+ lwc_string_length(component));
+ dom_string_unref(component);
+ }
+%}
+
+getter host %{
+ lwc_string *component;
+ component = nsurl_get_component(private->url, NSURL_HOST);
+ if (component != NULL) {
+ jsret = JS_NewStringCopyN(cx,
+ lwc_string_data(component),
+ lwc_string_length(component));
+ dom_string_unref(component);
+ }
+%}
+
+getter hostname %{
+ lwc_string *component;
+ component = nsurl_get_component(private->url, NSURL_HOST);
+ if (component != NULL) {
+ jsret = JS_NewStringCopyN(cx,
+ lwc_string_data(component),
+ lwc_string_length(component));
+ dom_string_unref(component);
+ }
+
+%}
+
+getter port %{
+ lwc_string *component;
+ component = nsurl_get_component(private->url, NSURL_PORT);
+ if (component != NULL) {
+ jsret = JS_NewStringCopyN(cx,
+ lwc_string_data(component),
+ lwc_string_length(component));
+ dom_string_unref(component);
+ }
+
+%}
+
+getter pathname %{
+ lwc_string *component;
+ component = nsurl_get_component(private->url, NSURL_PATH);
+ if (component != NULL) {
+ jsret = JS_NewStringCopyN(cx,
+ lwc_string_data(component),
+ lwc_string_length(component));
+ dom_string_unref(component);
+ }
+
+%}
+
+getter search %{
+ lwc_string *component;
+ component = nsurl_get_component(private->url, NSURL_QUERY);
+ if (component != NULL) {
+ jsret = JS_NewStringCopyN(cx,
+ lwc_string_data(component),
+ lwc_string_length(component));
+ dom_string_unref(component);
+ }
+
+%}
+
+getter hash %{
+ lwc_string *component;
+ component = nsurl_get_component(private->url, NSURL_FRAGMENT);
+ if (component != NULL) {
+ jsret = JS_NewStringCopyN(cx,
+ lwc_string_data(component),
+ lwc_string_length(component));
+ dom_string_unref(component);
+ }
+%}
diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd
index c4e6e88cb..dbc38a796 100644
--- a/javascript/jsapi/window.bnd
+++ b/javascript/jsapi/window.bnd
@@ -160,7 +160,8 @@ api new %{
return NULL;
}
- private->location = jsapi_new_Location(cx, NULL, newobject, bw);
+ private->location = jsapi_new_Location(cx, NULL, newobject, bw,
+ llcache_handle_get_url(private->htmlc->base.llcache));
if (private->location == NULL) {
free(private);
return NULL;
diff --git a/test/js/location-enumerate.html b/test/js/location-enumerate.html
new file mode 100644
index 000000000..d455c7535
--- /dev/null
+++ b/test/js/location-enumerate.html
@@ -0,0 +1,26 @@
+<html>
+<head>
+<title>location interface enumeration</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1>location interface enumeration</h1>
+
+<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 location) {
+ output(key, location[key]);
+}
+</script>
+</body>
+</html>