Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/04825c62df92c8adef3f4...
...commit
http://git.netsurf-browser.org/netsurf.git/commit/04825c62df92c8adef3f40f...
...tree
http://git.netsurf-browser.org/netsurf.git/tree/04825c62df92c8adef3f40f89...
The branch, master has been updated
via 04825c62df92c8adef3f40f89c7b5d88b963f833 (commit)
via 99f93da0f3a510df51c5a057e7597c570a636f9d (commit)
from 40076ea422458fde1799fd383b475586ee112c3f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commitdiff/04825c62df92c8adef3...
commit 04825c62df92c8adef3f40f89c7b5d88b963f833
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
implement document.URL and document.documentURI
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index f274935..7b0f614 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 72bc814..f17190d 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 32e38da..32677d1 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 0000000..2299b57
--- /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>
commitdiff
http://git.netsurf-browser.org/netsurf.git/commitdiff/99f93da0f3a510df51c...
commit 99f93da0f3a510df51c5a057e7597c570a636f9d
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
correctly handle location
diff --git a/javascript/jsapi.h b/javascript/jsapi.h
index 0493290..d757b7f 100644
--- a/javascript/jsapi.h
+++ b/javascript/jsapi.h
@@ -79,7 +79,7 @@
jsapi_property_##name##_set(cx, obj, jsval jsapi_id, vp)
/* native property return value */
-#define JSAPI_PROP_RVAL(cx, vp) (vp)
+#define JSAPI_PROP_RVAL(cx, vp) (*(vp))
/* native property getter return value */
#define JSAPI_PROP_SET_RVAL(cx, vp, v) (*(vp) = (v))
diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd
index 0ed7ac1..72bc814 100644
--- a/javascript/jsapi/htmldocument.bnd
+++ b/javascript/jsapi/htmldocument.bnd
@@ -43,6 +43,9 @@ binding document {
*/
private "dom_document *" node;
private "struct html_content *" htmlc;
+
+ /** location instantiated on first use */
+ property unshared location;
}
api finalise %{
@@ -53,6 +56,19 @@ api finalise %{
}
%}
+getter location %{
+ if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx,vp))) {
+ /* already created - return it */
+ return JS_TRUE;
+ }
+ jsret = jsapi_new_Location(cx,
+ NULL,
+ NULL,
+ private->htmlc->bw,
+ llcache_handle_get_url(private->htmlc->base.llcache));
+%}
+
+
getter cookie %{
char *cookie_str;
cookie_str =
urldb_get_cookie(llcache_handle_get_url(private->htmlc->base.llcache), false);
diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd
index d7f47ce..6153e90 100644
--- a/javascript/jsapi/window.bnd
+++ b/javascript/jsapi/window.bnd
@@ -42,7 +42,6 @@ binding window {
internal "JSObject *" document;
internal "JSObject *" navigator;
internal "JSObject *" console;
- internal "JSObject *" location;
property unshared type EventHandler;
}
@@ -58,9 +57,6 @@ api mark %{
if (private->console != NULL) {
JSAPI_GCMARK(private->console);
}
- if (private->location != NULL) {
- JSAPI_GCMARK(private->location);
- }
}
%}
@@ -180,13 +176,6 @@ api new %{
return NULL;
}
- 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;
- }
-
private->console = jsapi_new_Console(cx, NULL, newobject);
if (private->console == NULL) {
free(private);
@@ -210,14 +199,6 @@ operation prompt %{
warn_user(message, NULL);
%}
-getter window %{
- jsret = obj;
-%}
-
-getter self %{
- jsret = obj;
-%}
-
/* boolean dispatchEvent(Event event); */
operation dispatchEvent %{
/* this implementation is unique to the window object as it is
@@ -254,6 +235,20 @@ operation dispatchEvent %{
}
%}
+getter location %{
+ jsval loc;
+ JS_GetProperty(cx, private->document, "location", &loc);
+ jsret = JSVAL_TO_OBJECT(loc);
+%}
+
+getter window %{
+ jsret = obj;
+%}
+
+getter self %{
+ jsret = obj;
+%}
+
getter EventHandler %{
/* this implementation is unique to the window object as it is
* not a dom node.
-----------------------------------------------------------------------
Summary of changes:
javascript/jsapi.h | 2 +-
javascript/jsapi/binding.h | 4 +-
javascript/jsapi/htmldocument.bnd | 34 ++++++++++++++++++++
javascript/jsapi/location.bnd | 12 ++++++-
javascript/jsapi/window.bnd | 33 ++++++++-----------
...m-document-enumerate.html => document-url.html} | 13 +++++--
6 files changed, 70 insertions(+), 28 deletions(-)
copy test/js/{dom-document-enumerate.html => document-url.html} (59%)
diff --git a/javascript/jsapi.h b/javascript/jsapi.h
index 0493290..d757b7f 100644
--- a/javascript/jsapi.h
+++ b/javascript/jsapi.h
@@ -79,7 +79,7 @@
jsapi_property_##name##_set(cx, obj, jsval jsapi_id, vp)
/* native property return value */
-#define JSAPI_PROP_RVAL(cx, vp) (vp)
+#define JSAPI_PROP_RVAL(cx, vp) (*(vp))
/* native property getter return value */
#define JSAPI_PROP_SET_RVAL(cx, vp, v) (*(vp) = (v))
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index f274935..7b0f614 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 0ed7ac1..f17190d 100644
--- a/javascript/jsapi/htmldocument.bnd
+++ b/javascript/jsapi/htmldocument.bnd
@@ -43,6 +43,9 @@ binding document {
*/
private "dom_document *" node;
private "struct html_content *" htmlc;
+
+ /** location instantiated on first use */
+ property unshared location;
}
api finalise %{
@@ -53,6 +56,37 @@ api finalise %{
}
%}
+
+getter location %{
+ if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx,vp))) {
+ /* already created - return it */
+ return JS_TRUE;
+ }
+ jsret = jsapi_new_Location(cx,
+ NULL,
+ NULL,
+ 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;
cookie_str =
urldb_get_cookie(llcache_handle_get_url(private->htmlc->base.llcache), false);
diff --git a/javascript/jsapi/location.bnd b/javascript/jsapi/location.bnd
index 32e38da..32677d1 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/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd
index d7f47ce..6153e90 100644
--- a/javascript/jsapi/window.bnd
+++ b/javascript/jsapi/window.bnd
@@ -42,7 +42,6 @@ binding window {
internal "JSObject *" document;
internal "JSObject *" navigator;
internal "JSObject *" console;
- internal "JSObject *" location;
property unshared type EventHandler;
}
@@ -58,9 +57,6 @@ api mark %{
if (private->console != NULL) {
JSAPI_GCMARK(private->console);
}
- if (private->location != NULL) {
- JSAPI_GCMARK(private->location);
- }
}
%}
@@ -180,13 +176,6 @@ api new %{
return NULL;
}
- 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;
- }
-
private->console = jsapi_new_Console(cx, NULL, newobject);
if (private->console == NULL) {
free(private);
@@ -210,14 +199,6 @@ operation prompt %{
warn_user(message, NULL);
%}
-getter window %{
- jsret = obj;
-%}
-
-getter self %{
- jsret = obj;
-%}
-
/* boolean dispatchEvent(Event event); */
operation dispatchEvent %{
/* this implementation is unique to the window object as it is
@@ -254,6 +235,20 @@ operation dispatchEvent %{
}
%}
+getter location %{
+ jsval loc;
+ JS_GetProperty(cx, private->document, "location", &loc);
+ jsret = JSVAL_TO_OBJECT(loc);
+%}
+
+getter window %{
+ jsret = obj;
+%}
+
+getter self %{
+ jsret = obj;
+%}
+
getter EventHandler %{
/* this implementation is unique to the window object as it is
* not a dom node.
diff --git a/test/js/dom-document-enumerate.html b/test/js/document-url.html
similarity index 59%
copy from test/js/dom-document-enumerate.html
copy to test/js/document-url.html
index 18146ab..2299b57 100644
--- a/test/js/dom-document-enumerate.html
+++ b/test/js/document-url.html
@@ -1,11 +1,12 @@
<html>
<head>
-<title>document interface enumeration</title>
+<title>document location and URL interface</title>
<link rel="stylesheet" type="text/css"
href="tst.css">
</head>
<body>
-<h1>Document interface enumeration</h1>
+<h1>document location and URL interface</h1>
+<h2>Document location enumeration</h2>
<script>
function output(x,y) {
document.body.appendChild(document.createTextNode(x));
@@ -18,9 +19,13 @@ function output(x,y) {
document.body.appendChild(document.createElement('br'));
}
-for(var key in document) {
- output(key, document[key]);
+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>
--
NetSurf Browser