libnsfb: branch master updated. ab47efdb2ee3e0199fbfc3fa42aa1ac77794cf94
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsfb.git/shortlog/ab47efdb2ee3e0199fbfc...
...commit http://git.netsurf-browser.org/libnsfb.git/commit/ab47efdb2ee3e0199fbfc3f...
...tree http://git.netsurf-browser.org/libnsfb.git/tree/ab47efdb2ee3e0199fbfc3fa4...
The branch, master has been updated
via ab47efdb2ee3e0199fbfc3fa42aa1ac77794cf94 (commit)
from 480b2353d815540dca310edc8496da1d3f1b3295 (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/libnsfb.git/commitdiff/ab47efdb2ee3e0199fb...
commit ab47efdb2ee3e0199fbfc3fa42aa1ac77794cf94
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Also needs xcb-atom which is in libxcb-util0-dev
diff --git a/Makefile b/Makefile
index 1fd4d47..8358de6 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ WARNFLAGS := -Wall -Wextra -Wundef -Wpointer-arith -Wcast-align \
CFLAGS := -g -std=c99 -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112L \
-I$(CURDIR)/include/ -I$(CURDIR)/src $(WARNFLAGS) $(CFLAGS)
-NSFB_XCB_PKG_NAMES := xcb xcb-icccm xcb-image xcb-keysyms
+NSFB_XCB_PKG_NAMES := xcb xcb-icccm xcb-image xcb-keysyms xcb-atom
$(eval $(call pkg_config_package_available,NSFB_VNC_AVAILABLE,libvncserver))
$(eval $(call pkg_config_package_available,NSFB_SDL_AVAILABLE,sdl))
-----------------------------------------------------------------------
Summary of changes:
Makefile | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/Makefile b/Makefile
index 1fd4d47..8358de6 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ WARNFLAGS := -Wall -Wextra -Wundef -Wpointer-arith -Wcast-align \
CFLAGS := -g -std=c99 -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112L \
-I$(CURDIR)/include/ -I$(CURDIR)/src $(WARNFLAGS) $(CFLAGS)
-NSFB_XCB_PKG_NAMES := xcb xcb-icccm xcb-image xcb-keysyms
+NSFB_XCB_PKG_NAMES := xcb xcb-icccm xcb-image xcb-keysyms xcb-atom
$(eval $(call pkg_config_package_available,NSFB_VNC_AVAILABLE,libvncserver))
$(eval $(call pkg_config_package_available,NSFB_SDL_AVAILABLE,sdl))
--
NetSurf Framebuffer library
10 years, 4 months
netsurf: branch vince/nsgenbind updated. 7cb31505738ef0beaf984bebf8bb7f0529097f33
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/7cb31505738ef0beaf984...
...commit http://git.netsurf-browser.org/netsurf.git/commit/7cb31505738ef0beaf984be...
...tree http://git.netsurf-browser.org/netsurf.git/tree/7cb31505738ef0beaf984bebf...
The branch, vince/nsgenbind has been updated
via 7cb31505738ef0beaf984bebf8bb7f0529097f33 (commit)
from b84dc91e3dbf694de6d3e79ecd4755e8d0b699b7 (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/7cb31505738ef0beaf9...
commit 7cb31505738ef0beaf984bebf8bb7f0529097f33
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
improve example binding docuemntation
diff --git a/javascript/jsapi/bindings/example.bnd b/javascript/jsapi/bindings/example.bnd
index 897e9a5..f2f81fb 100644
--- a/javascript/jsapi/bindings/example.bnd
+++ b/javascript/jsapi/bindings/example.bnd
@@ -1,4 +1,7 @@
-/* Binding to generate Navigator interface
+/* Example binding to generate Example interface
+ *
+ * The js_libdom (javascript to libdom) binding type is currently the
+ * only one implemented and this principly describes that binding.
*
* Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
*
@@ -8,15 +11,26 @@
* http://www.opensource.org/licenses/mit-license
*/
+/* additional binding fragments may be included
+ * Note: this is not preprocessed despite the #include name, the
+ * parser will simply switch input to the included file and carry on
+ * cosntructing the bindings Abstract Syntax Tree (AST)
+ */
#include "dom.bnd"
+/* directive to read WebIDL file and add its contents to the webidl AST */
webidlfile "html.idl";
+/* The hdrcomment are added into the geenrated output comment header */
hdrcomment "Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>";
hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
hdrcomment "Released under the terms of the MIT License,";
hdrcomment " http://www.opensource.org/licenses/mit-license";
+/* the preamble block is copied verbatum into the generated output
+ *
+ * This can be used for includes, comments or whatever else is desired
+ */
preamble %{
#include <dom/dom.h>
@@ -27,64 +41,189 @@ preamble %{
#include "javascript/jsapi.h"
#include "javascript/jsapi/binding.h"
-/*
- * navigator properties for netsurf
- *
- * Property | Everyone else | NetSurf | Notes
- * ------------+-----------------+--------------+------------------------------
- * appCodeName | "Mozilla" | "NetSurf" | This is kinda a pointless
- * | | | constant as everyone returns
- * | | | "Mozilla" which is dumb
- * ------------+-----------------+--------------+------------------------------
- * appName | "<Browsername>" | "NetSurf" | Browsers named other than
- * | | | "Netscape", "Mozilla",
- * | | | "Netscape Navigator",
- * | | | "Microsoft Internet Explorer"
- * | | | often other browser have
- * | | | "(compatible with Netscape)"
- * | | | append.
- * ------------+-----------------+--------------+------------------------------
- * appVersion | "<ver> (<type>)"| "<ver>" | Actually just the version
- * | | | number e.g "3.0".
- * ------------+-----------------+--------------+------------------------------
- * language | "<lang>" | "<lang>" | The language the frontend is
- * | | | configured for
- * ------------+-----------------+--------------+------------------------------
- * platform | "<krn> <hw>" | "<krn> <hw>" | Efectively uname -s -i,
- * | | | eg "Linux x86_64"
- * ------------+-----------------+--------------+------------------------------
- * userAgent | "Mozilla/5.0 (" | "NetSurf" | The usual useragent string
- * | | | with excessive lies
- * ------------+-----------------+--------------+------------------------------
- */
-
%}
-binding navigator {
+/* this block describes the binding to be generated
+ *
+ * Depending on the type of binding being generated multiple blocks
+ * may be allowed.
+ *
+ * Note: the js_libdom (javascript to libdom) binding as currently
+ * implemented only allows for a single binding per file, this may
+ * be improved in future.
+ */
+binding example {
type js_libdom; /* the binding type */
- interface Navigator; /* Web IDL interface to generate */
+ interface Navigator; /* The WebIDL interface to generate a binding for */
/* private members:
* - stored in private context structure.
* - passed as parameters to constructor and stored automatically.
* - are *not* considered for property getters/setters.
- *
- * internal members:
+ */
+ private "dom_document *" node;
+
+ /* internal members:
* - value stored in private context structure
* - not passed to constructor
* - must be instantiated by constructor
* - are considered for property getters/setters.
*/
- private "dom_document *" node;
- private "struct html_content *" htmlc;
+ internal "void *" fluff;
+
}
-operation write %{
- LOG(("content %p parser %p writing %s",
- private->htmlc, private->htmlc->parser, text));
+/* operation implementation code.
+ *
+ * The body is copied verbatum into operation binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSNative JSAPI
+ * callback. The interface allows a uniform interface despite the
+ * evolution of the interface over differing spidermonkey versions.
+ *
+ * - The above implies the javascript context is in a variable called cx
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - if there are arguemnts they may be accesed via an argc/argv jsval
+ * vector.
+ *
+ * - Arguments are automatically converted into c variables (named as
+ * per the WebIDL names.
+ *
+ * - Return values (excepting void return types where its omitted) are
+ * always named "retval" and are of the appropriate c type. The
+ * initial value is set appropriately.
+ */
+operation foo %{
+ retval = JS_NewStringCopyN(cx, "foo", SLEN("foo"));
+%}
- if (private->htmlc->parser != NULL) {
- dom_hubbub_parser_insert_chunk(private->htmlc->parser, (uint8_t *)text, text_len);
- }
+/* property getter implementation code.
+ *
+ * The body is copied verbatum into property getter binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSPropertyOp
+ * JSAPI callback. The interface allows a uniform interface despite
+ * the evolution of the interface over differing spidermonkey
+ * versions.
+ *
+ * - The above implies the javascript context is available in a
+ * variable called "cx".
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - Return values (void on a getter is not possible) are always named
+ * "retval" and are of the appropriate c type. The initial value is
+ * set appropriately.
+ *
+ * - If the getter is omitted altogether but an internal or private
+ * value of the same name appears in the private structure a getter
+ * is automatically constructed to return that value.
+ */
+getter bar %{
+ retval = JS_NewStringCopyN(cx, "bar", SLEN("bar"));
%}
+
+/* property setter implementation code.
+ *
+ * The body is copied verbatum into property getter binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSPropertyOp
+ * JSAPI callback. The interface allows a uniform interface despite
+ * the evolution of the interface over differing spidermonkey
+ * versions.
+ *
+ * - The above implies the javascript context is available in a
+ * variable called "cx".
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - Value to set is placed in a c variable named "setval" of the
+ * appropriate type.
+ *
+ * - Return value, named retval" is a boolean (default true) which
+ * indicates if the set was performed.
+ *
+ * - If the setter is omitted altogether but an internal or private
+ * value of the same name appears in the private structure a setter
+ * is automatically constructed to assign that value.
+ */
+setter baz %{
+ printf("%s\n", setval);
+%}
+
+/* implementation of the class initilisation
+ *
+ * This allows the default JS_InitClass to be overriden - currently
+ * only used for the window (global) object to cause all the other class
+ * initialisors to be called.
+ *
+ * function prototype is:
+ * JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent)
+ */
+api init %{
+ %}
+
+/* implementation of the c instance creation
+ *
+ * This allows the overriding of the construction of an interface instance.
+ *
+ * The body is copied verbatum and must return the new object in the
+ * "newobject" variable.
+ *
+ * The base prototype is
+ * JSObject *jsapi_new_HTMLElement(JSContext *cx, JSObject *prototype, JSObject *parent, ...)
+ * The varadic elements are private variables as specified in the binding
+ *
+ * If there are private or internal values the private struct is
+ * constructed and instantiated. The struct is available during the
+ * new function and is automatically attached as the private value to
+ * the object.
+ *
+ * The default implemenattion simply calls JS_NewObject()
+ *
+ * Note this does *not* rely upon (or even call) the instances
+ * javascript constructor allowing the c code to create objects that
+ * cannot be instantiated from javascript.
+ *
+ */
+api new %{
+ %}
+
+/* additional code in the instance finalise operation.
+ *
+ * The body is copied verbatum into the output
+ *
+ * Prototype is
+ * void jsclass_finalize(JSContext *cx, JSObject *obj)
+ *
+ * private is available (if appropriate) and freed after the body
+ */
+api finalise %{
+ %}
+
+/* resolver code
+ *
+ * A resolver is only generated if this api is provided. This is a
+ * JSResolveOp with JSCLASS_NEW_RESOLVE specified and must provide a
+ * complete implementation.
+ *
+ * The body is copied verbatum into the output
+ *
+ * Prototype is:
+ * JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
+ *
+ */
+api resolve %{
+ %}
-----------------------------------------------------------------------
Summary of changes:
javascript/jsapi/bindings/example.bnd | 227 ++++++++++++++++++++++++++-------
1 files changed, 183 insertions(+), 44 deletions(-)
diff --git a/javascript/jsapi/bindings/example.bnd b/javascript/jsapi/bindings/example.bnd
index 897e9a5..f2f81fb 100644
--- a/javascript/jsapi/bindings/example.bnd
+++ b/javascript/jsapi/bindings/example.bnd
@@ -1,4 +1,7 @@
-/* Binding to generate Navigator interface
+/* Example binding to generate Example interface
+ *
+ * The js_libdom (javascript to libdom) binding type is currently the
+ * only one implemented and this principly describes that binding.
*
* Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
*
@@ -8,15 +11,26 @@
* http://www.opensource.org/licenses/mit-license
*/
+/* additional binding fragments may be included
+ * Note: this is not preprocessed despite the #include name, the
+ * parser will simply switch input to the included file and carry on
+ * cosntructing the bindings Abstract Syntax Tree (AST)
+ */
#include "dom.bnd"
+/* directive to read WebIDL file and add its contents to the webidl AST */
webidlfile "html.idl";
+/* The hdrcomment are added into the geenrated output comment header */
hdrcomment "Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>";
hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
hdrcomment "Released under the terms of the MIT License,";
hdrcomment " http://www.opensource.org/licenses/mit-license";
+/* the preamble block is copied verbatum into the generated output
+ *
+ * This can be used for includes, comments or whatever else is desired
+ */
preamble %{
#include <dom/dom.h>
@@ -27,64 +41,189 @@ preamble %{
#include "javascript/jsapi.h"
#include "javascript/jsapi/binding.h"
-/*
- * navigator properties for netsurf
- *
- * Property | Everyone else | NetSurf | Notes
- * ------------+-----------------+--------------+------------------------------
- * appCodeName | "Mozilla" | "NetSurf" | This is kinda a pointless
- * | | | constant as everyone returns
- * | | | "Mozilla" which is dumb
- * ------------+-----------------+--------------+------------------------------
- * appName | "<Browsername>" | "NetSurf" | Browsers named other than
- * | | | "Netscape", "Mozilla",
- * | | | "Netscape Navigator",
- * | | | "Microsoft Internet Explorer"
- * | | | often other browser have
- * | | | "(compatible with Netscape)"
- * | | | append.
- * ------------+-----------------+--------------+------------------------------
- * appVersion | "<ver> (<type>)"| "<ver>" | Actually just the version
- * | | | number e.g "3.0".
- * ------------+-----------------+--------------+------------------------------
- * language | "<lang>" | "<lang>" | The language the frontend is
- * | | | configured for
- * ------------+-----------------+--------------+------------------------------
- * platform | "<krn> <hw>" | "<krn> <hw>" | Efectively uname -s -i,
- * | | | eg "Linux x86_64"
- * ------------+-----------------+--------------+------------------------------
- * userAgent | "Mozilla/5.0 (" | "NetSurf" | The usual useragent string
- * | | | with excessive lies
- * ------------+-----------------+--------------+------------------------------
- */
-
%}
-binding navigator {
+/* this block describes the binding to be generated
+ *
+ * Depending on the type of binding being generated multiple blocks
+ * may be allowed.
+ *
+ * Note: the js_libdom (javascript to libdom) binding as currently
+ * implemented only allows for a single binding per file, this may
+ * be improved in future.
+ */
+binding example {
type js_libdom; /* the binding type */
- interface Navigator; /* Web IDL interface to generate */
+ interface Navigator; /* The WebIDL interface to generate a binding for */
/* private members:
* - stored in private context structure.
* - passed as parameters to constructor and stored automatically.
* - are *not* considered for property getters/setters.
- *
- * internal members:
+ */
+ private "dom_document *" node;
+
+ /* internal members:
* - value stored in private context structure
* - not passed to constructor
* - must be instantiated by constructor
* - are considered for property getters/setters.
*/
- private "dom_document *" node;
- private "struct html_content *" htmlc;
+ internal "void *" fluff;
+
}
-operation write %{
- LOG(("content %p parser %p writing %s",
- private->htmlc, private->htmlc->parser, text));
+/* operation implementation code.
+ *
+ * The body is copied verbatum into operation binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSNative JSAPI
+ * callback. The interface allows a uniform interface despite the
+ * evolution of the interface over differing spidermonkey versions.
+ *
+ * - The above implies the javascript context is in a variable called cx
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - if there are arguemnts they may be accesed via an argc/argv jsval
+ * vector.
+ *
+ * - Arguments are automatically converted into c variables (named as
+ * per the WebIDL names.
+ *
+ * - Return values (excepting void return types where its omitted) are
+ * always named "retval" and are of the appropriate c type. The
+ * initial value is set appropriately.
+ */
+operation foo %{
+ retval = JS_NewStringCopyN(cx, "foo", SLEN("foo"));
+%}
- if (private->htmlc->parser != NULL) {
- dom_hubbub_parser_insert_chunk(private->htmlc->parser, (uint8_t *)text, text_len);
- }
+/* property getter implementation code.
+ *
+ * The body is copied verbatum into property getter binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSPropertyOp
+ * JSAPI callback. The interface allows a uniform interface despite
+ * the evolution of the interface over differing spidermonkey
+ * versions.
+ *
+ * - The above implies the javascript context is available in a
+ * variable called "cx".
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - Return values (void on a getter is not possible) are always named
+ * "retval" and are of the appropriate c type. The initial value is
+ * set appropriately.
+ *
+ * - If the getter is omitted altogether but an internal or private
+ * value of the same name appears in the private structure a getter
+ * is automatically constructed to return that value.
+ */
+getter bar %{
+ retval = JS_NewStringCopyN(cx, "bar", SLEN("bar"));
%}
+
+/* property setter implementation code.
+ *
+ * The body is copied verbatum into property getter binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSPropertyOp
+ * JSAPI callback. The interface allows a uniform interface despite
+ * the evolution of the interface over differing spidermonkey
+ * versions.
+ *
+ * - The above implies the javascript context is available in a
+ * variable called "cx".
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - Value to set is placed in a c variable named "setval" of the
+ * appropriate type.
+ *
+ * - Return value, named retval" is a boolean (default true) which
+ * indicates if the set was performed.
+ *
+ * - If the setter is omitted altogether but an internal or private
+ * value of the same name appears in the private structure a setter
+ * is automatically constructed to assign that value.
+ */
+setter baz %{
+ printf("%s\n", setval);
+%}
+
+/* implementation of the class initilisation
+ *
+ * This allows the default JS_InitClass to be overriden - currently
+ * only used for the window (global) object to cause all the other class
+ * initialisors to be called.
+ *
+ * function prototype is:
+ * JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent)
+ */
+api init %{
+ %}
+
+/* implementation of the c instance creation
+ *
+ * This allows the overriding of the construction of an interface instance.
+ *
+ * The body is copied verbatum and must return the new object in the
+ * "newobject" variable.
+ *
+ * The base prototype is
+ * JSObject *jsapi_new_HTMLElement(JSContext *cx, JSObject *prototype, JSObject *parent, ...)
+ * The varadic elements are private variables as specified in the binding
+ *
+ * If there are private or internal values the private struct is
+ * constructed and instantiated. The struct is available during the
+ * new function and is automatically attached as the private value to
+ * the object.
+ *
+ * The default implemenattion simply calls JS_NewObject()
+ *
+ * Note this does *not* rely upon (or even call) the instances
+ * javascript constructor allowing the c code to create objects that
+ * cannot be instantiated from javascript.
+ *
+ */
+api new %{
+ %}
+
+/* additional code in the instance finalise operation.
+ *
+ * The body is copied verbatum into the output
+ *
+ * Prototype is
+ * void jsclass_finalize(JSContext *cx, JSObject *obj)
+ *
+ * private is available (if appropriate) and freed after the body
+ */
+api finalise %{
+ %}
+
+/* resolver code
+ *
+ * A resolver is only generated if this api is provided. This is a
+ * JSResolveOp with JSCLASS_NEW_RESOLVE specified and must provide a
+ * complete implementation.
+ *
+ * The body is copied verbatum into the output
+ *
+ * Prototype is:
+ * JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
+ *
+ */
+api resolve %{
+ %}
--
NetSurf Browser
10 years, 4 months
nsgenjsbind: branch master updated. 408787939032719568b43d13fd0ea05d25d52781
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/nsgenjsbind.git/shortlog/40878793903271956...
...commit http://git.netsurf-browser.org/nsgenjsbind.git/commit/408787939032719568b...
...tree http://git.netsurf-browser.org/nsgenjsbind.git/tree/408787939032719568b43...
The branch, master has been updated
via 408787939032719568b43d13fd0ea05d25d52781 (commit)
from 6182a17c63737e57581685a2cd37f6e49e9ebd8a (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/nsgenjsbind.git/commitdiff/408787939032719...
commit 408787939032719568b43d13fd0ea05d25d52781
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
example binding
diff --git a/doc/example.bnd b/doc/example.bnd
new file mode 100644
index 0000000..f2f81fb
--- /dev/null
+++ b/doc/example.bnd
@@ -0,0 +1,229 @@
+/* Example binding to generate Example interface
+ *
+ * The js_libdom (javascript to libdom) binding type is currently the
+ * only one implemented and this principly describes that binding.
+ *
+ * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+/* additional binding fragments may be included
+ * Note: this is not preprocessed despite the #include name, the
+ * parser will simply switch input to the included file and carry on
+ * cosntructing the bindings Abstract Syntax Tree (AST)
+ */
+#include "dom.bnd"
+
+/* directive to read WebIDL file and add its contents to the webidl AST */
+webidlfile "html.idl";
+
+/* The hdrcomment are added into the geenrated output comment header */
+hdrcomment "Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>";
+hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
+hdrcomment "Released under the terms of the MIT License,";
+hdrcomment " http://www.opensource.org/licenses/mit-license";
+
+/* the preamble block is copied verbatum into the generated output
+ *
+ * This can be used for includes, comments or whatever else is desired
+ */
+preamble %{
+
+#include <dom/dom.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+
+#include "javascript/jsapi.h"
+#include "javascript/jsapi/binding.h"
+
+%}
+
+/* this block describes the binding to be generated
+ *
+ * Depending on the type of binding being generated multiple blocks
+ * may be allowed.
+ *
+ * Note: the js_libdom (javascript to libdom) binding as currently
+ * implemented only allows for a single binding per file, this may
+ * be improved in future.
+ */
+binding example {
+ type js_libdom; /* the binding type */
+
+ interface Navigator; /* The WebIDL interface to generate a binding for */
+
+ /* private members:
+ * - stored in private context structure.
+ * - passed as parameters to constructor and stored automatically.
+ * - are *not* considered for property getters/setters.
+ */
+ private "dom_document *" node;
+
+ /* internal members:
+ * - value stored in private context structure
+ * - not passed to constructor
+ * - must be instantiated by constructor
+ * - are considered for property getters/setters.
+ */
+ internal "void *" fluff;
+
+}
+
+/* operation implementation code.
+ *
+ * The body is copied verbatum into operation binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSNative JSAPI
+ * callback. The interface allows a uniform interface despite the
+ * evolution of the interface over differing spidermonkey versions.
+ *
+ * - The above implies the javascript context is in a variable called cx
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - if there are arguemnts they may be accesed via an argc/argv jsval
+ * vector.
+ *
+ * - Arguments are automatically converted into c variables (named as
+ * per the WebIDL names.
+ *
+ * - Return values (excepting void return types where its omitted) are
+ * always named "retval" and are of the appropriate c type. The
+ * initial value is set appropriately.
+ */
+operation foo %{
+ retval = JS_NewStringCopyN(cx, "foo", SLEN("foo"));
+%}
+
+/* property getter implementation code.
+ *
+ * The body is copied verbatum into property getter binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSPropertyOp
+ * JSAPI callback. The interface allows a uniform interface despite
+ * the evolution of the interface over differing spidermonkey
+ * versions.
+ *
+ * - The above implies the javascript context is available in a
+ * variable called "cx".
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - Return values (void on a getter is not possible) are always named
+ * "retval" and are of the appropriate c type. The initial value is
+ * set appropriately.
+ *
+ * - If the getter is omitted altogether but an internal or private
+ * value of the same name appears in the private structure a getter
+ * is automatically constructed to return that value.
+ */
+getter bar %{
+ retval = JS_NewStringCopyN(cx, "bar", SLEN("bar"));
+%}
+
+/* property setter implementation code.
+ *
+ * The body is copied verbatum into property getter binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSPropertyOp
+ * JSAPI callback. The interface allows a uniform interface despite
+ * the evolution of the interface over differing spidermonkey
+ * versions.
+ *
+ * - The above implies the javascript context is available in a
+ * variable called "cx".
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - Value to set is placed in a c variable named "setval" of the
+ * appropriate type.
+ *
+ * - Return value, named retval" is a boolean (default true) which
+ * indicates if the set was performed.
+ *
+ * - If the setter is omitted altogether but an internal or private
+ * value of the same name appears in the private structure a setter
+ * is automatically constructed to assign that value.
+ */
+setter baz %{
+ printf("%s\n", setval);
+%}
+
+/* implementation of the class initilisation
+ *
+ * This allows the default JS_InitClass to be overriden - currently
+ * only used for the window (global) object to cause all the other class
+ * initialisors to be called.
+ *
+ * function prototype is:
+ * JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent)
+ */
+api init %{
+ %}
+
+/* implementation of the c instance creation
+ *
+ * This allows the overriding of the construction of an interface instance.
+ *
+ * The body is copied verbatum and must return the new object in the
+ * "newobject" variable.
+ *
+ * The base prototype is
+ * JSObject *jsapi_new_HTMLElement(JSContext *cx, JSObject *prototype, JSObject *parent, ...)
+ * The varadic elements are private variables as specified in the binding
+ *
+ * If there are private or internal values the private struct is
+ * constructed and instantiated. The struct is available during the
+ * new function and is automatically attached as the private value to
+ * the object.
+ *
+ * The default implemenattion simply calls JS_NewObject()
+ *
+ * Note this does *not* rely upon (or even call) the instances
+ * javascript constructor allowing the c code to create objects that
+ * cannot be instantiated from javascript.
+ *
+ */
+api new %{
+ %}
+
+/* additional code in the instance finalise operation.
+ *
+ * The body is copied verbatum into the output
+ *
+ * Prototype is
+ * void jsclass_finalize(JSContext *cx, JSObject *obj)
+ *
+ * private is available (if appropriate) and freed after the body
+ */
+api finalise %{
+ %}
+
+/* resolver code
+ *
+ * A resolver is only generated if this api is provided. This is a
+ * JSResolveOp with JSCLASS_NEW_RESOLVE specified and must provide a
+ * complete implementation.
+ *
+ * The body is copied verbatum into the output
+ *
+ * Prototype is:
+ * JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
+ *
+ */
+api resolve %{
+ %}
-----------------------------------------------------------------------
Summary of changes:
doc/example.bnd | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 229 insertions(+), 0 deletions(-)
create mode 100644 doc/example.bnd
diff --git a/doc/example.bnd b/doc/example.bnd
new file mode 100644
index 0000000..f2f81fb
--- /dev/null
+++ b/doc/example.bnd
@@ -0,0 +1,229 @@
+/* Example binding to generate Example interface
+ *
+ * The js_libdom (javascript to libdom) binding type is currently the
+ * only one implemented and this principly describes that binding.
+ *
+ * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+/* additional binding fragments may be included
+ * Note: this is not preprocessed despite the #include name, the
+ * parser will simply switch input to the included file and carry on
+ * cosntructing the bindings Abstract Syntax Tree (AST)
+ */
+#include "dom.bnd"
+
+/* directive to read WebIDL file and add its contents to the webidl AST */
+webidlfile "html.idl";
+
+/* The hdrcomment are added into the geenrated output comment header */
+hdrcomment "Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>";
+hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
+hdrcomment "Released under the terms of the MIT License,";
+hdrcomment " http://www.opensource.org/licenses/mit-license";
+
+/* the preamble block is copied verbatum into the generated output
+ *
+ * This can be used for includes, comments or whatever else is desired
+ */
+preamble %{
+
+#include <dom/dom.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+
+#include "javascript/jsapi.h"
+#include "javascript/jsapi/binding.h"
+
+%}
+
+/* this block describes the binding to be generated
+ *
+ * Depending on the type of binding being generated multiple blocks
+ * may be allowed.
+ *
+ * Note: the js_libdom (javascript to libdom) binding as currently
+ * implemented only allows for a single binding per file, this may
+ * be improved in future.
+ */
+binding example {
+ type js_libdom; /* the binding type */
+
+ interface Navigator; /* The WebIDL interface to generate a binding for */
+
+ /* private members:
+ * - stored in private context structure.
+ * - passed as parameters to constructor and stored automatically.
+ * - are *not* considered for property getters/setters.
+ */
+ private "dom_document *" node;
+
+ /* internal members:
+ * - value stored in private context structure
+ * - not passed to constructor
+ * - must be instantiated by constructor
+ * - are considered for property getters/setters.
+ */
+ internal "void *" fluff;
+
+}
+
+/* operation implementation code.
+ *
+ * The body is copied verbatum into operation binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSNative JSAPI
+ * callback. The interface allows a uniform interface despite the
+ * evolution of the interface over differing spidermonkey versions.
+ *
+ * - The above implies the javascript context is in a variable called cx
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - if there are arguemnts they may be accesed via an argc/argv jsval
+ * vector.
+ *
+ * - Arguments are automatically converted into c variables (named as
+ * per the WebIDL names.
+ *
+ * - Return values (excepting void return types where its omitted) are
+ * always named "retval" and are of the appropriate c type. The
+ * initial value is set appropriately.
+ */
+operation foo %{
+ retval = JS_NewStringCopyN(cx, "foo", SLEN("foo"));
+%}
+
+/* property getter implementation code.
+ *
+ * The body is copied verbatum into property getter binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSPropertyOp
+ * JSAPI callback. The interface allows a uniform interface despite
+ * the evolution of the interface over differing spidermonkey
+ * versions.
+ *
+ * - The above implies the javascript context is available in a
+ * variable called "cx".
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - Return values (void on a getter is not possible) are always named
+ * "retval" and are of the appropriate c type. The initial value is
+ * set appropriately.
+ *
+ * - If the getter is omitted altogether but an internal or private
+ * value of the same name appears in the private structure a getter
+ * is automatically constructed to return that value.
+ */
+getter bar %{
+ retval = JS_NewStringCopyN(cx, "bar", SLEN("bar"));
+%}
+
+/* property setter implementation code.
+ *
+ * The body is copied verbatum into property getter binding
+ *
+ * several values are generated automatically:
+ *
+ * - The generated operations use a macro to create a JSPropertyOp
+ * JSAPI callback. The interface allows a uniform interface despite
+ * the evolution of the interface over differing spidermonkey
+ * versions.
+ *
+ * - The above implies the javascript context is available in a
+ * variable called "cx".
+ *
+ * - If private or internal binding members are present they may be
+ * accessed through a structure named "private"
+ *
+ * - Value to set is placed in a c variable named "setval" of the
+ * appropriate type.
+ *
+ * - Return value, named retval" is a boolean (default true) which
+ * indicates if the set was performed.
+ *
+ * - If the setter is omitted altogether but an internal or private
+ * value of the same name appears in the private structure a setter
+ * is automatically constructed to assign that value.
+ */
+setter baz %{
+ printf("%s\n", setval);
+%}
+
+/* implementation of the class initilisation
+ *
+ * This allows the default JS_InitClass to be overriden - currently
+ * only used for the window (global) object to cause all the other class
+ * initialisors to be called.
+ *
+ * function prototype is:
+ * JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent)
+ */
+api init %{
+ %}
+
+/* implementation of the c instance creation
+ *
+ * This allows the overriding of the construction of an interface instance.
+ *
+ * The body is copied verbatum and must return the new object in the
+ * "newobject" variable.
+ *
+ * The base prototype is
+ * JSObject *jsapi_new_HTMLElement(JSContext *cx, JSObject *prototype, JSObject *parent, ...)
+ * The varadic elements are private variables as specified in the binding
+ *
+ * If there are private or internal values the private struct is
+ * constructed and instantiated. The struct is available during the
+ * new function and is automatically attached as the private value to
+ * the object.
+ *
+ * The default implemenattion simply calls JS_NewObject()
+ *
+ * Note this does *not* rely upon (or even call) the instances
+ * javascript constructor allowing the c code to create objects that
+ * cannot be instantiated from javascript.
+ *
+ */
+api new %{
+ %}
+
+/* additional code in the instance finalise operation.
+ *
+ * The body is copied verbatum into the output
+ *
+ * Prototype is
+ * void jsclass_finalize(JSContext *cx, JSObject *obj)
+ *
+ * private is available (if appropriate) and freed after the body
+ */
+api finalise %{
+ %}
+
+/* resolver code
+ *
+ * A resolver is only generated if this api is provided. This is a
+ * JSResolveOp with JSCLASS_NEW_RESOLVE specified and must provide a
+ * complete implementation.
+ *
+ * The body is copied verbatum into the output
+ *
+ * Prototype is:
+ * JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
+ *
+ */
+api resolve %{
+ %}
--
NetSurf Generator for JavaScript bindings
10 years, 4 months
netsurf: branch vince/nsgenbind updated. b84dc91e3dbf694de6d3e79ecd4755e8d0b699b7
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/b84dc91e3dbf694de6d3e...
...commit http://git.netsurf-browser.org/netsurf.git/commit/b84dc91e3dbf694de6d3e79...
...tree http://git.netsurf-browser.org/netsurf.git/tree/b84dc91e3dbf694de6d3e79ec...
The branch, vince/nsgenbind has been updated
via b84dc91e3dbf694de6d3e79ecd4755e8d0b699b7 (commit)
from 2b6bd44ef0aec9c99617e7125bda918545be7316 (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/b84dc91e3dbf694de6d...
commit b84dc91e3dbf694de6d3e79ecd4755e8d0b699b7
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
remove extraneous debug
diff --git a/javascript/jsapi/bindings/dom.bnd b/javascript/jsapi/bindings/dom.bnd
index 0f54571..362c828 100644
--- a/javascript/jsapi/bindings/dom.bnd
+++ b/javascript/jsapi/bindings/dom.bnd
@@ -7,15 +7,11 @@ operation getElementById %{
dom_element *element;
dom_exception exc;
- LOG(("elementId_len %d elementId %s",elementId_len,elementId));
-
dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom);
- LOG(("dom string %p", elementId_dom));
-
exc = dom_document_get_element_by_id(private->node, elementId_dom, &element);
if ((exc == DOM_NO_ERR) && (element != NULL)) {
- jsret = jsapi_new_HTMLElement(cx, NULL, JS_GetGlobalObject(cx), element, private->htmlc);
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc);
}
%}
-----------------------------------------------------------------------
Summary of changes:
javascript/jsapi/bindings/dom.bnd | 6 +-----
1 files changed, 1 insertions(+), 5 deletions(-)
diff --git a/javascript/jsapi/bindings/dom.bnd b/javascript/jsapi/bindings/dom.bnd
index 0f54571..362c828 100644
--- a/javascript/jsapi/bindings/dom.bnd
+++ b/javascript/jsapi/bindings/dom.bnd
@@ -7,15 +7,11 @@ operation getElementById %{
dom_element *element;
dom_exception exc;
- LOG(("elementId_len %d elementId %s",elementId_len,elementId));
-
dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom);
- LOG(("dom string %p", elementId_dom));
-
exc = dom_document_get_element_by_id(private->node, elementId_dom, &element);
if ((exc == DOM_NO_ERR) && (element != NULL)) {
- jsret = jsapi_new_HTMLElement(cx, NULL, JS_GetGlobalObject(cx), element, private->htmlc);
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc);
}
%}
--
NetSurf Browser
10 years, 4 months
nsgenjsbind: branch master updated. 6182a17c63737e57581685a2cd37f6e49e9ebd8a
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/nsgenjsbind.git/shortlog/6182a17c63737e575...
...commit http://git.netsurf-browser.org/nsgenjsbind.git/commit/6182a17c63737e57581...
...tree http://git.netsurf-browser.org/nsgenjsbind.git/tree/6182a17c63737e5758168...
The branch, master has been updated
via 6182a17c63737e57581685a2cd37f6e49e9ebd8a (commit)
from 8779ca25c44286b956ac604549d55c7d1661619e (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/nsgenjsbind.git/commitdiff/6182a17c63737e5...
commit 6182a17c63737e57581685a2cd37f6e49e9ebd8a
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
use teh correct return value setting macros in native operation calls
diff --git a/src/jsapi-libdom-operator.c b/src/jsapi-libdom-operator.c
index a20f377..1155108 100644
--- a/src/jsapi-libdom-operator.c
+++ b/src/jsapi-libdom-operator.c
@@ -159,7 +159,7 @@ static int output_return(struct binding *binding,
case WEBIDL_TYPE_USER:
/* User type are represented with jsobject */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
ident);
break;
@@ -167,7 +167,7 @@ static int output_return(struct binding *binding,
case WEBIDL_TYPE_BOOL:
/* JSBool */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(%s));\n",
ident);
break;
@@ -184,7 +184,7 @@ static int output_return(struct binding *binding,
case WEBIDL_TYPE_DOUBLE:
/* double */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(%s));\n",
ident);
break;
@@ -199,14 +199,14 @@ static int output_return(struct binding *binding,
case WEBIDL_TYPE_LONG:
/* int32_t */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, INT_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, INT_TO_JSVAL(%s));\n",
ident);
break;
case WEBIDL_TYPE_STRING:
/* JSString * */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, STRING_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, STRING_TO_JSVAL(%s));\n",
ident);
break;
@@ -217,7 +217,7 @@ static int output_return(struct binding *binding,
case WEBIDL_TYPE_OBJECT:
/* JSObject * */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
ident);
break;
-----------------------------------------------------------------------
Summary of changes:
src/jsapi-libdom-operator.c | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/jsapi-libdom-operator.c b/src/jsapi-libdom-operator.c
index a20f377..1155108 100644
--- a/src/jsapi-libdom-operator.c
+++ b/src/jsapi-libdom-operator.c
@@ -159,7 +159,7 @@ static int output_return(struct binding *binding,
case WEBIDL_TYPE_USER:
/* User type are represented with jsobject */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
ident);
break;
@@ -167,7 +167,7 @@ static int output_return(struct binding *binding,
case WEBIDL_TYPE_BOOL:
/* JSBool */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(%s));\n",
ident);
break;
@@ -184,7 +184,7 @@ static int output_return(struct binding *binding,
case WEBIDL_TYPE_DOUBLE:
/* double */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(%s));\n",
ident);
break;
@@ -199,14 +199,14 @@ static int output_return(struct binding *binding,
case WEBIDL_TYPE_LONG:
/* int32_t */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, INT_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, INT_TO_JSVAL(%s));\n",
ident);
break;
case WEBIDL_TYPE_STRING:
/* JSString * */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, STRING_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, STRING_TO_JSVAL(%s));\n",
ident);
break;
@@ -217,7 +217,7 @@ static int output_return(struct binding *binding,
case WEBIDL_TYPE_OBJECT:
/* JSObject * */
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ "\tJSAPI_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
ident);
break;
--
NetSurf Generator for JavaScript bindings
10 years, 4 months
libdom: branch master updated. ab88f11bb45322003b5882a98f35e9e4e9061e5b
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/ab88f11bb45322003b5882...
...commit http://git.netsurf-browser.org/libdom.git/commit/ab88f11bb45322003b5882a9...
...tree http://git.netsurf-browser.org/libdom.git/tree/ab88f11bb45322003b5882a98f...
The branch, master has been updated
via ab88f11bb45322003b5882a98f35e9e4e9061e5b (commit)
from 733d2632b8640c3e6185e2b999778eba6b171aa5 (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/libdom.git/commitdiff/ab88f11bb45322003b58...
commit ab88f11bb45322003b5882a98f35e9e4e9061e5b
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
alter when the id name is set to before the hubbub parse completion so id based searches work during dom creation
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 8296fe8..95c2043 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -742,6 +742,7 @@ dom_hubbub_parser_create(const char *enc,
hubbub_parser_optparams params;
hubbub_error error;
dom_exception err;
+ dom_string *idname = NULL;
/* check result parameter */
if (document == NULL) {
@@ -813,6 +814,21 @@ dom_hubbub_parser_create(const char *enc,
HUBBUB_PARSER_ENABLE_SCRIPTING,
¶ms);
+ /* set the document id parameter before the parse so searches
+ * based on id succeed.
+ */
+ err = dom_string_create_interned((const uint8_t *) "id",
+ SLEN("id"),
+ &idname);
+ if (err != DOM_NO_ERR) {
+ hubbub_parser_destroy(parser->parser);
+ free(parser);
+ msg(DOM_MSG_ERROR, mctx, "Can't set DOM document id name");
+ return NULL;
+ }
+ _dom_document_set_id_name(parser->doc, idname);
+ dom_string_unref(idname);
+
/* set return parameter */
*document = (dom_document *)dom_node_ref(parser->doc);
@@ -880,9 +896,7 @@ dom_hubbub_error dom_hubbub_parser_parse_chunk(dom_hubbub_parser *parser,
*/
dom_hubbub_error dom_hubbub_parser_completed(dom_hubbub_parser *parser)
{
- dom_exception derr;
hubbub_error err;
- dom_string *name = NULL;
err = hubbub_parser_completed(parser->parser);
if (err != HUBBUB_OK) {
@@ -893,14 +907,6 @@ dom_hubbub_error dom_hubbub_parser_completed(dom_hubbub_parser *parser)
parser->complete = true;
- derr = dom_string_create_interned((const uint8_t *) "id", SLEN("id"),
- &name);
- if (derr != DOM_NO_ERR)
- return DOM_HUBBUB_HUBBUB_ERR | HUBBUB_UNKNOWN;
-
- _dom_document_set_id_name(parser->doc, name);
- dom_string_unref(name);
-
return DOM_HUBBUB_OK;
}
-----------------------------------------------------------------------
Summary of changes:
bindings/hubbub/parser.c | 26 ++++++++++++++++----------
1 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 8296fe8..95c2043 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -742,6 +742,7 @@ dom_hubbub_parser_create(const char *enc,
hubbub_parser_optparams params;
hubbub_error error;
dom_exception err;
+ dom_string *idname = NULL;
/* check result parameter */
if (document == NULL) {
@@ -813,6 +814,21 @@ dom_hubbub_parser_create(const char *enc,
HUBBUB_PARSER_ENABLE_SCRIPTING,
¶ms);
+ /* set the document id parameter before the parse so searches
+ * based on id succeed.
+ */
+ err = dom_string_create_interned((const uint8_t *) "id",
+ SLEN("id"),
+ &idname);
+ if (err != DOM_NO_ERR) {
+ hubbub_parser_destroy(parser->parser);
+ free(parser);
+ msg(DOM_MSG_ERROR, mctx, "Can't set DOM document id name");
+ return NULL;
+ }
+ _dom_document_set_id_name(parser->doc, idname);
+ dom_string_unref(idname);
+
/* set return parameter */
*document = (dom_document *)dom_node_ref(parser->doc);
@@ -880,9 +896,7 @@ dom_hubbub_error dom_hubbub_parser_parse_chunk(dom_hubbub_parser *parser,
*/
dom_hubbub_error dom_hubbub_parser_completed(dom_hubbub_parser *parser)
{
- dom_exception derr;
hubbub_error err;
- dom_string *name = NULL;
err = hubbub_parser_completed(parser->parser);
if (err != HUBBUB_OK) {
@@ -893,14 +907,6 @@ dom_hubbub_error dom_hubbub_parser_completed(dom_hubbub_parser *parser)
parser->complete = true;
- derr = dom_string_create_interned((const uint8_t *) "id", SLEN("id"),
- &name);
- if (derr != DOM_NO_ERR)
- return DOM_HUBBUB_HUBBUB_ERR | HUBBUB_UNKNOWN;
-
- _dom_document_set_id_name(parser->doc, name);
- dom_string_unref(name);
-
return DOM_HUBBUB_OK;
}
--
Document Object Model library
10 years, 4 months
netsurf: branch master updated. 70f168b5037a86186af810fbe8d34410ee295456
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/70f168b5037a86186af81...
...commit http://git.netsurf-browser.org/netsurf.git/commit/70f168b5037a86186af810f...
...tree http://git.netsurf-browser.org/netsurf.git/tree/70f168b5037a86186af810fbe...
The branch, master has been updated
via 70f168b5037a86186af810fbe8d34410ee295456 (commit)
via 9ab851a5a9f951a8d2e7e285489245bee2cd0303 (commit)
from efbfbbc96732ba7b0b8f526b07c776908c79533b (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/70f168b5037a86186af...
commit 70f168b5037a86186af810fbe8d34410ee295456
Merge: 9ab851a efbfbbc
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Merge branch 'master' of git://git.netsurf-browser.org/netsurf
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/9ab851a5a9f951a8d2e...
commit 9ab851a5a9f951a8d2e7e285489245bee2cd0303
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Fix join with rel part of " ". Add a few tests.
diff --git a/test/nsurl.c b/test/nsurl.c
index 20109f8..66bc057 100644
--- a/test/nsurl.c
+++ b/test/nsurl.c
@@ -136,6 +136,12 @@ static const struct test_pairs join_tests[] = {
{ "http://", "http:" },
{ "http:/", "http:" },
{ "http:", "http:" },
+ { " ", "http://a/b/c/d;p?q" },
+ { " ", "http://a/b/c/d;p?q" },
+ { "/", "http://a/" },
+ { " / ", "http://a/" },
+ { " ? ", "http://a/b/c/d;p?" },
+ { " h ", "http://a/b/c/h" },
/* [1] Extra slash beyond rfc3986 5.4.1 example, since we're
* testing normalisation in addition to joining */
/* [2] Using the strict parsers option */
diff --git a/utils/nsurl.c b/utils/nsurl.c
index 8c52545..18577b6 100644
--- a/utils/nsurl.c
+++ b/utils/nsurl.c
@@ -264,6 +264,13 @@ static void nsurl__get_string_markers(const char * const url_s,
marker.scheme_end = marker.authority = marker.colon_first = marker.at =
marker.colon_last = marker.path = marker.start;
+ if (*pos == '\0') {
+ /* Nothing but whitespace, early exit */
+ marker.query = marker.fragment = marker.end = marker.path;
+ *markers = marker;
+ return;
+ }
+
/* Get scheme */
if (isalpha(*pos)) {
pos++;
-----------------------------------------------------------------------
Summary of changes:
test/nsurl.c | 6 ++++++
utils/nsurl.c | 7 +++++++
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/test/nsurl.c b/test/nsurl.c
index 20109f8..66bc057 100644
--- a/test/nsurl.c
+++ b/test/nsurl.c
@@ -136,6 +136,12 @@ static const struct test_pairs join_tests[] = {
{ "http://", "http:" },
{ "http:/", "http:" },
{ "http:", "http:" },
+ { " ", "http://a/b/c/d;p?q" },
+ { " ", "http://a/b/c/d;p?q" },
+ { "/", "http://a/" },
+ { " / ", "http://a/" },
+ { " ? ", "http://a/b/c/d;p?" },
+ { " h ", "http://a/b/c/h" },
/* [1] Extra slash beyond rfc3986 5.4.1 example, since we're
* testing normalisation in addition to joining */
/* [2] Using the strict parsers option */
diff --git a/utils/nsurl.c b/utils/nsurl.c
index 8c52545..18577b6 100644
--- a/utils/nsurl.c
+++ b/utils/nsurl.c
@@ -264,6 +264,13 @@ static void nsurl__get_string_markers(const char * const url_s,
marker.scheme_end = marker.authority = marker.colon_first = marker.at =
marker.colon_last = marker.path = marker.start;
+ if (*pos == '\0') {
+ /* Nothing but whitespace, early exit */
+ marker.query = marker.fragment = marker.end = marker.path;
+ *markers = marker;
+ return;
+ }
+
/* Get scheme */
if (isalpha(*pos)) {
pos++;
--
NetSurf Browser
10 years, 4 months
netsurf: branch vince/nsgenbind updated. 2b6bd44ef0aec9c99617e7125bda918545be7316
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/2b6bd44ef0aec9c99617e...
...commit http://git.netsurf-browser.org/netsurf.git/commit/2b6bd44ef0aec9c99617e71...
...tree http://git.netsurf-browser.org/netsurf.git/tree/2b6bd44ef0aec9c99617e7125...
The branch, vince/nsgenbind has been updated
via 2b6bd44ef0aec9c99617e7125bda918545be7316 (commit)
via b34cbc5e8303fba36712d48af65d8eefb1097890 (commit)
via 2b8cdf1f295cc65c5f6935f067289fdb35e3349d (commit)
via 8f08f820f4d17173c08d121a1bd50e1afe66724c (commit)
from 5496a604310b65db0513c063ed171f0168baee28 (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/2b6bd44ef0aec9c9961...
commit 2b6bd44ef0aec9c99617e7125bda918545be7316
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
add location binding
diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript
index 3fb1fb2..58b8860 100644
--- a/Makefile.sources.javascript
+++ b/Makefile.sources.javascript
@@ -15,6 +15,7 @@ JSAPI_BINDING_htmlelement := javascript/jsapi/bindings/htmlelement.bnd
JSAPI_BINDING_window := javascript/jsapi/bindings/window.bnd
JSAPI_BINDING_navigator := javascript/jsapi/bindings/navigator.bnd
JSAPI_BINDING_console := javascript/jsapi/bindings/console.bnd
+JSAPI_BINDING_location := javascript/jsapi/bindings/location.bnd
# 1: input file
# 2: output file
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index 8b32e91..68ab6d1 100644
--- a/javascript/jsapi/binding.h
+++ b/javascript/jsapi/binding.h
@@ -41,6 +41,12 @@ JSObject *jsapi_new_Window(JSContext *cx,
struct browser_window *bw,
html_content *htmlc);
+JSObject *jsapi_InitClass_Location(JSContext *cx, JSObject *parent);
+JSObject *jsapi_new_Location(JSContext *cx,
+ JSObject *window,
+ JSObject *parent,
+ struct browser_window *bw);
+
JSObject *jsapi_InitClass_Document(JSContext *cx, JSObject *parent);
diff --git a/javascript/jsapi/bindings/location.bnd b/javascript/jsapi/bindings/location.bnd
new file mode 100644
index 0000000..c83fe46
--- /dev/null
+++ b/javascript/jsapi/bindings/location.bnd
@@ -0,0 +1,53 @@
+/* Binding to generate Location interface
+ *
+ * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+#include "dom.bnd"
+
+webidlfile "html.idl";
+
+hdrcomment "Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>";
+hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
+hdrcomment "Released under the terms of the MIT License,";
+hdrcomment " http://www.opensource.org/licenses/mit-license";
+
+preamble %{
+
+#include "desktop/browser.h"
+
+#include "utils/config.h"
+#include "utils/log.h"
+
+#include "javascript/jsapi.h"
+#include "javascript/jsapi/binding.h"
+
+%}
+
+binding location {
+ type js_libdom; /* the binding type */
+
+ interface Location; /* Web IDL interface to generate */
+
+ /* private members:
+ * - stored in private context structure.
+ * - passed as parameters to constructor and stored automatically.
+ * - are *not* considered for property getters/setters.
+ *
+ * internal members:
+ * - value stored in private context structure
+ * - not passed to constructor
+ * - must be instantiated by constructor
+ * - are considered for property getters/setters.
+ */
+ private "struct browser_window *" bw;
+}
+
+operation reload %{
+ browser_window_reload(private->bw, false);
+%}
diff --git a/javascript/jsapi/bindings/window.bnd b/javascript/jsapi/bindings/window.bnd
index beb2b12..956932c 100644
--- a/javascript/jsapi/bindings/window.bnd
+++ b/javascript/jsapi/bindings/window.bnd
@@ -18,25 +18,26 @@ preamble %{
%}
-operation confirm %{
- warn_user(message, NULL);
-%}
-
-operation alert %{
- warn_user(message, NULL);
-%}
-
-operation prompt %{
- warn_user(message, NULL);
-%}
-
-getter window %{
- jsret = obj;
-%}
+binding window {
+ type js_libdom; /* the binding type */
+
+ interface Window; /* Web IDL interface to generate */
+
+ /* private are parameters to constructor stored in private
+ * context structure.
+ *
+ * internal are value stored in private context structure but not
+ * passed to constructor but are considered for property
+ * getters/setters.
+ */
+ private "struct browser_window *" bw;
+ private "struct html_content *" htmlc;
+ internal "JSObject *" document;
+ internal "JSObject *" navigator;
+ internal "JSObject *" console;
+ internal "JSObject *" location;
+}
-getter self %{
- jsret = obj;
-%}
api init %{
JSObject *user_proto;
@@ -85,6 +86,11 @@ api init %{
return NULL;
}
+ user_proto = jsapi_InitClass_Location(cx, prototype);
+ if (user_proto == NULL) {
+ return NULL;
+ }
+
user_proto = jsapi_InitClass_Console(cx, prototype);
if (user_proto == NULL) {
return NULL;
@@ -121,7 +127,11 @@ api new %{
return NULL;
}
- /** @todo forms, history, location */
+ private->location = jsapi_new_Location(cx, NULL, newobject, bw);
+ if (private->location == NULL) {
+ free(private);
+ return NULL;
+ }
private->console = jsapi_new_Console(cx, NULL, newobject);
if (private->console == NULL) {
@@ -129,25 +139,27 @@ api new %{
return NULL;
}
+ /** @todo forms, history */
+
LOG(("Created new window object %p", newobject));
%}
+operation confirm %{
+ warn_user(message, NULL);
+%}
-binding window {
- type js_libdom; /* the binding type */
-
- interface Window; /* Web IDL interface to generate */
-
- /* private are parameters to constructor stored in private
- * context structure.
- *
- * internal are value stored in private context structure but not
- * passed to constructor but are considered for property getters/setters.
- */
- private "struct browser_window *" bw;
- private "struct html_content *" htmlc;
- internal "JSObject *" document;
- internal "JSObject *" navigator;
- internal "JSObject *" console;
+operation alert %{
+ warn_user(message, NULL);
+%}
-}
+operation prompt %{
+ warn_user(message, NULL);
+%}
+
+getter window %{
+ jsret = obj;
+%}
+
+getter self %{
+ jsret = obj;
+%}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/b34cbc5e8303fba3671...
commit b34cbc5e8303fba36712d48af65d8eefb1097890
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
remove old handmade binding code
diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript
index 51db26f..3fb1fb2 100644
--- a/Makefile.sources.javascript
+++ b/Makefile.sources.javascript
@@ -33,7 +33,6 @@ endef
ifeq ($(NETSURF_USE_JS),YES)
S_JSAPI =
-# htmlelement.c htmldocument.c window.c navigator.c console.c
S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI))
diff --git a/javascript/jsapi/console.c b/javascript/jsapi/console.c
deleted file mode 100644
index 3cd5188..0000000
--- a/javascript/jsapi/console.c
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "utils/log.h"
-
-#include "javascript/jsapi.h"
-
-static JSBool JSAPI_NATIVE(debug, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(dir, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(error, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(group, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(groupCollapsed, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(groupEnd, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(info, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(log, JSContext *cx, uintN argc, jsval *vp)
-{
- unsigned int argloop;
- JSString *jsstr;
- unsigned long jsstrlen;
- char *txt;
-
- for (argloop = 0; argloop < argc; argloop++) {
- jsstr = JS_ValueToString(cx, *JSAPI_ARGV(cx, vp + argloop));
-
- JSString_to_char(jsstr, txt, jsstrlen);
- LOG(("%s", txt));
- }
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(time, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(timeEnd, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(trace, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(warn, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSFunctionSpec jsfunctions_console[] = {
- JSAPI_FS(debug, 1, 0),
- JSAPI_FS(dir, 1, 0),
- JSAPI_FS(error, 1, 0),
- JSAPI_FS(group, 1, 0),
- JSAPI_FS(groupCollapsed, 1, 0),
- JSAPI_FS(groupEnd, 1, 0),
- JSAPI_FS(info, 1, 0),
- JSAPI_FS(log, 1, 0),
- JSAPI_FS(time, 1, 0),
- JSAPI_FS(timeEnd, 1, 0),
- JSAPI_FS(trace, 1, 0),
- JSAPI_FS(warn, 1, 0),
- JSAPI_FS_END
-};
-
-static JSClass jsclass_console =
-{
- "console",
- JSCLASS_HAS_PRIVATE,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- JS_FinalizeStub,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-JSObject *jsapi_new_Console(JSContext *cx, JSObject *parent)
-{
- return JS_InitClass(cx,
- parent,
- NULL,
- &jsclass_console,
- NULL,
- 0,
- NULL,
- jsfunctions_console,
- NULL,
- NULL);
-}
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
deleted file mode 100644
index 2d3bde4..0000000
--- a/javascript/jsapi/document.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-document
-
-interface Document : Node {
- readonly attribute DOMImplementation implementation;
- readonly attribute DOMString URL;
- readonly attribute DOMString documentURI;
- readonly attribute DOMString compatMode;
- readonly attribute DOMString characterSet;
- readonly attribute DOMString contentType;
-
- readonly attribute DocumentType? doctype;
- readonly attribute Element? documentElement;
- HTMLCollection getElementsByTagName(DOMString localName);
- HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
- HTMLCollection getElementsByClassName(DOMString classNames);
- Element? getElementById(DOMString elementId);
-
- Element createElement(DOMString localName);
- Element createElementNS(DOMString? namespace, DOMString qualifiedName);
- DocumentFragment createDocumentFragment();
- Text createTextNode(DOMString data);
- Comment createComment(DOMString data);
- ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data);
-
- Node importNode(Node node, optional boolean deep = true);
- Node adoptNode(Node node);
-
- Event createEvent(DOMString interface);
-
- Range createRange();
-
- // NodeFilter.SHOW_ALL = 0xFFFFFFFF
- NodeIterator createNodeIterator(Node root, optional unsigned long whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null);
- TreeWalker createTreeWalker(Node root, optional unsigned long whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null);
-
- // NEW
- void prepend((Node or DOMString)... nodes);
- void append((Node or DOMString)... nodes);
-};
-
-
- */
-
-#include "jsclass.h"
-
-#include "node.c"
-
-static JSBool JSAPI_NATIVE(getElementById, JSContext *cx, uintN argc, jsval *vp)
-{
- JSString* u16_txt;
- char *txt;
- unsigned long txtlen;
- dom_string *idstr;
- dom_element *idelement;
- struct jsclass_document_priv *document;
-
- document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (document == NULL) {
- return JS_FALSE;
- }
-
- if (document->node == NULL) {
- /* no document available, this is obviously a problem
- * for finding elements
- */
- JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
-
- return JS_TRUE;
- }
-
- if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
- return JS_FALSE;
-
- JSString_to_char(u16_txt, txt, txtlen);
-
- dom_string_create((unsigned char*)txt, txtlen, &idstr);
-
- dom_document_get_element_by_id(document->node, idstr, &idelement);
-
- JSAPI_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsapi_new_element(cx, JS_GetGlobalObject(cx), document->htmlc, idelement)));
-
- return JS_TRUE;
-}
-
-#define JSAPI_FS_DOCUMENT \
- JSAPI_FS_NODE, \
- JSAPI_FS(getElementById, 1, 0) \
-
-
-#define JSAPI_PS_DOCUMENT \
- JSAPI_PS_NODE
diff --git a/javascript/jsapi/domexception.c b/javascript/jsapi/domexception.c
deleted file mode 100644
index b7c61cf..0000000
--- a/javascript/jsapi/domexception.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <dom/dom.h>
-
-
-#include "javascript/jsapi.h"
-#include "utils/config.h"
-#include "render/html_internal.h"
-#include "utils/log.h"
-
-/* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#exception-domexc...
-exception DOMException {
- const unsigned short INDEX_SIZE_ERR = 1;
- const unsigned short DOMSTRING_SIZE_ERR = 2; // historical
- const unsigned short HIERARCHY_REQUEST_ERR = 3;
- const unsigned short WRONG_DOCUMENT_ERR = 4;
- const unsigned short INVALID_CHARACTER_ERR = 5;
- const unsigned short NO_DATA_ALLOWED_ERR = 6; // historical
- const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7;
- const unsigned short NOT_FOUND_ERR = 8;
- const unsigned short NOT_SUPPORTED_ERR = 9;
- const unsigned short INUSE_ATTRIBUTE_ERR = 10; // historical
- const unsigned short INVALID_STATE_ERR = 11;
- const unsigned short SYNTAX_ERR = 12;
- const unsigned short INVALID_MODIFICATION_ERR = 13;
- const unsigned short NAMESPACE_ERR = 14;
- const unsigned short INVALID_ACCESS_ERR = 15;
- const unsigned short VALIDATION_ERR = 16; // historical
- const unsigned short TYPE_MISMATCH_ERR = 17;
- const unsigned short SECURITY_ERR = 18;
- const unsigned short NETWORK_ERR = 19;
- const unsigned short ABORT_ERR = 20;
- const unsigned short URL_MISMATCH_ERR = 21;
- const unsigned short QUOTA_EXCEEDED_ERR = 22;
- const unsigned short TIMEOUT_ERR = 23;
- const unsigned short INVALID_NODE_TYPE_ERR = 24;
- const unsigned short DATA_CLONE_ERR = 25;
- unsigned short code;
-};
-
-*/
-
-static JSClass jsclass_domexception =
-{
- "DOMException",
- JSCLASS_HAS_PRIVATE,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- JS_FinalizeStub,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-
-JSObject *
-jsapi_new_domexception(JSContext *cx,
- JSObject *parent,
- int code)
-{
- /* create element object and return it*/
- JSObject *jsdomexception;
-
- jssomexception = JS_InitClass(cx,
- parent,
- NULL,
- &jsclass_domexception,
- NULL,
- 0,
- NULL,
- NULL,
- NULL,
- NULL);
- if (jsdomexecption == NULL) {
- return NULL;
- }
-
- LOG(("setting element private to %d", code));
- /* private pointer to browsing context */
- if (JS_SetPrivate(cx, jsdomexception, code) != JS_TRUE) {
- LOG(("failed to set content"));
- return NULL;
- }
-
- return jsdomexception;
-}
diff --git a/javascript/jsapi/element.c b/javascript/jsapi/element.c
deleted file mode 100644
index d301321..0000000
--- a/javascript/jsapi/element.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-element
-
-
-interface Element : Node {
- readonly attribute DOMString? namespaceURI;
- readonly attribute DOMString? prefix;
- readonly attribute DOMString localName;
- readonly attribute DOMString tagName;
-
- attribute DOMString id;
- attribute DOMString className;
- readonly attribute DOMTokenList classList;
-
- readonly attribute Attr[] attributes;
- DOMString? getAttribute(DOMString name);
- DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
- void setAttribute(DOMString name, DOMString value);
- void setAttributeNS(DOMString? namespace, DOMString name, DOMString value);
- void removeAttribute(DOMString name);
- void removeAttributeNS(DOMString? namespace, DOMString localName);
- boolean hasAttribute(DOMString name);
- boolean hasAttributeNS(DOMString? namespace, DOMString localName);
-
- HTMLCollection getElementsByTagName(DOMString localName);
- HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
- HTMLCollection getElementsByClassName(DOMString classNames);
-
- readonly attribute HTMLCollection children;
- readonly attribute Element? firstElementChild;
- readonly attribute Element? lastElementChild;
- readonly attribute Element? previousElementSibling;
- readonly attribute Element? nextElementSibling;
- readonly attribute unsigned long childElementCount;
-
- // NEW
- void prepend((Node or DOMString)... nodes);
- void append((Node or DOMString)... nodes);
- void before((Node or DOMString)... nodes);
- void after((Node or DOMString)... nodes);
- void replace((Node or DOMString)... nodes);
- void remove();
-};
-*/
-
-#include "jsclass.h"
-
-#include "node.c"
-
-static JSBool JSAPI_NATIVE(getAttribute, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
-
- return JS_TRUE;
-}
-
-#define JSAPI_FS_ELEMENT \
- JSAPI_FS_NODE, \
- JSAPI_FS(getAttribute, 0, 0)
-
-static JSBool JSAPI_PROPERTYGET(id, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, JSVAL_NULL);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(id, JSContext *cx, JSObject *obj, jsval *vp)
-{
- return JS_FALSE;
-}
-
-#define JSAPI_PS_ELEMENT \
- JSAPI_PS_NODE, \
- JSAPI_PS(id, 0, JSPROP_ENUMERATE | JSPROP_SHARED)
diff --git a/javascript/jsapi/eventtarget.c b/javascript/jsapi/eventtarget.c
deleted file mode 100644
index e2ab6a9..0000000
--- a/javascript/jsapi/eventtarget.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#eventtarget
-
-interface EventTarget {
- void addEventListener(DOMString type, EventListener? callback, optional boolean capture = false);
- void removeEventListener(DOMString type, EventListener? callback, optional boolean capture = false);
- boolean dispatchEvent(Event event);
-};
-*/
-
-#include "jsclass.h"
-
-static JSBool JSAPI_NATIVE(addEventListener, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(removeEventListener, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(dispatchEvent, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-#define JSAPI_FS_EVENTTARGET \
- JSAPI_FS(addEventListener, 0, 0), \
- JSAPI_FS(removeEventListener, 0, 0), \
- JSAPI_FS(dispatchEvent, 0, 0)
diff --git a/javascript/jsapi/htmldocument.c b/javascript/jsapi/htmldocument.c
deleted file mode 100644
index 8b38acd..0000000
--- a/javascript/jsapi/htmldocument.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <dom/dom.h>
-
-#include "utils/config.h"
-#include "utils/log.h"
-
-#include "javascript/jsapi.h"
-
-/* IDL http://www.whatwg.org/specs/web-apps/current-work/#the-document-object
-
-[OverrideBuiltins]
-partial interface Document {
- // resource metadata management
- [PutForwards=href] readonly attribute Location? location;
- attribute DOMString domain;
- readonly attribute DOMString referrer;
- attribute DOMString cookie;
- readonly attribute DOMString lastModified;
- readonly attribute DOMString readyState;
-
- // DOM tree accessors
- getter object (DOMString name);
- attribute DOMString title;
- attribute DOMString dir;
- attribute HTMLElement? body;
- readonly attribute HTMLHeadElement? head;
- readonly attribute HTMLCollection images;
- readonly attribute HTMLCollection embeds;
- readonly attribute HTMLCollection plugins;
- readonly attribute HTMLCollection links;
- readonly attribute HTMLCollection forms;
- readonly attribute HTMLCollection scripts;
- NodeList getElementsByName(DOMString elementName);
- NodeList getItems(optional DOMString typeNames); // microdata
- readonly attribute DOMElementMap cssElementMap;
-
- // dynamic markup insertion
- Document open(optional DOMString type, optional DOMString replace);
- WindowProxy open(DOMString url, DOMString name, DOMString features, optional boolean replace);
- void close();
- void write(DOMString... text);
- void writeln(DOMString... text);
-
- // user interaction
- readonly attribute WindowProxy? defaultView;
- readonly attribute Element? activeElement;
- boolean hasFocus();
- attribute DOMString designMode;
- boolean execCommand(DOMString commandId);
- boolean execCommand(DOMString commandId, boolean showUI);
- boolean execCommand(DOMString commandId, boolean showUI, DOMString value);
- boolean queryCommandEnabled(DOMString commandId);
- boolean queryCommandIndeterm(DOMString commandId);
- boolean queryCommandState(DOMString commandId);
- boolean queryCommandSupported(DOMString commandId);
- DOMString queryCommandValue(DOMString commandId);
- readonly attribute HTMLCollection commands;
-
- // event handler IDL attributes
- attribute EventHandler onabort;
- attribute EventHandler onblur;
- attribute EventHandler oncancel;
- attribute EventHandler oncanplay;
- attribute EventHandler oncanplaythrough;
- attribute EventHandler onchange;
- attribute EventHandler onclick;
- attribute EventHandler onclose;
- attribute EventHandler oncontextmenu;
- attribute EventHandler oncuechange;
- attribute EventHandler ondblclick;
- attribute EventHandler ondrag;
- attribute EventHandler ondragend;
- attribute EventHandler ondragenter;
- attribute EventHandler ondragleave;
- attribute EventHandler ondragover;
- attribute EventHandler ondragstart;
- attribute EventHandler ondrop;
- attribute EventHandler ondurationchange;
- attribute EventHandler onemptied;
- attribute EventHandler onended;
- attribute OnErrorEventHandler onerror;
- attribute EventHandler onfocus;
- attribute EventHandler oninput;
- attribute EventHandler oninvalid;
- attribute EventHandler onkeydown;
- attribute EventHandler onkeypress;
- attribute EventHandler onkeyup;
- attribute EventHandler onload;
- attribute EventHandler onloadeddata;
- attribute EventHandler onloadedmetadata;
- attribute EventHandler onloadstart;
- attribute EventHandler onmousedown;
- attribute EventHandler onmousemove;
- attribute EventHandler onmouseout;
- attribute EventHandler onmouseover;
- attribute EventHandler onmouseup;
- attribute EventHandler onmousewheel;
- attribute EventHandler onpause;
- attribute EventHandler onplay;
- attribute EventHandler onplaying;
- attribute EventHandler onprogress;
- attribute EventHandler onratechange;
- attribute EventHandler onreset;
- attribute EventHandler onscroll;
- attribute EventHandler onseeked;
- attribute EventHandler onseeking;
- attribute EventHandler onselect;
- attribute EventHandler onshow;
- attribute EventHandler onstalled;
- attribute EventHandler onsubmit;
- attribute EventHandler onsuspend;
- attribute EventHandler ontimeupdate;
- attribute EventHandler onvolumechange;
- attribute EventHandler onwaiting;
-
- // special event handler IDL attributes that only apply to Document objects
- [LenientThis] attribute EventHandler onreadystatechange;
-};
-
- */
-
-static void jsfinalize_document(JSContext *cx, JSObject *obj);
-static JSBool jsresove_node(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp);
-
-struct jsclass_document_priv {
- struct html_content *htmlc;
- dom_document *node;
-};
-
-
-#define JSCLASS_NAME document
-
-#include "jsclass.h"
-
-static JSClass JSCLASS_OBJECT =
-{
- "document",
- JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- (JSResolveOp)jsresove_node,
- JS_ConvertStub,
- jsfinalize_document,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-#include "document.c"
-
-static JSBool jsresove_node(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
-{
- *objp = NULL;
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(write, JSContext *cx, uintN argc, jsval *vp)
-{
- JSString* u16_txt;
- char *txt;
- unsigned long length;
- struct jsclass_document_priv *document;
-
- document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (document == NULL) {
- return JS_FALSE;
- }
-
- if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt)) {
- return JS_FALSE;
- }
-
- JSString_to_char(u16_txt, txt, length);
-
- LOG(("content %p parser %p writing %s",
- document->htmlc, document->htmlc->parser, txt));
- if (document->htmlc->parser != NULL) {
- dom_hubbub_parser_insert_chunk(document->htmlc->parser, (uint8_t *)txt, length);
- }
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSFunctionSpec jsfunctions_document[] = {
- JSAPI_FS_DOCUMENT,
- JSAPI_FS(write, 1, 0),
- JSAPI_FS_END
-};
-
-static JSPropertySpec jsproperties_document[] =
-{
- JSAPI_PS_DOCUMENT,
- JSAPI_PS_END
-};
-
-static void jsfinalize_document(JSContext *cx, JSObject *obj)
-{
- struct jsclass_document_priv *document;
-
- document = JS_GetInstancePrivate(cx, obj, &JSCLASS_OBJECT, NULL);
- if (document != NULL) {
- free(document);
- }
-}
-
-JSObject *jsapi_new_document(JSContext *cx, JSObject *parent, struct html_content *htmlc)
-{
- /* create document object and return it */
- JSObject *jsdocument;
- struct jsclass_document_priv *document;
-
- document = malloc(sizeof(*document));
- if (document == NULL) {
- return NULL;
- }
- document->htmlc = htmlc;
- document->node = htmlc->document;
-
- jsdocument = JS_InitClass(cx,
- parent,
- NULL,
- &JSCLASS_OBJECT,
- NULL,
- 0,
- jsproperties_document,
- jsfunctions_document,
- NULL,
- NULL);
- if (jsdocument == NULL) {
- free(document);
- return NULL;
- }
-
- LOG(("setting document private to %p", document));
- /* private pointer to browsing context */
- if (JS_SetPrivate(cx, jsdocument, document) != JS_TRUE) {
- LOG(("failed to set document private"));
- free(document);
- return NULL;
- }
-
- return jsdocument;
-}
diff --git a/javascript/jsapi/htmlelement.c b/javascript/jsapi/htmlelement.c
deleted file mode 100644
index a7846ba..0000000
--- a/javascript/jsapi/htmlelement.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <dom/dom.h>
-
-#include "utils/config.h"
-#include "utils/log.h"
-#include "render/html_internal.h"
-
-#include "javascript/jsapi.h"
-
-/* IDL http://www.whatwg.org/specs/web-apps/current-work/#elements-in-the-dom
-
-CAUTION - innerHTML and outerHTML etc. are part of the DOM parsing
- specification but more can be found in:
-http://html5.org/specs/dom-parsing.html#extensions-to-the-element-interface
-
-interface HTMLElement : Element {
- // metadata attributes
- attribute DOMString title;
- attribute DOMString lang;
- attribute boolean translate;
- attribute DOMString dir;
- readonly attribute DOMStringMap dataset;
-
- // microdata
- attribute boolean itemScope;
- [PutForwards=value] readonly attribute DOMSettableTokenList itemType;
- attribute DOMString itemId;
- [PutForwards=value] readonly attribute DOMSettableTokenList itemRef;
- [PutForwards=value] readonly attribute DOMSettableTokenList itemProp;
- readonly attribute HTMLPropertiesCollection properties;
- attribute any itemValue;
-
- // user interaction
- attribute boolean hidden;
- void click();
- attribute long tabIndex;
- void focus();
- void blur();
- attribute DOMString accessKey;
- readonly attribute DOMString accessKeyLabel;
- attribute boolean draggable;
- [PutForwards=value] readonly attribute DOMSettableTokenList dropzone;
- attribute DOMString contentEditable;
- readonly attribute boolean isContentEditable;
- attribute HTMLMenuElement? contextMenu;
- attribute boolean spellcheck;
-
- // command API
- readonly attribute DOMString? commandType;
- readonly attribute DOMString? commandLabel;
- readonly attribute DOMString? commandIcon;
- readonly attribute boolean? commandHidden;
- readonly attribute boolean? commandDisabled;
- readonly attribute boolean? commandChecked;
-
- // styling
- readonly attribute CSSStyleDeclaration style;
-
- // event handler IDL attributes
- attribute EventHandler onabort;
- attribute EventHandler onblur;
- attribute EventHandler oncancel;
- attribute EventHandler oncanplay;
- attribute EventHandler oncanplaythrough;
- attribute EventHandler onchange;
- attribute EventHandler onclick;
- attribute EventHandler onclose;
- attribute EventHandler oncontextmenu;
- attribute EventHandler oncuechange;
- attribute EventHandler ondblclick;
- attribute EventHandler ondrag;
- attribute EventHandler ondragend;
- attribute EventHandler ondragenter;
- attribute EventHandler ondragleave;
- attribute EventHandler ondragover;
- attribute EventHandler ondragstart;
- attribute EventHandler ondrop;
- attribute EventHandler ondurationchange;
- attribute EventHandler onemptied;
- attribute EventHandler onended;
- attribute OnErrorEventHandler onerror;
- attribute EventHandler onfocus;
- attribute EventHandler oninput;
- attribute EventHandler oninvalid;
- attribute EventHandler onkeydown;
- attribute EventHandler onkeypress;
- attribute EventHandler onkeyup;
- attribute EventHandler onload;
- attribute EventHandler onloadeddata;
- attribute EventHandler onloadedmetadata;
- attribute EventHandler onloadstart;
- attribute EventHandler onmousedown;
- attribute EventHandler onmousemove;
- attribute EventHandler onmouseout;
- attribute EventHandler onmouseover;
- attribute EventHandler onmouseup;
- attribute EventHandler onmousewheel;
- attribute EventHandler onpause;
- attribute EventHandler onplay;
- attribute EventHandler onplaying;
- attribute EventHandler onprogress;
- attribute EventHandler onratechange;
- attribute EventHandler onreset;
- attribute EventHandler onscroll;
- attribute EventHandler onseeked;
- attribute EventHandler onseeking;
- attribute EventHandler onselect;
- attribute EventHandler onshow;
- attribute EventHandler onstalled;
- attribute EventHandler onsubmit;
- attribute EventHandler onsuspend;
- attribute EventHandler ontimeupdate;
- attribute EventHandler onvolumechange;
- attribute EventHandler onwaiting;
-};
-
-*/
-
-static void jsfinalize_element(JSContext *cx, JSObject *obj);
-
-struct jsclass_document_priv {
- struct html_content *htmlc;
- dom_element *node;
-};
-
-#define JSCLASS_NAME htmlelement
-
-#include "jsclass.h"
-
-static JSClass JSCLASS_OBJECT =
-{
- "HTMLElement",
- JSCLASS_HAS_PRIVATE,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- jsfinalize_element,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-#include "element.c"
-
-static void jsfinalize_element(JSContext *cx, JSObject *obj)
-{
- struct jsclass_document_priv *element;
- element = JS_GetInstancePrivate(cx, obj, &JSCLASS_OBJECT, NULL);
- if (element != NULL) {
- free(element);
- }
-}
-
-
-
-static JSFunctionSpec jsfunctions_element[] = {
- JSAPI_FS_ELEMENT,
- JSAPI_FS_END
-};
-
-
-
-
-static JSPropertySpec jsproperties_element[] =
-{
- JSAPI_PS_ELEMENT,
- JSAPI_PS_END
-};
-
-JSObject *
-jsapi_new_element(JSContext *cx,
- JSObject *parent,
- struct html_content *htmlc,
- dom_element *domelement)
-{
- /* create element object and return it */
- JSObject *jselement;
- struct jsclass_document_priv *element;
-
- element = malloc(sizeof(element));
- if (element == NULL) {
- return NULL;
- }
- element->htmlc = htmlc;
- element->node = domelement;
-
- jselement = JS_InitClass(cx,
- parent,
- NULL,
- &JSCLASS_OBJECT,
- NULL,
- 0,
- jsproperties_element,
- jsfunctions_element,
- NULL,
- NULL);
- if (jselement == NULL) {
- free(element);
- return NULL;
- }
-
- LOG(("setting private to %p", element));
- /* private pointer to browsing context */
- if (JS_SetPrivate(cx, jselement, element) != JS_TRUE) {
- LOG(("failed to set private"));
- free(element);
- return NULL;
- }
-
- return jselement;
-}
diff --git a/javascript/jsapi/jsclass.h b/javascript/jsapi/jsclass.h
deleted file mode 100644
index 30b926a..0000000
--- a/javascript/jsapi/jsclass.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/** \file
- * jsapi pseudo class glue.
- */
-
-#ifndef _NETSURF_JAVASCRIPT_JSAPI_JSCLASS_H_
-#define _NETSURF_JAVASCRIPT_JSAPI_JSCLASS_H_
-
-#ifndef JSCLASS_NAME
-#error "The class name must be defined"
-#endif
-
-#ifndef JSCLASS_TYPE
-#define CLASS jsclass
-#define PRIVATE priv
-#define EXPAND(a,b) PASTE(a,b)
-#define PASTE(x,y) x##_##y
-#define JSCLASS_OBJECT EXPAND(CLASS,JSCLASS_NAME)
-#define JSCLASS_TYPE EXPAND(JSCLASS_OBJECT,PRIVATE)
-#endif
-
-#endif
diff --git a/javascript/jsapi/navigator.c b/javascript/jsapi/navigator.c
deleted file mode 100644
index 88fc535..0000000
--- a/javascript/jsapi/navigator.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <assert.h>
-#include <stdlib.h>
-
-#include "desktop/netsurf.h"
-#include "desktop/options.h"
-
-#include "utils/config.h"
-#include "utils/useragent.h"
-#include "utils/log.h"
-#include "utils/utsname.h"
-
-#include "javascript/jsapi.h"
-
-/*
- * navigator properties for netsurf
- *
- * Property | Everyone else | NetSurf | Notes
- * ------------+-----------------+--------------+------------------------------
- * appCodeName | "Mozilla" | "NetSurf" | This is kinda a pointless
- * | | | constant as everyone returns
- * | | | "Mozilla" which is dumb
- * ------------+-----------------+--------------+------------------------------
- * appName | "<Browsername>" | "NetSurf" | Browsers named other than
- * | | | "Netscape", "Mozilla",
- * | | | "Netscape Navigator",
- * | | | "Microsoft Internet Explorer"
- * | | | often other browser have
- * | | | "(compatible with Netscape)"
- * | | | append.
- * ------------+-----------------+--------------+------------------------------
- * appVersion | "<ver> (<type>)"| "<ver>" | Actually just the version
- * | | | number e.g "3.0".
- * ------------+-----------------+--------------+------------------------------
- * language | "<lang>" | "<lang>" | The language the frontend is
- * | | | configured for
- * ------------+-----------------+--------------+------------------------------
- * platform | "<krn> <hw>" | "<krn> <hw>" | Efectively uname -s -i,
- * | | | eg "Linux x86_64"
- * ------------+-----------------+--------------+------------------------------
- * userAgent | "Mozilla/5.0 (" | "NetSurf" | The usual useragent string
- * | | | with excessive lies
- * ------------+-----------------+--------------+------------------------------
- */
-
-static JSFunctionSpec jsfunctions_navigator[] = {
- JS_FS_END
-};
-
-#define NAVIGATOR_APPNAME "NetSurf"
-#define NAVIGATOR_APPCODENAME "NetSurf"
-
-static JSBool JSAPI_PROPERTYGET(appName, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME)));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(appName, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-static JSBool JSAPI_PROPERTYGET(appCodeName, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME)));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(appCodeName, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-static JSBool JSAPI_PROPERTYGET(appVersion, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, netsurf_version)));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(appVersion, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-static JSBool JSAPI_PROPERTYGET(language, JSContext *cx, JSObject *obj, jsval *vp)
-{
- const char *alang = nsoption_charp(accept_language);
-
- if (alang != NULL) {
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, alang)));
- } else {
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- }
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(language, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-static JSBool JSAPI_PROPERTYGET(platform, JSContext *cx, JSObject *obj, jsval *vp)
-{
- struct utsname *cutsname;
-
- cutsname = malloc(sizeof(struct utsname));
-
- if ((cutsname == NULL) || uname(cutsname) < 0) {
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- } else {
- char *platstr;
- int platstrlen;
- platstrlen = strlen(cutsname->sysname) + strlen(cutsname->machine) + 2;
- platstr = malloc(platstrlen);
- if (platstr != NULL) {
- snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine);
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyN(cx, platstr, platstrlen - 1)));
- free(platstr);
- } else {
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- }
- }
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(platform, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-static JSBool JSAPI_PROPERTYGET(userAgent, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, user_agent_string())));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(userAgent, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-
-static JSPropertySpec jsproperties_navigator[] =
-{
- JSAPI_PS(appName, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS(appCodeName, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS(appVersion, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS(language, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS(platform, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS(userAgent, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS_END
-};
-
-static JSClass jsclass_navigator =
-{
- "navigator",
- JSCLASS_HAS_PRIVATE,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- JS_FinalizeStub,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-JSObject *jsapi_new_navigator(JSContext *cx, JSObject *parent)
-{
- return JS_InitClass(cx,
- parent,
- NULL,
- &jsclass_navigator,
- NULL,
- 0,
- jsproperties_navigator,
- jsfunctions_navigator,
- NULL,
- NULL);
-}
diff --git a/javascript/jsapi/node.c b/javascript/jsapi/node.c
deleted file mode 100644
index b8c0737..0000000
--- a/javascript/jsapi/node.c
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-node
-
-interface Node : EventTarget {
- const unsigned short ELEMENT_NODE = 1;
- const unsigned short ATTRIBUTE_NODE = 2; // historical
- const unsigned short TEXT_NODE = 3;
- const unsigned short CDATA_SECTION_NODE = 4; // historical
- const unsigned short ENTITY_REFERENCE_NODE = 5; // historical
- const unsigned short ENTITY_NODE = 6; // historical
- const unsigned short PROCESSING_INSTRUCTION_NODE = 7;
- const unsigned short COMMENT_NODE = 8;
- const unsigned short DOCUMENT_NODE = 9;
- const unsigned short DOCUMENT_TYPE_NODE = 10;
- const unsigned short DOCUMENT_FRAGMENT_NODE = 11;
- const unsigned short NOTATION_NODE = 12; // historical
- readonly attribute unsigned short nodeType;
- readonly attribute DOMString nodeName;
-
- readonly attribute DOMString? baseURI;
-
- readonly attribute Document? ownerDocument;
- readonly attribute Node? parentNode;
- readonly attribute Element? parentElement;
- boolean hasChildNodes();
- readonly attribute NodeList childNodes;
- readonly attribute Node? firstChild;
- readonly attribute Node? lastChild;
- readonly attribute Node? previousSibling;
- readonly attribute Node? nextSibling;
-
- const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01;
- const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02;
- const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04;
- const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08;
- const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10;
- const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; // historical
- unsigned short compareDocumentPosition(Node other);
- boolean contains(Node? other);
-
- attribute DOMString? nodeValue;
- attribute DOMString? textContent;
- Node insertBefore(Node node, Node? child);
- Node appendChild(Node node);
- Node replaceChild(Node node, Node child);
- Node removeChild(Node child);
- void normalize();
-
-
- Node cloneNode(optional boolean deep = true);
- boolean isEqualNode(Node? node);
-
- DOMString lookupPrefix(DOMString? namespace);
- DOMString lookupNamespaceURI(DOMString? prefix);
- boolean isDefaultNamespace(DOMString? namespace);
-};
-*/
-
-#include "jsclass.h"
-
-#include "eventtarget.c"
-
-static JSBool JSAPI_NATIVE(hasChildNodes, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(compareDocumentPosition, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(contains, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(insertBefore, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(appendChild, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(replaceChild, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(removeChild, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(normalize, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(cloneNode, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(isEqualNode, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(lookupPrefix, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(lookupNamespaceURI, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(isDefaultNamespace, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-#define JSAPI_FS_NODE \
- JSAPI_FS_EVENTTARGET, \
- JSAPI_FS(hasChildNodes, 0, 0), \
- JSAPI_FS(compareDocumentPosition, 0, 0), \
- JSAPI_FS(contains, 0, 0), \
- JSAPI_FS(insertBefore, 0, 0), \
- JSAPI_FS(appendChild, 0, 0), \
- JSAPI_FS(replaceChild, 0, 0), \
- JSAPI_FS(removeChild, 0, 0), \
- JSAPI_FS(normalize, 0, 0), \
- JSAPI_FS(cloneNode, 0, 0), \
- JSAPI_FS(isEqualNode, 0, 0), \
- JSAPI_FS(lookupPrefix, 0, 0), \
- JSAPI_FS(lookupNamespaceURI, 0, 0), \
- JSAPI_FS(isDefaultNamespace, 0, 0)
-
-
-static JSBool JSAPI_PROPERTYGET(nodeType, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, JSVAL_NULL);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYGET(textContent, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, JSVAL_NULL);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(textContent, JSContext *cx, JSObject *obj, jsval *vp)
-{
- return JS_FALSE;
-}
-
-#define JSAPI_PS_NODE \
- JSAPI_PS_RO(nodeType, 0, JSPROP_ENUMERATE | JSPROP_SHARED), \
- JSAPI_PS(textContent, 0, JSPROP_ENUMERATE | JSPROP_SHARED)
diff --git a/javascript/jsapi/window.c b/javascript/jsapi/window.c
deleted file mode 100644
index 062d925..0000000
--- a/javascript/jsapi/window.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "utils/log.h"
-
-#include "javascript/jsapi.h"
-#include "javascript/jsapi/binding.h"
-
-
-struct jsclass_private {
- struct browser_window *bw;
- struct html_content *htmlc;
- JSObject *document_obj;
- JSObject *navigator_obj;
- JSObject *console_obj;
-};
-
-static void jsclass_finalize(JSContext *cx, JSObject *obj);
-static JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp);
-
-JSClass JSClass_Window = {
- "Window",
- JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- (JSResolveOp)jsclass_resolve,
- JS_ConvertStub,
- jsclass_finalize,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-static JSBool JSAPI_NATIVE(alert, JSContext *cx, uintN argc, jsval *vp)
-{
- JSString* u16_txt;
- char *txt;
- unsigned long length;
-
- if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
- return JS_FALSE;
-
- JSString_to_char(u16_txt, txt, length);
-
- warn_user(txt, NULL);
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(confirm, JSContext *cx, uintN argc, jsval *vp)
-{
- JSString* u16_txt;
- char *txt;
- unsigned long length;
- JSBool result = JS_FALSE;
-
- if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
- return JS_FALSE;
-
- JSString_to_char(u16_txt, txt, length);
-
- warn_user(txt, NULL);
-
- JSAPI_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(result));
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(prompt, JSContext *cx, uintN argc, jsval *vp)
-{
- JSString* u16_txt;
- char *txt;
- unsigned long length;
-
- if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
- return JS_FALSE;
-
- JSString_to_char(u16_txt, txt, length);
-
- warn_user(txt, NULL);
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(close, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(stop, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(focus, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(blur, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSFunctionSpec jsfunctions_window[] =
-{
- JSAPI_FS(close, 0, 0),
- JSAPI_FS(stop, 0, 0),
- JSAPI_FS(focus, 0, 0),
- JSAPI_FS(blur, 0, 0),
- JSAPI_FS(alert, 1, 0),
- JSAPI_FS(confirm, 1, 0),
- JSAPI_FS(prompt, 1, 0),
- JSAPI_FS_END
-};
-
-
-static JSBool JSAPI_PROPERTYGET(window, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYGET(self, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYGET(document, JSContext *cx, JSObject *obj, jsval *vp)
-{
- struct jsclass_private *private;
-
- private = JS_GetInstancePrivate(cx,
- obj,
- &JSClass_Window,
- NULL);
- if (private == NULL)
- return JS_FALSE;
-
- JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(private->document_obj));
- return JS_TRUE;
-}
-
-static JSPropertySpec jsproperties_window[] =
-{
- JSAPI_PS_RO(document, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
- JSAPI_PS_RO(window, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
- JSAPI_PS_RO(self, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
- JSAPI_PS_END
-};
-
-static JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
-{
- *objp = NULL;
- return JS_TRUE;
-}
-
-static void jsclass_finalize(JSContext *cx, JSObject *obj)
-{ struct jsclass_private *private;
-
- private = JS_GetInstancePrivate(cx, obj, &JSClass_Window, NULL);
- if (private != NULL) {
- free(private);
- }
-}
-
-JSObject *jsapi_InitClass_Window(JSContext *cx, JSObject *parent)
-{
- JSObject *window = NULL;
- JSObject *proto;
-
- window = JS_NewCompartmentAndGlobalObject(cx, &JSClass_Window, NULL);
- if (window == NULL) {
- return NULL;
- }
-
- /** @todo reconsider global object handling. future
- * editions of spidermonkey appear to be removing the
- * idea of a global so we probably need to handle
- * global object references internally
- */
-
- /* set the contexts global */
- JS_SetGlobalObject(cx, window);
-
- /* Populate the global object with the standard globals, like
- * Object and Array.
- */
- if (!JS_InitStandardClasses(cx, window)) {
- return NULL;
- }
-
- /* Initialises all the user javascript classes to make their
- * prototypes available.
- */
- /** @todo should we be managing these prototype objects ourselves */
- proto = jsapi_InitClass_Document(cx, window);
- if (proto == NULL) {
- return NULL;
- }
-
- return window;
-}
-
-JSObject *jsapi_new_Window(JSContext *cx,
- JSObject *window,
- JSObject *parent,
- struct browser_window *bw,
- html_content *htmlc)
-{
- struct jsclass_private *private;
-
- /* @todo sort out windows that are not globals */
- assert(parent == NULL);
-
- /* create private data */
- private = malloc(sizeof(struct jsclass_private));
- if (private == NULL) {
- return NULL;
- }
- private->bw = bw;
- private->htmlc = htmlc;
-
-
- /* instantiate the subclasses off the window global */
- private->document_obj = jsapi_new_Document(cx,
- NULL,
- window,
- htmlc->document,
- htmlc);
- if (private->document_obj == NULL) {
- free(private);
- return NULL;
- }
-
- private->navigator_obj = jsapi_new_Navigator(cx, window);
- if (private->navigator_obj == NULL) {
- free(private);
- return NULL;
- }
-
- /** @todo forms, history, location */
-
- private->console_obj = jsapi_new_Console(cx, window);
- if (private->console_obj == NULL) {
- free(private);
- return NULL;
- }
-
- /* private pointer to browsing context */
- if (!JS_SetPrivate(cx, window, private))
- return NULL;
-
- /* functions */
- if (!JS_DefineFunctions(cx, window, jsfunctions_window)) {
- return NULL;
- }
-
- /* properties */
- if (!JS_DefineProperties(cx, window, jsproperties_window))
- return NULL;
-
-
- LOG(("Created new window object %p", window));
-
- return window;
-}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/2b8cdf1f295cc65c5f6...
commit 2b8cdf1f295cc65c5f6935f067289fdb35e3349d
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
add HTMLElement interface binding
diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript
index f5c49f8..51db26f 100644
--- a/Makefile.sources.javascript
+++ b/Makefile.sources.javascript
@@ -11,6 +11,7 @@
S_JSAPI_BINDING:=
JSAPI_BINDING_htmldocument := javascript/jsapi/bindings/htmldocument.bnd
+JSAPI_BINDING_htmlelement := javascript/jsapi/bindings/htmlelement.bnd
JSAPI_BINDING_window := javascript/jsapi/bindings/window.bnd
JSAPI_BINDING_navigator := javascript/jsapi/bindings/navigator.bnd
JSAPI_BINDING_console := javascript/jsapi/bindings/console.bnd
@@ -31,8 +32,8 @@ endef
# Javascript sources
ifeq ($(NETSURF_USE_JS),YES)
-S_JSAPI = htmlelement.c
-#htmldocument.c window.c navigator.c console.c
+S_JSAPI =
+# htmlelement.c htmldocument.c window.c navigator.c console.c
S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI))
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index 80340a5..8b32e91 100644
--- a/javascript/jsapi/binding.h
+++ b/javascript/jsapi/binding.h
@@ -76,6 +76,7 @@ JSObject *jsapi_InitClass_Navigator(JSContext *cx, JSObject *parent);
*/
JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent);
+JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent);
/** Create a new javascript element object
*
* @param cx The javascript context.
@@ -83,6 +84,10 @@ JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent);
* @param doc_priv The private context to set on the object
* @return new javascript object or NULL on error
*/
-JSObject *jsapi_new_element(JSContext *cx, JSObject *parent, struct html_content *htmlc, struct dom_element *domelement);
+JSObject *jsapi_new_HTMLElement(JSContext *cx,
+ JSObject *prototype,
+ JSObject *parent,
+ dom_element *node,
+ struct html_content *htmlc);
#endif
diff --git a/javascript/jsapi/bindings/dom.bnd b/javascript/jsapi/bindings/dom.bnd
index f323ff2..0f54571 100644
--- a/javascript/jsapi/bindings/dom.bnd
+++ b/javascript/jsapi/bindings/dom.bnd
@@ -1,14 +1,30 @@
-/* test binding for document - must be included */
+/* DOM bindings entries */
webidlfile "dom.idl";
operation getElementById %{
dom_string *elementId_dom;
dom_element *element;
+ dom_exception exc;
+
+ LOG(("elementId_len %d elementId %s",elementId_len,elementId));
dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom);
+ LOG(("dom string %p", elementId_dom));
+
+
+ exc = dom_document_get_element_by_id(private->node, elementId_dom, &element);
+ if ((exc == DOM_NO_ERR) && (element != NULL)) {
+ jsret = jsapi_new_HTMLElement(cx, NULL, JS_GetGlobalObject(cx), element, private->htmlc);
+ }
+%}
- dom_document_get_element_by_id(private->node, elementId_dom, &element);
+getter textContent %{
+ dom_exception exc;
+ dom_string *content;
- jsretval = OBJECT_TO_JSVAL(jsapi_new_element(cx, JS_GetGlobalObject(cx), private->htmlc, element));
+ exc = dom_node_get_text_content(private->node, &content);
+ if ((exc == DOM_NO_ERR) && (content != NULL)) {
+ jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content));
+ }
%}
diff --git a/javascript/jsapi/bindings/htmlelement.bnd b/javascript/jsapi/bindings/htmlelement.bnd
new file mode 100644
index 0000000..596bb7d
--- /dev/null
+++ b/javascript/jsapi/bindings/htmlelement.bnd
@@ -0,0 +1,51 @@
+/* Binding to generate HTMLElement interface
+ *
+ * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+#include "dom.bnd"
+
+webidlfile "html.idl";
+
+hdrcomment "Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>";
+hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
+hdrcomment "Released under the terms of the MIT License,";
+hdrcomment " http://www.opensource.org/licenses/mit-license";
+
+preamble %{
+
+#include <dom/dom.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+
+#include "javascript/jsapi.h"
+#include "javascript/jsapi/binding.h"
+
+%}
+
+binding htmlelement {
+ type js_libdom; /* the binding type */
+
+ interface HTMLElement; /* Web IDL interface to generate */
+
+ /* private members:
+ * - stored in private context structure.
+ * - passed as parameters to constructor and stored automatically.
+ * - are *not* considered for property getters/setters.
+ *
+ * internal members:
+ * - value stored in private context structure
+ * - not passed to constructor
+ * - must be instantiated by constructor
+ * - are considered for property getters/setters.
+ */
+ private "dom_element *" node;
+ private "struct html_content *" htmlc;
+}
+
diff --git a/javascript/jsapi/bindings/navigator.bnd b/javascript/jsapi/bindings/navigator.bnd
index 596f1ac..e63e9a9 100644
--- a/javascript/jsapi/bindings/navigator.bnd
+++ b/javascript/jsapi/bindings/navigator.bnd
@@ -76,22 +76,22 @@ binding navigator {
}
getter appName %{
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME));
+ jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME);
%}
getter appCodeName %{
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME));
+ jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME);
%}
getter appVersion %{
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, netsurf_version));
+ jsret = JS_NewStringCopyZ(cx, netsurf_version);
%}
getter language %{
const char *alang = nsoption_charp(accept_language);
if (alang != NULL) {
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, alang));
+ jsret = JS_NewStringCopyZ(cx, alang);
}
%}
@@ -109,12 +109,12 @@ getter platform %{
platstr = malloc(platstrlen);
if (platstr != NULL) {
snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine);
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyN(cx, platstr, platstrlen - 1));
+ jsret = JS_NewStringCopyN(cx, platstr, platstrlen - 1);
free(platstr);
}
}
%}
getter userAgent %{
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, user_agent_string()));
+ jsret = JS_NewStringCopyZ(cx, user_agent_string());
%}
diff --git a/javascript/jsapi/bindings/window.bnd b/javascript/jsapi/bindings/window.bnd
index ba2db52..beb2b12 100644
--- a/javascript/jsapi/bindings/window.bnd
+++ b/javascript/jsapi/bindings/window.bnd
@@ -31,11 +31,11 @@ operation prompt %{
%}
getter window %{
- jsretval = OBJECT_TO_JSVAL(obj);
+ jsret = obj;
%}
getter self %{
- jsretval = OBJECT_TO_JSVAL(obj);
+ jsret = obj;
%}
api init %{
@@ -90,6 +90,11 @@ api init %{
return NULL;
}
+ user_proto = jsapi_InitClass_HTMLElement(cx, prototype);
+ if (user_proto == NULL) {
+ return NULL;
+ }
+
%}
api new %{
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/8f08f820f4d17173c08...
commit 8f08f820f4d17173c08d121a1bd50e1afe66724c
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
improve tests
diff --git a/test/js/doc-dom2.html b/test/js/doc-dom2.html
index 17a916c..a55962b 100644
--- a/test/js/doc-dom2.html
+++ b/test/js/doc-dom2.html
@@ -4,9 +4,13 @@
<link rel="stylesheet" type="text/css" href="tst.css">
</head>
<body>
-<h1 id="heading">Direct DOM element reference</h1>
-<p>Before</p>
-<script>document.write(document.getElementById("heading").textContent);</script>
-<p>Afterwards</p>
+<h1>DOM getElementById element reference</h1>
+<p>This shows the text content of an element obtained using <a href="http://dom.spec.whatwg.org/#dom-document-getelementbyid">document.getElementById</a></p>
+<p>Referenced text</p>
+<p id="reftext">DOM getElementById element referenced test text</p>
+<p>Inserted text</p>
+<p><script>document.write(document.getElementById("reftext").textContent);</script></p>
+<p>After inserted text</p>
+
</body>
</html>
diff --git a/test/js/index.html b/test/js/index.html
index a7d34f5..f618e93 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -10,7 +10,7 @@
</ul>
<h2>Document write tests</h2>
<ul>
-<li><a href="inline-doc-write-simple.html">Simple docuemnt write</a></li>
+<li><a href="inline-doc-write-simple.html">Simple document write</a></li>
<li><a href="noscript-inline-doc-write.html">Script within inline script document write with noscript alternative</a></li>
<li><a href="inline-doc-write.html">Script within inline script</a></li>
<li><a href="sync-script.html">External syncronous script</a></li>
-----------------------------------------------------------------------
Summary of changes:
Makefile.sources.javascript | 5 +-
javascript/jsapi/binding.h | 13 +-
javascript/jsapi/bindings/dom.bnd | 22 ++-
.../bindings/{console.bnd => htmlelement.bnd} | 28 +--
.../jsapi/bindings/{console.bnd => location.bnd} | 28 +--
javascript/jsapi/bindings/navigator.bnd | 12 +-
javascript/jsapi/bindings/window.bnd | 89 ++++---
javascript/jsapi/console.c | 152 ----------
javascript/jsapi/document.c | 110 -------
javascript/jsapi/domexception.c | 106 -------
javascript/jsapi/element.c | 99 -------
javascript/jsapi/eventtarget.c | 76 -----
javascript/jsapi/htmldocument.c | 262 -----------------
javascript/jsapi/htmlelement.c | 230 ---------------
javascript/jsapi/jsclass.h | 39 ---
javascript/jsapi/navigator.c | 206 --------------
javascript/jsapi/node.c | 299 --------------------
javascript/jsapi/window.c | 297 -------------------
test/js/doc-dom2.html | 12 +-
test/js/index.html | 2 +-
20 files changed, 123 insertions(+), 1964 deletions(-)
copy javascript/jsapi/bindings/{console.bnd => htmlelement.bnd} (72%)
copy javascript/jsapi/bindings/{console.bnd => location.bnd} (72%)
delete mode 100644 javascript/jsapi/console.c
delete mode 100644 javascript/jsapi/document.c
delete mode 100644 javascript/jsapi/domexception.c
delete mode 100644 javascript/jsapi/element.c
delete mode 100644 javascript/jsapi/eventtarget.c
delete mode 100644 javascript/jsapi/htmldocument.c
delete mode 100644 javascript/jsapi/htmlelement.c
delete mode 100644 javascript/jsapi/jsclass.h
delete mode 100644 javascript/jsapi/navigator.c
delete mode 100644 javascript/jsapi/node.c
delete mode 100644 javascript/jsapi/window.c
diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript
index f5c49f8..58b8860 100644
--- a/Makefile.sources.javascript
+++ b/Makefile.sources.javascript
@@ -11,9 +11,11 @@
S_JSAPI_BINDING:=
JSAPI_BINDING_htmldocument := javascript/jsapi/bindings/htmldocument.bnd
+JSAPI_BINDING_htmlelement := javascript/jsapi/bindings/htmlelement.bnd
JSAPI_BINDING_window := javascript/jsapi/bindings/window.bnd
JSAPI_BINDING_navigator := javascript/jsapi/bindings/navigator.bnd
JSAPI_BINDING_console := javascript/jsapi/bindings/console.bnd
+JSAPI_BINDING_location := javascript/jsapi/bindings/location.bnd
# 1: input file
# 2: output file
@@ -31,8 +33,7 @@ endef
# Javascript sources
ifeq ($(NETSURF_USE_JS),YES)
-S_JSAPI = htmlelement.c
-#htmldocument.c window.c navigator.c console.c
+S_JSAPI =
S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI))
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index 80340a5..68ab6d1 100644
--- a/javascript/jsapi/binding.h
+++ b/javascript/jsapi/binding.h
@@ -41,6 +41,12 @@ JSObject *jsapi_new_Window(JSContext *cx,
struct browser_window *bw,
html_content *htmlc);
+JSObject *jsapi_InitClass_Location(JSContext *cx, JSObject *parent);
+JSObject *jsapi_new_Location(JSContext *cx,
+ JSObject *window,
+ JSObject *parent,
+ struct browser_window *bw);
+
JSObject *jsapi_InitClass_Document(JSContext *cx, JSObject *parent);
@@ -76,6 +82,7 @@ JSObject *jsapi_InitClass_Navigator(JSContext *cx, JSObject *parent);
*/
JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent);
+JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent);
/** Create a new javascript element object
*
* @param cx The javascript context.
@@ -83,6 +90,10 @@ JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent);
* @param doc_priv The private context to set on the object
* @return new javascript object or NULL on error
*/
-JSObject *jsapi_new_element(JSContext *cx, JSObject *parent, struct html_content *htmlc, struct dom_element *domelement);
+JSObject *jsapi_new_HTMLElement(JSContext *cx,
+ JSObject *prototype,
+ JSObject *parent,
+ dom_element *node,
+ struct html_content *htmlc);
#endif
diff --git a/javascript/jsapi/bindings/dom.bnd b/javascript/jsapi/bindings/dom.bnd
index f323ff2..0f54571 100644
--- a/javascript/jsapi/bindings/dom.bnd
+++ b/javascript/jsapi/bindings/dom.bnd
@@ -1,14 +1,30 @@
-/* test binding for document - must be included */
+/* DOM bindings entries */
webidlfile "dom.idl";
operation getElementById %{
dom_string *elementId_dom;
dom_element *element;
+ dom_exception exc;
+
+ LOG(("elementId_len %d elementId %s",elementId_len,elementId));
dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom);
+ LOG(("dom string %p", elementId_dom));
+
+
+ exc = dom_document_get_element_by_id(private->node, elementId_dom, &element);
+ if ((exc == DOM_NO_ERR) && (element != NULL)) {
+ jsret = jsapi_new_HTMLElement(cx, NULL, JS_GetGlobalObject(cx), element, private->htmlc);
+ }
+%}
- dom_document_get_element_by_id(private->node, elementId_dom, &element);
+getter textContent %{
+ dom_exception exc;
+ dom_string *content;
- jsretval = OBJECT_TO_JSVAL(jsapi_new_element(cx, JS_GetGlobalObject(cx), private->htmlc, element));
+ exc = dom_node_get_text_content(private->node, &content);
+ if ((exc == DOM_NO_ERR) && (content != NULL)) {
+ jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content));
+ }
%}
diff --git a/javascript/jsapi/bindings/console.bnd b/javascript/jsapi/bindings/htmlelement.bnd
similarity index 72%
copy from javascript/jsapi/bindings/console.bnd
copy to javascript/jsapi/bindings/htmlelement.bnd
index 6aef9dc..596bb7d 100644
--- a/javascript/jsapi/bindings/console.bnd
+++ b/javascript/jsapi/bindings/htmlelement.bnd
@@ -1,4 +1,4 @@
-/* Binding to generate Console interface
+/* Binding to generate HTMLElement interface
*
* Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
*
@@ -8,7 +8,9 @@
* http://www.opensource.org/licenses/mit-license
*/
-webidlfile "console.idl";
+#include "dom.bnd"
+
+webidlfile "html.idl";
hdrcomment "Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>";
hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
@@ -17,6 +19,8 @@ hdrcomment " http://www.opensource.org/licenses/mit-license";
preamble %{
+#include <dom/dom.h>
+
#include "utils/config.h"
#include "utils/log.h"
@@ -25,10 +29,10 @@ preamble %{
%}
-binding navigator {
+binding htmlelement {
type js_libdom; /* the binding type */
- interface Console; /* Web IDL interface to generate */
+ interface HTMLElement; /* Web IDL interface to generate */
/* private members:
* - stored in private context structure.
@@ -41,19 +45,7 @@ binding navigator {
* - must be instantiated by constructor
* - are considered for property getters/setters.
*/
- internal "void *" gui_console;
+ private "dom_element *" node;
+ private "struct html_content *" htmlc;
}
-operation log %{
- unsigned int argloop;
- JSString *jsstr;
- unsigned long jsstrlen;
- char *txt;
-
- for (argloop = 0; argloop < argc; argloop++) {
- jsstr = JS_ValueToString(cx, argv[argloop]);
-
- JSString_to_char(jsstr, txt, jsstrlen);
- LOG(("%s", txt));
- }
-%}
diff --git a/javascript/jsapi/bindings/console.bnd b/javascript/jsapi/bindings/location.bnd
similarity index 72%
copy from javascript/jsapi/bindings/console.bnd
copy to javascript/jsapi/bindings/location.bnd
index 6aef9dc..c83fe46 100644
--- a/javascript/jsapi/bindings/console.bnd
+++ b/javascript/jsapi/bindings/location.bnd
@@ -1,4 +1,4 @@
-/* Binding to generate Console interface
+/* Binding to generate Location interface
*
* Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
*
@@ -8,7 +8,9 @@
* http://www.opensource.org/licenses/mit-license
*/
-webidlfile "console.idl";
+#include "dom.bnd"
+
+webidlfile "html.idl";
hdrcomment "Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>";
hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
@@ -17,6 +19,8 @@ hdrcomment " http://www.opensource.org/licenses/mit-license";
preamble %{
+#include "desktop/browser.h"
+
#include "utils/config.h"
#include "utils/log.h"
@@ -25,10 +29,10 @@ preamble %{
%}
-binding navigator {
+binding location {
type js_libdom; /* the binding type */
- interface Console; /* Web IDL interface to generate */
+ interface Location; /* Web IDL interface to generate */
/* private members:
* - stored in private context structure.
@@ -41,19 +45,9 @@ binding navigator {
* - must be instantiated by constructor
* - are considered for property getters/setters.
*/
- internal "void *" gui_console;
+ private "struct browser_window *" bw;
}
-operation log %{
- unsigned int argloop;
- JSString *jsstr;
- unsigned long jsstrlen;
- char *txt;
-
- for (argloop = 0; argloop < argc; argloop++) {
- jsstr = JS_ValueToString(cx, argv[argloop]);
-
- JSString_to_char(jsstr, txt, jsstrlen);
- LOG(("%s", txt));
- }
+operation reload %{
+ browser_window_reload(private->bw, false);
%}
diff --git a/javascript/jsapi/bindings/navigator.bnd b/javascript/jsapi/bindings/navigator.bnd
index 596f1ac..e63e9a9 100644
--- a/javascript/jsapi/bindings/navigator.bnd
+++ b/javascript/jsapi/bindings/navigator.bnd
@@ -76,22 +76,22 @@ binding navigator {
}
getter appName %{
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME));
+ jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME);
%}
getter appCodeName %{
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME));
+ jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME);
%}
getter appVersion %{
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, netsurf_version));
+ jsret = JS_NewStringCopyZ(cx, netsurf_version);
%}
getter language %{
const char *alang = nsoption_charp(accept_language);
if (alang != NULL) {
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, alang));
+ jsret = JS_NewStringCopyZ(cx, alang);
}
%}
@@ -109,12 +109,12 @@ getter platform %{
platstr = malloc(platstrlen);
if (platstr != NULL) {
snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine);
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyN(cx, platstr, platstrlen - 1));
+ jsret = JS_NewStringCopyN(cx, platstr, platstrlen - 1);
free(platstr);
}
}
%}
getter userAgent %{
- jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, user_agent_string()));
+ jsret = JS_NewStringCopyZ(cx, user_agent_string());
%}
diff --git a/javascript/jsapi/bindings/window.bnd b/javascript/jsapi/bindings/window.bnd
index ba2db52..956932c 100644
--- a/javascript/jsapi/bindings/window.bnd
+++ b/javascript/jsapi/bindings/window.bnd
@@ -18,25 +18,26 @@ preamble %{
%}
-operation confirm %{
- warn_user(message, NULL);
-%}
-
-operation alert %{
- warn_user(message, NULL);
-%}
-
-operation prompt %{
- warn_user(message, NULL);
-%}
-
-getter window %{
- jsretval = OBJECT_TO_JSVAL(obj);
-%}
+binding window {
+ type js_libdom; /* the binding type */
+
+ interface Window; /* Web IDL interface to generate */
+
+ /* private are parameters to constructor stored in private
+ * context structure.
+ *
+ * internal are value stored in private context structure but not
+ * passed to constructor but are considered for property
+ * getters/setters.
+ */
+ private "struct browser_window *" bw;
+ private "struct html_content *" htmlc;
+ internal "JSObject *" document;
+ internal "JSObject *" navigator;
+ internal "JSObject *" console;
+ internal "JSObject *" location;
+}
-getter self %{
- jsretval = OBJECT_TO_JSVAL(obj);
-%}
api init %{
JSObject *user_proto;
@@ -85,11 +86,21 @@ api init %{
return NULL;
}
+ user_proto = jsapi_InitClass_Location(cx, prototype);
+ if (user_proto == NULL) {
+ return NULL;
+ }
+
user_proto = jsapi_InitClass_Console(cx, prototype);
if (user_proto == NULL) {
return NULL;
}
+ user_proto = jsapi_InitClass_HTMLElement(cx, prototype);
+ if (user_proto == NULL) {
+ return NULL;
+ }
+
%}
api new %{
@@ -116,7 +127,11 @@ api new %{
return NULL;
}
- /** @todo forms, history, location */
+ private->location = jsapi_new_Location(cx, NULL, newobject, bw);
+ if (private->location == NULL) {
+ free(private);
+ return NULL;
+ }
private->console = jsapi_new_Console(cx, NULL, newobject);
if (private->console == NULL) {
@@ -124,25 +139,27 @@ api new %{
return NULL;
}
+ /** @todo forms, history */
+
LOG(("Created new window object %p", newobject));
%}
+operation confirm %{
+ warn_user(message, NULL);
+%}
-binding window {
- type js_libdom; /* the binding type */
-
- interface Window; /* Web IDL interface to generate */
-
- /* private are parameters to constructor stored in private
- * context structure.
- *
- * internal are value stored in private context structure but not
- * passed to constructor but are considered for property getters/setters.
- */
- private "struct browser_window *" bw;
- private "struct html_content *" htmlc;
- internal "JSObject *" document;
- internal "JSObject *" navigator;
- internal "JSObject *" console;
+operation alert %{
+ warn_user(message, NULL);
+%}
-}
+operation prompt %{
+ warn_user(message, NULL);
+%}
+
+getter window %{
+ jsret = obj;
+%}
+
+getter self %{
+ jsret = obj;
+%}
diff --git a/javascript/jsapi/console.c b/javascript/jsapi/console.c
deleted file mode 100644
index 3cd5188..0000000
--- a/javascript/jsapi/console.c
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "utils/log.h"
-
-#include "javascript/jsapi.h"
-
-static JSBool JSAPI_NATIVE(debug, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(dir, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(error, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(group, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(groupCollapsed, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(groupEnd, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(info, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(log, JSContext *cx, uintN argc, jsval *vp)
-{
- unsigned int argloop;
- JSString *jsstr;
- unsigned long jsstrlen;
- char *txt;
-
- for (argloop = 0; argloop < argc; argloop++) {
- jsstr = JS_ValueToString(cx, *JSAPI_ARGV(cx, vp + argloop));
-
- JSString_to_char(jsstr, txt, jsstrlen);
- LOG(("%s", txt));
- }
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(time, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(timeEnd, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(trace, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(warn, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
- return JS_TRUE;
-}
-
-static JSFunctionSpec jsfunctions_console[] = {
- JSAPI_FS(debug, 1, 0),
- JSAPI_FS(dir, 1, 0),
- JSAPI_FS(error, 1, 0),
- JSAPI_FS(group, 1, 0),
- JSAPI_FS(groupCollapsed, 1, 0),
- JSAPI_FS(groupEnd, 1, 0),
- JSAPI_FS(info, 1, 0),
- JSAPI_FS(log, 1, 0),
- JSAPI_FS(time, 1, 0),
- JSAPI_FS(timeEnd, 1, 0),
- JSAPI_FS(trace, 1, 0),
- JSAPI_FS(warn, 1, 0),
- JSAPI_FS_END
-};
-
-static JSClass jsclass_console =
-{
- "console",
- JSCLASS_HAS_PRIVATE,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- JS_FinalizeStub,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-JSObject *jsapi_new_Console(JSContext *cx, JSObject *parent)
-{
- return JS_InitClass(cx,
- parent,
- NULL,
- &jsclass_console,
- NULL,
- 0,
- NULL,
- jsfunctions_console,
- NULL,
- NULL);
-}
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
deleted file mode 100644
index 2d3bde4..0000000
--- a/javascript/jsapi/document.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-document
-
-interface Document : Node {
- readonly attribute DOMImplementation implementation;
- readonly attribute DOMString URL;
- readonly attribute DOMString documentURI;
- readonly attribute DOMString compatMode;
- readonly attribute DOMString characterSet;
- readonly attribute DOMString contentType;
-
- readonly attribute DocumentType? doctype;
- readonly attribute Element? documentElement;
- HTMLCollection getElementsByTagName(DOMString localName);
- HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
- HTMLCollection getElementsByClassName(DOMString classNames);
- Element? getElementById(DOMString elementId);
-
- Element createElement(DOMString localName);
- Element createElementNS(DOMString? namespace, DOMString qualifiedName);
- DocumentFragment createDocumentFragment();
- Text createTextNode(DOMString data);
- Comment createComment(DOMString data);
- ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data);
-
- Node importNode(Node node, optional boolean deep = true);
- Node adoptNode(Node node);
-
- Event createEvent(DOMString interface);
-
- Range createRange();
-
- // NodeFilter.SHOW_ALL = 0xFFFFFFFF
- NodeIterator createNodeIterator(Node root, optional unsigned long whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null);
- TreeWalker createTreeWalker(Node root, optional unsigned long whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null);
-
- // NEW
- void prepend((Node or DOMString)... nodes);
- void append((Node or DOMString)... nodes);
-};
-
-
- */
-
-#include "jsclass.h"
-
-#include "node.c"
-
-static JSBool JSAPI_NATIVE(getElementById, JSContext *cx, uintN argc, jsval *vp)
-{
- JSString* u16_txt;
- char *txt;
- unsigned long txtlen;
- dom_string *idstr;
- dom_element *idelement;
- struct jsclass_document_priv *document;
-
- document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (document == NULL) {
- return JS_FALSE;
- }
-
- if (document->node == NULL) {
- /* no document available, this is obviously a problem
- * for finding elements
- */
- JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
-
- return JS_TRUE;
- }
-
- if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
- return JS_FALSE;
-
- JSString_to_char(u16_txt, txt, txtlen);
-
- dom_string_create((unsigned char*)txt, txtlen, &idstr);
-
- dom_document_get_element_by_id(document->node, idstr, &idelement);
-
- JSAPI_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsapi_new_element(cx, JS_GetGlobalObject(cx), document->htmlc, idelement)));
-
- return JS_TRUE;
-}
-
-#define JSAPI_FS_DOCUMENT \
- JSAPI_FS_NODE, \
- JSAPI_FS(getElementById, 1, 0) \
-
-
-#define JSAPI_PS_DOCUMENT \
- JSAPI_PS_NODE
diff --git a/javascript/jsapi/domexception.c b/javascript/jsapi/domexception.c
deleted file mode 100644
index b7c61cf..0000000
--- a/javascript/jsapi/domexception.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <dom/dom.h>
-
-
-#include "javascript/jsapi.h"
-#include "utils/config.h"
-#include "render/html_internal.h"
-#include "utils/log.h"
-
-/* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#exception-domexc...
-exception DOMException {
- const unsigned short INDEX_SIZE_ERR = 1;
- const unsigned short DOMSTRING_SIZE_ERR = 2; // historical
- const unsigned short HIERARCHY_REQUEST_ERR = 3;
- const unsigned short WRONG_DOCUMENT_ERR = 4;
- const unsigned short INVALID_CHARACTER_ERR = 5;
- const unsigned short NO_DATA_ALLOWED_ERR = 6; // historical
- const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7;
- const unsigned short NOT_FOUND_ERR = 8;
- const unsigned short NOT_SUPPORTED_ERR = 9;
- const unsigned short INUSE_ATTRIBUTE_ERR = 10; // historical
- const unsigned short INVALID_STATE_ERR = 11;
- const unsigned short SYNTAX_ERR = 12;
- const unsigned short INVALID_MODIFICATION_ERR = 13;
- const unsigned short NAMESPACE_ERR = 14;
- const unsigned short INVALID_ACCESS_ERR = 15;
- const unsigned short VALIDATION_ERR = 16; // historical
- const unsigned short TYPE_MISMATCH_ERR = 17;
- const unsigned short SECURITY_ERR = 18;
- const unsigned short NETWORK_ERR = 19;
- const unsigned short ABORT_ERR = 20;
- const unsigned short URL_MISMATCH_ERR = 21;
- const unsigned short QUOTA_EXCEEDED_ERR = 22;
- const unsigned short TIMEOUT_ERR = 23;
- const unsigned short INVALID_NODE_TYPE_ERR = 24;
- const unsigned short DATA_CLONE_ERR = 25;
- unsigned short code;
-};
-
-*/
-
-static JSClass jsclass_domexception =
-{
- "DOMException",
- JSCLASS_HAS_PRIVATE,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- JS_FinalizeStub,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-
-JSObject *
-jsapi_new_domexception(JSContext *cx,
- JSObject *parent,
- int code)
-{
- /* create element object and return it*/
- JSObject *jsdomexception;
-
- jssomexception = JS_InitClass(cx,
- parent,
- NULL,
- &jsclass_domexception,
- NULL,
- 0,
- NULL,
- NULL,
- NULL,
- NULL);
- if (jsdomexecption == NULL) {
- return NULL;
- }
-
- LOG(("setting element private to %d", code));
- /* private pointer to browsing context */
- if (JS_SetPrivate(cx, jsdomexception, code) != JS_TRUE) {
- LOG(("failed to set content"));
- return NULL;
- }
-
- return jsdomexception;
-}
diff --git a/javascript/jsapi/element.c b/javascript/jsapi/element.c
deleted file mode 100644
index d301321..0000000
--- a/javascript/jsapi/element.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-element
-
-
-interface Element : Node {
- readonly attribute DOMString? namespaceURI;
- readonly attribute DOMString? prefix;
- readonly attribute DOMString localName;
- readonly attribute DOMString tagName;
-
- attribute DOMString id;
- attribute DOMString className;
- readonly attribute DOMTokenList classList;
-
- readonly attribute Attr[] attributes;
- DOMString? getAttribute(DOMString name);
- DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
- void setAttribute(DOMString name, DOMString value);
- void setAttributeNS(DOMString? namespace, DOMString name, DOMString value);
- void removeAttribute(DOMString name);
- void removeAttributeNS(DOMString? namespace, DOMString localName);
- boolean hasAttribute(DOMString name);
- boolean hasAttributeNS(DOMString? namespace, DOMString localName);
-
- HTMLCollection getElementsByTagName(DOMString localName);
- HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
- HTMLCollection getElementsByClassName(DOMString classNames);
-
- readonly attribute HTMLCollection children;
- readonly attribute Element? firstElementChild;
- readonly attribute Element? lastElementChild;
- readonly attribute Element? previousElementSibling;
- readonly attribute Element? nextElementSibling;
- readonly attribute unsigned long childElementCount;
-
- // NEW
- void prepend((Node or DOMString)... nodes);
- void append((Node or DOMString)... nodes);
- void before((Node or DOMString)... nodes);
- void after((Node or DOMString)... nodes);
- void replace((Node or DOMString)... nodes);
- void remove();
-};
-*/
-
-#include "jsclass.h"
-
-#include "node.c"
-
-static JSBool JSAPI_NATIVE(getAttribute, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
-
- return JS_TRUE;
-}
-
-#define JSAPI_FS_ELEMENT \
- JSAPI_FS_NODE, \
- JSAPI_FS(getAttribute, 0, 0)
-
-static JSBool JSAPI_PROPERTYGET(id, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, JSVAL_NULL);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(id, JSContext *cx, JSObject *obj, jsval *vp)
-{
- return JS_FALSE;
-}
-
-#define JSAPI_PS_ELEMENT \
- JSAPI_PS_NODE, \
- JSAPI_PS(id, 0, JSPROP_ENUMERATE | JSPROP_SHARED)
diff --git a/javascript/jsapi/eventtarget.c b/javascript/jsapi/eventtarget.c
deleted file mode 100644
index e2ab6a9..0000000
--- a/javascript/jsapi/eventtarget.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#eventtarget
-
-interface EventTarget {
- void addEventListener(DOMString type, EventListener? callback, optional boolean capture = false);
- void removeEventListener(DOMString type, EventListener? callback, optional boolean capture = false);
- boolean dispatchEvent(Event event);
-};
-*/
-
-#include "jsclass.h"
-
-static JSBool JSAPI_NATIVE(addEventListener, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(removeEventListener, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(dispatchEvent, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-#define JSAPI_FS_EVENTTARGET \
- JSAPI_FS(addEventListener, 0, 0), \
- JSAPI_FS(removeEventListener, 0, 0), \
- JSAPI_FS(dispatchEvent, 0, 0)
diff --git a/javascript/jsapi/htmldocument.c b/javascript/jsapi/htmldocument.c
deleted file mode 100644
index 8b38acd..0000000
--- a/javascript/jsapi/htmldocument.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <dom/dom.h>
-
-#include "utils/config.h"
-#include "utils/log.h"
-
-#include "javascript/jsapi.h"
-
-/* IDL http://www.whatwg.org/specs/web-apps/current-work/#the-document-object
-
-[OverrideBuiltins]
-partial interface Document {
- // resource metadata management
- [PutForwards=href] readonly attribute Location? location;
- attribute DOMString domain;
- readonly attribute DOMString referrer;
- attribute DOMString cookie;
- readonly attribute DOMString lastModified;
- readonly attribute DOMString readyState;
-
- // DOM tree accessors
- getter object (DOMString name);
- attribute DOMString title;
- attribute DOMString dir;
- attribute HTMLElement? body;
- readonly attribute HTMLHeadElement? head;
- readonly attribute HTMLCollection images;
- readonly attribute HTMLCollection embeds;
- readonly attribute HTMLCollection plugins;
- readonly attribute HTMLCollection links;
- readonly attribute HTMLCollection forms;
- readonly attribute HTMLCollection scripts;
- NodeList getElementsByName(DOMString elementName);
- NodeList getItems(optional DOMString typeNames); // microdata
- readonly attribute DOMElementMap cssElementMap;
-
- // dynamic markup insertion
- Document open(optional DOMString type, optional DOMString replace);
- WindowProxy open(DOMString url, DOMString name, DOMString features, optional boolean replace);
- void close();
- void write(DOMString... text);
- void writeln(DOMString... text);
-
- // user interaction
- readonly attribute WindowProxy? defaultView;
- readonly attribute Element? activeElement;
- boolean hasFocus();
- attribute DOMString designMode;
- boolean execCommand(DOMString commandId);
- boolean execCommand(DOMString commandId, boolean showUI);
- boolean execCommand(DOMString commandId, boolean showUI, DOMString value);
- boolean queryCommandEnabled(DOMString commandId);
- boolean queryCommandIndeterm(DOMString commandId);
- boolean queryCommandState(DOMString commandId);
- boolean queryCommandSupported(DOMString commandId);
- DOMString queryCommandValue(DOMString commandId);
- readonly attribute HTMLCollection commands;
-
- // event handler IDL attributes
- attribute EventHandler onabort;
- attribute EventHandler onblur;
- attribute EventHandler oncancel;
- attribute EventHandler oncanplay;
- attribute EventHandler oncanplaythrough;
- attribute EventHandler onchange;
- attribute EventHandler onclick;
- attribute EventHandler onclose;
- attribute EventHandler oncontextmenu;
- attribute EventHandler oncuechange;
- attribute EventHandler ondblclick;
- attribute EventHandler ondrag;
- attribute EventHandler ondragend;
- attribute EventHandler ondragenter;
- attribute EventHandler ondragleave;
- attribute EventHandler ondragover;
- attribute EventHandler ondragstart;
- attribute EventHandler ondrop;
- attribute EventHandler ondurationchange;
- attribute EventHandler onemptied;
- attribute EventHandler onended;
- attribute OnErrorEventHandler onerror;
- attribute EventHandler onfocus;
- attribute EventHandler oninput;
- attribute EventHandler oninvalid;
- attribute EventHandler onkeydown;
- attribute EventHandler onkeypress;
- attribute EventHandler onkeyup;
- attribute EventHandler onload;
- attribute EventHandler onloadeddata;
- attribute EventHandler onloadedmetadata;
- attribute EventHandler onloadstart;
- attribute EventHandler onmousedown;
- attribute EventHandler onmousemove;
- attribute EventHandler onmouseout;
- attribute EventHandler onmouseover;
- attribute EventHandler onmouseup;
- attribute EventHandler onmousewheel;
- attribute EventHandler onpause;
- attribute EventHandler onplay;
- attribute EventHandler onplaying;
- attribute EventHandler onprogress;
- attribute EventHandler onratechange;
- attribute EventHandler onreset;
- attribute EventHandler onscroll;
- attribute EventHandler onseeked;
- attribute EventHandler onseeking;
- attribute EventHandler onselect;
- attribute EventHandler onshow;
- attribute EventHandler onstalled;
- attribute EventHandler onsubmit;
- attribute EventHandler onsuspend;
- attribute EventHandler ontimeupdate;
- attribute EventHandler onvolumechange;
- attribute EventHandler onwaiting;
-
- // special event handler IDL attributes that only apply to Document objects
- [LenientThis] attribute EventHandler onreadystatechange;
-};
-
- */
-
-static void jsfinalize_document(JSContext *cx, JSObject *obj);
-static JSBool jsresove_node(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp);
-
-struct jsclass_document_priv {
- struct html_content *htmlc;
- dom_document *node;
-};
-
-
-#define JSCLASS_NAME document
-
-#include "jsclass.h"
-
-static JSClass JSCLASS_OBJECT =
-{
- "document",
- JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- (JSResolveOp)jsresove_node,
- JS_ConvertStub,
- jsfinalize_document,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-#include "document.c"
-
-static JSBool jsresove_node(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
-{
- *objp = NULL;
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(write, JSContext *cx, uintN argc, jsval *vp)
-{
- JSString* u16_txt;
- char *txt;
- unsigned long length;
- struct jsclass_document_priv *document;
-
- document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (document == NULL) {
- return JS_FALSE;
- }
-
- if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt)) {
- return JS_FALSE;
- }
-
- JSString_to_char(u16_txt, txt, length);
-
- LOG(("content %p parser %p writing %s",
- document->htmlc, document->htmlc->parser, txt));
- if (document->htmlc->parser != NULL) {
- dom_hubbub_parser_insert_chunk(document->htmlc->parser, (uint8_t *)txt, length);
- }
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSFunctionSpec jsfunctions_document[] = {
- JSAPI_FS_DOCUMENT,
- JSAPI_FS(write, 1, 0),
- JSAPI_FS_END
-};
-
-static JSPropertySpec jsproperties_document[] =
-{
- JSAPI_PS_DOCUMENT,
- JSAPI_PS_END
-};
-
-static void jsfinalize_document(JSContext *cx, JSObject *obj)
-{
- struct jsclass_document_priv *document;
-
- document = JS_GetInstancePrivate(cx, obj, &JSCLASS_OBJECT, NULL);
- if (document != NULL) {
- free(document);
- }
-}
-
-JSObject *jsapi_new_document(JSContext *cx, JSObject *parent, struct html_content *htmlc)
-{
- /* create document object and return it */
- JSObject *jsdocument;
- struct jsclass_document_priv *document;
-
- document = malloc(sizeof(*document));
- if (document == NULL) {
- return NULL;
- }
- document->htmlc = htmlc;
- document->node = htmlc->document;
-
- jsdocument = JS_InitClass(cx,
- parent,
- NULL,
- &JSCLASS_OBJECT,
- NULL,
- 0,
- jsproperties_document,
- jsfunctions_document,
- NULL,
- NULL);
- if (jsdocument == NULL) {
- free(document);
- return NULL;
- }
-
- LOG(("setting document private to %p", document));
- /* private pointer to browsing context */
- if (JS_SetPrivate(cx, jsdocument, document) != JS_TRUE) {
- LOG(("failed to set document private"));
- free(document);
- return NULL;
- }
-
- return jsdocument;
-}
diff --git a/javascript/jsapi/htmlelement.c b/javascript/jsapi/htmlelement.c
deleted file mode 100644
index a7846ba..0000000
--- a/javascript/jsapi/htmlelement.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <dom/dom.h>
-
-#include "utils/config.h"
-#include "utils/log.h"
-#include "render/html_internal.h"
-
-#include "javascript/jsapi.h"
-
-/* IDL http://www.whatwg.org/specs/web-apps/current-work/#elements-in-the-dom
-
-CAUTION - innerHTML and outerHTML etc. are part of the DOM parsing
- specification but more can be found in:
-http://html5.org/specs/dom-parsing.html#extensions-to-the-element-interface
-
-interface HTMLElement : Element {
- // metadata attributes
- attribute DOMString title;
- attribute DOMString lang;
- attribute boolean translate;
- attribute DOMString dir;
- readonly attribute DOMStringMap dataset;
-
- // microdata
- attribute boolean itemScope;
- [PutForwards=value] readonly attribute DOMSettableTokenList itemType;
- attribute DOMString itemId;
- [PutForwards=value] readonly attribute DOMSettableTokenList itemRef;
- [PutForwards=value] readonly attribute DOMSettableTokenList itemProp;
- readonly attribute HTMLPropertiesCollection properties;
- attribute any itemValue;
-
- // user interaction
- attribute boolean hidden;
- void click();
- attribute long tabIndex;
- void focus();
- void blur();
- attribute DOMString accessKey;
- readonly attribute DOMString accessKeyLabel;
- attribute boolean draggable;
- [PutForwards=value] readonly attribute DOMSettableTokenList dropzone;
- attribute DOMString contentEditable;
- readonly attribute boolean isContentEditable;
- attribute HTMLMenuElement? contextMenu;
- attribute boolean spellcheck;
-
- // command API
- readonly attribute DOMString? commandType;
- readonly attribute DOMString? commandLabel;
- readonly attribute DOMString? commandIcon;
- readonly attribute boolean? commandHidden;
- readonly attribute boolean? commandDisabled;
- readonly attribute boolean? commandChecked;
-
- // styling
- readonly attribute CSSStyleDeclaration style;
-
- // event handler IDL attributes
- attribute EventHandler onabort;
- attribute EventHandler onblur;
- attribute EventHandler oncancel;
- attribute EventHandler oncanplay;
- attribute EventHandler oncanplaythrough;
- attribute EventHandler onchange;
- attribute EventHandler onclick;
- attribute EventHandler onclose;
- attribute EventHandler oncontextmenu;
- attribute EventHandler oncuechange;
- attribute EventHandler ondblclick;
- attribute EventHandler ondrag;
- attribute EventHandler ondragend;
- attribute EventHandler ondragenter;
- attribute EventHandler ondragleave;
- attribute EventHandler ondragover;
- attribute EventHandler ondragstart;
- attribute EventHandler ondrop;
- attribute EventHandler ondurationchange;
- attribute EventHandler onemptied;
- attribute EventHandler onended;
- attribute OnErrorEventHandler onerror;
- attribute EventHandler onfocus;
- attribute EventHandler oninput;
- attribute EventHandler oninvalid;
- attribute EventHandler onkeydown;
- attribute EventHandler onkeypress;
- attribute EventHandler onkeyup;
- attribute EventHandler onload;
- attribute EventHandler onloadeddata;
- attribute EventHandler onloadedmetadata;
- attribute EventHandler onloadstart;
- attribute EventHandler onmousedown;
- attribute EventHandler onmousemove;
- attribute EventHandler onmouseout;
- attribute EventHandler onmouseover;
- attribute EventHandler onmouseup;
- attribute EventHandler onmousewheel;
- attribute EventHandler onpause;
- attribute EventHandler onplay;
- attribute EventHandler onplaying;
- attribute EventHandler onprogress;
- attribute EventHandler onratechange;
- attribute EventHandler onreset;
- attribute EventHandler onscroll;
- attribute EventHandler onseeked;
- attribute EventHandler onseeking;
- attribute EventHandler onselect;
- attribute EventHandler onshow;
- attribute EventHandler onstalled;
- attribute EventHandler onsubmit;
- attribute EventHandler onsuspend;
- attribute EventHandler ontimeupdate;
- attribute EventHandler onvolumechange;
- attribute EventHandler onwaiting;
-};
-
-*/
-
-static void jsfinalize_element(JSContext *cx, JSObject *obj);
-
-struct jsclass_document_priv {
- struct html_content *htmlc;
- dom_element *node;
-};
-
-#define JSCLASS_NAME htmlelement
-
-#include "jsclass.h"
-
-static JSClass JSCLASS_OBJECT =
-{
- "HTMLElement",
- JSCLASS_HAS_PRIVATE,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- jsfinalize_element,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-#include "element.c"
-
-static void jsfinalize_element(JSContext *cx, JSObject *obj)
-{
- struct jsclass_document_priv *element;
- element = JS_GetInstancePrivate(cx, obj, &JSCLASS_OBJECT, NULL);
- if (element != NULL) {
- free(element);
- }
-}
-
-
-
-static JSFunctionSpec jsfunctions_element[] = {
- JSAPI_FS_ELEMENT,
- JSAPI_FS_END
-};
-
-
-
-
-static JSPropertySpec jsproperties_element[] =
-{
- JSAPI_PS_ELEMENT,
- JSAPI_PS_END
-};
-
-JSObject *
-jsapi_new_element(JSContext *cx,
- JSObject *parent,
- struct html_content *htmlc,
- dom_element *domelement)
-{
- /* create element object and return it */
- JSObject *jselement;
- struct jsclass_document_priv *element;
-
- element = malloc(sizeof(element));
- if (element == NULL) {
- return NULL;
- }
- element->htmlc = htmlc;
- element->node = domelement;
-
- jselement = JS_InitClass(cx,
- parent,
- NULL,
- &JSCLASS_OBJECT,
- NULL,
- 0,
- jsproperties_element,
- jsfunctions_element,
- NULL,
- NULL);
- if (jselement == NULL) {
- free(element);
- return NULL;
- }
-
- LOG(("setting private to %p", element));
- /* private pointer to browsing context */
- if (JS_SetPrivate(cx, jselement, element) != JS_TRUE) {
- LOG(("failed to set private"));
- free(element);
- return NULL;
- }
-
- return jselement;
-}
diff --git a/javascript/jsapi/jsclass.h b/javascript/jsapi/jsclass.h
deleted file mode 100644
index 30b926a..0000000
--- a/javascript/jsapi/jsclass.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/** \file
- * jsapi pseudo class glue.
- */
-
-#ifndef _NETSURF_JAVASCRIPT_JSAPI_JSCLASS_H_
-#define _NETSURF_JAVASCRIPT_JSAPI_JSCLASS_H_
-
-#ifndef JSCLASS_NAME
-#error "The class name must be defined"
-#endif
-
-#ifndef JSCLASS_TYPE
-#define CLASS jsclass
-#define PRIVATE priv
-#define EXPAND(a,b) PASTE(a,b)
-#define PASTE(x,y) x##_##y
-#define JSCLASS_OBJECT EXPAND(CLASS,JSCLASS_NAME)
-#define JSCLASS_TYPE EXPAND(JSCLASS_OBJECT,PRIVATE)
-#endif
-
-#endif
diff --git a/javascript/jsapi/navigator.c b/javascript/jsapi/navigator.c
deleted file mode 100644
index 88fc535..0000000
--- a/javascript/jsapi/navigator.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <assert.h>
-#include <stdlib.h>
-
-#include "desktop/netsurf.h"
-#include "desktop/options.h"
-
-#include "utils/config.h"
-#include "utils/useragent.h"
-#include "utils/log.h"
-#include "utils/utsname.h"
-
-#include "javascript/jsapi.h"
-
-/*
- * navigator properties for netsurf
- *
- * Property | Everyone else | NetSurf | Notes
- * ------------+-----------------+--------------+------------------------------
- * appCodeName | "Mozilla" | "NetSurf" | This is kinda a pointless
- * | | | constant as everyone returns
- * | | | "Mozilla" which is dumb
- * ------------+-----------------+--------------+------------------------------
- * appName | "<Browsername>" | "NetSurf" | Browsers named other than
- * | | | "Netscape", "Mozilla",
- * | | | "Netscape Navigator",
- * | | | "Microsoft Internet Explorer"
- * | | | often other browser have
- * | | | "(compatible with Netscape)"
- * | | | append.
- * ------------+-----------------+--------------+------------------------------
- * appVersion | "<ver> (<type>)"| "<ver>" | Actually just the version
- * | | | number e.g "3.0".
- * ------------+-----------------+--------------+------------------------------
- * language | "<lang>" | "<lang>" | The language the frontend is
- * | | | configured for
- * ------------+-----------------+--------------+------------------------------
- * platform | "<krn> <hw>" | "<krn> <hw>" | Efectively uname -s -i,
- * | | | eg "Linux x86_64"
- * ------------+-----------------+--------------+------------------------------
- * userAgent | "Mozilla/5.0 (" | "NetSurf" | The usual useragent string
- * | | | with excessive lies
- * ------------+-----------------+--------------+------------------------------
- */
-
-static JSFunctionSpec jsfunctions_navigator[] = {
- JS_FS_END
-};
-
-#define NAVIGATOR_APPNAME "NetSurf"
-#define NAVIGATOR_APPCODENAME "NetSurf"
-
-static JSBool JSAPI_PROPERTYGET(appName, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME)));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(appName, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-static JSBool JSAPI_PROPERTYGET(appCodeName, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME)));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(appCodeName, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-static JSBool JSAPI_PROPERTYGET(appVersion, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, netsurf_version)));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(appVersion, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-static JSBool JSAPI_PROPERTYGET(language, JSContext *cx, JSObject *obj, jsval *vp)
-{
- const char *alang = nsoption_charp(accept_language);
-
- if (alang != NULL) {
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, alang)));
- } else {
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- }
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(language, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-static JSBool JSAPI_PROPERTYGET(platform, JSContext *cx, JSObject *obj, jsval *vp)
-{
- struct utsname *cutsname;
-
- cutsname = malloc(sizeof(struct utsname));
-
- if ((cutsname == NULL) || uname(cutsname) < 0) {
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- } else {
- char *platstr;
- int platstrlen;
- platstrlen = strlen(cutsname->sysname) + strlen(cutsname->machine) + 2;
- platstr = malloc(platstrlen);
- if (platstr != NULL) {
- snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine);
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyN(cx, platstr, platstrlen - 1)));
- free(platstr);
- } else {
- JS_SET_RVAL(cx, vp, JSVAL_VOID);
- }
- }
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(platform, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-static JSBool JSAPI_PROPERTYGET(userAgent, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, user_agent_string())));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(userAgent, JSContext *cx, JSObject *obj, jsval *vp)
-{
- assert(false);
- return JS_FALSE;
-}
-
-
-static JSPropertySpec jsproperties_navigator[] =
-{
- JSAPI_PS(appName, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS(appCodeName, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS(appVersion, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS(language, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS(platform, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS(userAgent, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
- JSAPI_PS_END
-};
-
-static JSClass jsclass_navigator =
-{
- "navigator",
- JSCLASS_HAS_PRIVATE,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- JS_FinalizeStub,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-JSObject *jsapi_new_navigator(JSContext *cx, JSObject *parent)
-{
- return JS_InitClass(cx,
- parent,
- NULL,
- &jsclass_navigator,
- NULL,
- 0,
- jsproperties_navigator,
- jsfunctions_navigator,
- NULL,
- NULL);
-}
diff --git a/javascript/jsapi/node.c b/javascript/jsapi/node.c
deleted file mode 100644
index b8c0737..0000000
--- a/javascript/jsapi/node.c
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-node
-
-interface Node : EventTarget {
- const unsigned short ELEMENT_NODE = 1;
- const unsigned short ATTRIBUTE_NODE = 2; // historical
- const unsigned short TEXT_NODE = 3;
- const unsigned short CDATA_SECTION_NODE = 4; // historical
- const unsigned short ENTITY_REFERENCE_NODE = 5; // historical
- const unsigned short ENTITY_NODE = 6; // historical
- const unsigned short PROCESSING_INSTRUCTION_NODE = 7;
- const unsigned short COMMENT_NODE = 8;
- const unsigned short DOCUMENT_NODE = 9;
- const unsigned short DOCUMENT_TYPE_NODE = 10;
- const unsigned short DOCUMENT_FRAGMENT_NODE = 11;
- const unsigned short NOTATION_NODE = 12; // historical
- readonly attribute unsigned short nodeType;
- readonly attribute DOMString nodeName;
-
- readonly attribute DOMString? baseURI;
-
- readonly attribute Document? ownerDocument;
- readonly attribute Node? parentNode;
- readonly attribute Element? parentElement;
- boolean hasChildNodes();
- readonly attribute NodeList childNodes;
- readonly attribute Node? firstChild;
- readonly attribute Node? lastChild;
- readonly attribute Node? previousSibling;
- readonly attribute Node? nextSibling;
-
- const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01;
- const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02;
- const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04;
- const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08;
- const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10;
- const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; // historical
- unsigned short compareDocumentPosition(Node other);
- boolean contains(Node? other);
-
- attribute DOMString? nodeValue;
- attribute DOMString? textContent;
- Node insertBefore(Node node, Node? child);
- Node appendChild(Node node);
- Node replaceChild(Node node, Node child);
- Node removeChild(Node child);
- void normalize();
-
-
- Node cloneNode(optional boolean deep = true);
- boolean isEqualNode(Node? node);
-
- DOMString lookupPrefix(DOMString? namespace);
- DOMString lookupNamespaceURI(DOMString? prefix);
- boolean isDefaultNamespace(DOMString? namespace);
-};
-*/
-
-#include "jsclass.h"
-
-#include "eventtarget.c"
-
-static JSBool JSAPI_NATIVE(hasChildNodes, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(compareDocumentPosition, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(contains, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(insertBefore, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(appendChild, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(replaceChild, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(removeChild, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(normalize, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(cloneNode, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(isEqualNode, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(lookupPrefix, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(lookupNamespaceURI, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(isDefaultNamespace, JSContext *cx, uintN argc, jsval *vp)
-{
- struct JSCLASS_TYPE *priv;
-
- priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &JSCLASS_OBJECT, NULL);
- if (priv == NULL)
- return JS_FALSE;
-
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-#define JSAPI_FS_NODE \
- JSAPI_FS_EVENTTARGET, \
- JSAPI_FS(hasChildNodes, 0, 0), \
- JSAPI_FS(compareDocumentPosition, 0, 0), \
- JSAPI_FS(contains, 0, 0), \
- JSAPI_FS(insertBefore, 0, 0), \
- JSAPI_FS(appendChild, 0, 0), \
- JSAPI_FS(replaceChild, 0, 0), \
- JSAPI_FS(removeChild, 0, 0), \
- JSAPI_FS(normalize, 0, 0), \
- JSAPI_FS(cloneNode, 0, 0), \
- JSAPI_FS(isEqualNode, 0, 0), \
- JSAPI_FS(lookupPrefix, 0, 0), \
- JSAPI_FS(lookupNamespaceURI, 0, 0), \
- JSAPI_FS(isDefaultNamespace, 0, 0)
-
-
-static JSBool JSAPI_PROPERTYGET(nodeType, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, JSVAL_NULL);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYGET(textContent, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, JSVAL_NULL);
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYSET(textContent, JSContext *cx, JSObject *obj, jsval *vp)
-{
- return JS_FALSE;
-}
-
-#define JSAPI_PS_NODE \
- JSAPI_PS_RO(nodeType, 0, JSPROP_ENUMERATE | JSPROP_SHARED), \
- JSAPI_PS(textContent, 0, JSPROP_ENUMERATE | JSPROP_SHARED)
diff --git a/javascript/jsapi/window.c b/javascript/jsapi/window.c
deleted file mode 100644
index 062d925..0000000
--- a/javascript/jsapi/window.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "utils/log.h"
-
-#include "javascript/jsapi.h"
-#include "javascript/jsapi/binding.h"
-
-
-struct jsclass_private {
- struct browser_window *bw;
- struct html_content *htmlc;
- JSObject *document_obj;
- JSObject *navigator_obj;
- JSObject *console_obj;
-};
-
-static void jsclass_finalize(JSContext *cx, JSObject *obj);
-static JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp);
-
-JSClass JSClass_Window = {
- "Window",
- JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- (JSResolveOp)jsclass_resolve,
- JS_ConvertStub,
- jsclass_finalize,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-static JSBool JSAPI_NATIVE(alert, JSContext *cx, uintN argc, jsval *vp)
-{
- JSString* u16_txt;
- char *txt;
- unsigned long length;
-
- if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
- return JS_FALSE;
-
- JSString_to_char(u16_txt, txt, length);
-
- warn_user(txt, NULL);
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(confirm, JSContext *cx, uintN argc, jsval *vp)
-{
- JSString* u16_txt;
- char *txt;
- unsigned long length;
- JSBool result = JS_FALSE;
-
- if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
- return JS_FALSE;
-
- JSString_to_char(u16_txt, txt, length);
-
- warn_user(txt, NULL);
-
- JSAPI_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(result));
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(prompt, JSContext *cx, uintN argc, jsval *vp)
-{
- JSString* u16_txt;
- char *txt;
- unsigned long length;
-
- if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
- return JS_FALSE;
-
- JSString_to_char(u16_txt, txt, length);
-
- warn_user(txt, NULL);
-
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(close, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(stop, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(focus, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSBool JSAPI_NATIVE(blur, JSContext *cx, uintN argc, jsval *vp)
-{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
-
- return JS_TRUE;
-}
-
-static JSFunctionSpec jsfunctions_window[] =
-{
- JSAPI_FS(close, 0, 0),
- JSAPI_FS(stop, 0, 0),
- JSAPI_FS(focus, 0, 0),
- JSAPI_FS(blur, 0, 0),
- JSAPI_FS(alert, 1, 0),
- JSAPI_FS(confirm, 1, 0),
- JSAPI_FS(prompt, 1, 0),
- JSAPI_FS_END
-};
-
-
-static JSBool JSAPI_PROPERTYGET(window, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYGET(self, JSContext *cx, JSObject *obj, jsval *vp)
-{
- JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
- return JS_TRUE;
-}
-
-static JSBool JSAPI_PROPERTYGET(document, JSContext *cx, JSObject *obj, jsval *vp)
-{
- struct jsclass_private *private;
-
- private = JS_GetInstancePrivate(cx,
- obj,
- &JSClass_Window,
- NULL);
- if (private == NULL)
- return JS_FALSE;
-
- JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(private->document_obj));
- return JS_TRUE;
-}
-
-static JSPropertySpec jsproperties_window[] =
-{
- JSAPI_PS_RO(document, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
- JSAPI_PS_RO(window, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
- JSAPI_PS_RO(self, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
- JSAPI_PS_END
-};
-
-static JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
-{
- *objp = NULL;
- return JS_TRUE;
-}
-
-static void jsclass_finalize(JSContext *cx, JSObject *obj)
-{ struct jsclass_private *private;
-
- private = JS_GetInstancePrivate(cx, obj, &JSClass_Window, NULL);
- if (private != NULL) {
- free(private);
- }
-}
-
-JSObject *jsapi_InitClass_Window(JSContext *cx, JSObject *parent)
-{
- JSObject *window = NULL;
- JSObject *proto;
-
- window = JS_NewCompartmentAndGlobalObject(cx, &JSClass_Window, NULL);
- if (window == NULL) {
- return NULL;
- }
-
- /** @todo reconsider global object handling. future
- * editions of spidermonkey appear to be removing the
- * idea of a global so we probably need to handle
- * global object references internally
- */
-
- /* set the contexts global */
- JS_SetGlobalObject(cx, window);
-
- /* Populate the global object with the standard globals, like
- * Object and Array.
- */
- if (!JS_InitStandardClasses(cx, window)) {
- return NULL;
- }
-
- /* Initialises all the user javascript classes to make their
- * prototypes available.
- */
- /** @todo should we be managing these prototype objects ourselves */
- proto = jsapi_InitClass_Document(cx, window);
- if (proto == NULL) {
- return NULL;
- }
-
- return window;
-}
-
-JSObject *jsapi_new_Window(JSContext *cx,
- JSObject *window,
- JSObject *parent,
- struct browser_window *bw,
- html_content *htmlc)
-{
- struct jsclass_private *private;
-
- /* @todo sort out windows that are not globals */
- assert(parent == NULL);
-
- /* create private data */
- private = malloc(sizeof(struct jsclass_private));
- if (private == NULL) {
- return NULL;
- }
- private->bw = bw;
- private->htmlc = htmlc;
-
-
- /* instantiate the subclasses off the window global */
- private->document_obj = jsapi_new_Document(cx,
- NULL,
- window,
- htmlc->document,
- htmlc);
- if (private->document_obj == NULL) {
- free(private);
- return NULL;
- }
-
- private->navigator_obj = jsapi_new_Navigator(cx, window);
- if (private->navigator_obj == NULL) {
- free(private);
- return NULL;
- }
-
- /** @todo forms, history, location */
-
- private->console_obj = jsapi_new_Console(cx, window);
- if (private->console_obj == NULL) {
- free(private);
- return NULL;
- }
-
- /* private pointer to browsing context */
- if (!JS_SetPrivate(cx, window, private))
- return NULL;
-
- /* functions */
- if (!JS_DefineFunctions(cx, window, jsfunctions_window)) {
- return NULL;
- }
-
- /* properties */
- if (!JS_DefineProperties(cx, window, jsproperties_window))
- return NULL;
-
-
- LOG(("Created new window object %p", window));
-
- return window;
-}
diff --git a/test/js/doc-dom2.html b/test/js/doc-dom2.html
index 17a916c..a55962b 100644
--- a/test/js/doc-dom2.html
+++ b/test/js/doc-dom2.html
@@ -4,9 +4,13 @@
<link rel="stylesheet" type="text/css" href="tst.css">
</head>
<body>
-<h1 id="heading">Direct DOM element reference</h1>
-<p>Before</p>
-<script>document.write(document.getElementById("heading").textContent);</script>
-<p>Afterwards</p>
+<h1>DOM getElementById element reference</h1>
+<p>This shows the text content of an element obtained using <a href="http://dom.spec.whatwg.org/#dom-document-getelementbyid">document.getElementById</a></p>
+<p>Referenced text</p>
+<p id="reftext">DOM getElementById element referenced test text</p>
+<p>Inserted text</p>
+<p><script>document.write(document.getElementById("reftext").textContent);</script></p>
+<p>After inserted text</p>
+
</body>
</html>
diff --git a/test/js/index.html b/test/js/index.html
index a7d34f5..f618e93 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -10,7 +10,7 @@
</ul>
<h2>Document write tests</h2>
<ul>
-<li><a href="inline-doc-write-simple.html">Simple docuemnt write</a></li>
+<li><a href="inline-doc-write-simple.html">Simple document write</a></li>
<li><a href="noscript-inline-doc-write.html">Script within inline script document write with noscript alternative</a></li>
<li><a href="inline-doc-write.html">Script within inline script</a></li>
<li><a href="sync-script.html">External syncronous script</a></li>
--
NetSurf Browser
10 years, 4 months
nsgenjsbind: branch master updated. 8779ca25c44286b956ac604549d55c7d1661619e
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/nsgenjsbind.git/shortlog/8779ca25c44286b95...
...commit http://git.netsurf-browser.org/nsgenjsbind.git/commit/8779ca25c44286b956a...
...tree http://git.netsurf-browser.org/nsgenjsbind.git/tree/8779ca25c44286b956ac6...
The branch, master has been updated
via 8779ca25c44286b956ac604549d55c7d1661619e (commit)
from e35c777cc2d3d551d4f659e95c06b902379992aa (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/nsgenjsbind.git/commitdiff/8779ca25c44286b...
commit 8779ca25c44286b956ac604549d55c7d1661619e
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
improve return variable handling
diff --git a/src/jsapi-libdom-operator.c b/src/jsapi-libdom-operator.c
index 748ea4c..a20f377 100644
--- a/src/jsapi-libdom-operator.c
+++ b/src/jsapi-libdom-operator.c
@@ -17,6 +17,9 @@
#include "webidl-ast.h"
#include "jsapi-libdom.h"
+#define WARN(msg, args...) fprintf(stderr, "%s: warning:"msg"\n", __func__, ## args);
+
+
static int webidl_func_spec_cb(struct webidl_node *node, void *ctx)
{
struct binding *binding = ctx;
@@ -125,6 +128,219 @@ int output_function_spec(struct binding *binding)
return res;
}
+static int output_return(struct binding *binding,
+ const char *ident,
+ struct webidl_node *node)
+{
+ struct webidl_node *arglist_node = NULL;
+ struct webidl_node *type_node = NULL;
+ struct webidl_node *type_base = NULL;
+ enum webidl_type webidl_arg_type;
+
+ arglist_node = webidl_node_find_type(node,
+ NULL,
+ WEBIDL_NODE_TYPE_LIST);
+
+ if (arglist_node == NULL) {
+ return -1; /* @todo check if this is broken AST */
+ }
+
+ type_node = webidl_node_find_type(webidl_node_getnode(arglist_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
+
+ type_base = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE_BASE);
+
+ webidl_arg_type = webidl_node_getint(type_base);
+
+ switch (webidl_arg_type) {
+ case WEBIDL_TYPE_USER:
+ /* User type are represented with jsobject */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ ident);
+
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ /* JSBool */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(%s));\n",
+ ident);
+
+ break;
+
+ case WEBIDL_TYPE_BYTE:
+ WARN("Unhandled type WEBIDL_TYPE_BYTE");
+ break;
+
+ case WEBIDL_TYPE_OCTET:
+ WARN("Unhandled type WEBIDL_TYPE_OCTET");
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ /* double */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ WARN("Unhandled type WEBIDL_TYPE_SHORT");
+ break;
+
+ case WEBIDL_TYPE_LONGLONG:
+ WARN("Unhandled type WEBIDL_TYPE_LONGLONG");
+ break;
+
+ case WEBIDL_TYPE_LONG:
+ /* int32_t */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, INT_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_STRING:
+ /* JSString * */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, STRING_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SEQUENCE:
+ WARN("Unhandled type WEBIDL_TYPE_SEQUENCE");
+ break;
+
+ case WEBIDL_TYPE_OBJECT:
+ /* JSObject * */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_DATE:
+ WARN("Unhandled type WEBIDL_TYPE_DATE");
+ break;
+
+ case WEBIDL_TYPE_VOID:
+ /* specifically requires no value */
+ break;
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+
+/* generate variable declaration of the correct type with appropriate default */
+static int output_return_declaration(struct binding *binding,
+ const char *ident,
+ struct webidl_node *node)
+{
+ struct webidl_node *arglist_node = NULL;
+ struct webidl_node *type_node = NULL;
+ struct webidl_node *type_base = NULL;
+ struct webidl_node *type_name = NULL;
+ enum webidl_type webidl_arg_type;
+
+ arglist_node = webidl_node_find_type(node,
+ NULL,
+ WEBIDL_NODE_TYPE_LIST);
+
+ if (arglist_node == NULL) {
+ return -1; /* @todo check if this is broken AST */
+ }
+
+ type_node = webidl_node_find_type(webidl_node_getnode(arglist_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
+
+ type_base = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE_BASE);
+
+ webidl_arg_type = webidl_node_getint(type_base);
+
+ switch (webidl_arg_type) {
+ case WEBIDL_TYPE_USER:
+ /* User type are represented with jsobject */
+ type_name = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_IDENT);
+ fprintf(binding->outfile,
+ "\tJSObject *%s = NULL; /* %s */\n",
+ ident,
+ webidl_node_gettext(type_name));
+
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ /* JSBool */
+ fprintf(binding->outfile, "\tJSBool %s = JS_FALSE;\n",ident);
+
+ break;
+
+ case WEBIDL_TYPE_BYTE:
+ WARN("Unhandled type WEBIDL_TYPE_BYTE");
+ break;
+
+ case WEBIDL_TYPE_OCTET:
+ WARN("Unhandled type WEBIDL_TYPE_OCTET");
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ /* double */
+ fprintf(binding->outfile, "\tdouble %s = 0;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ WARN("Unhandled type WEBIDL_TYPE_SHORT");
+ break;
+
+ case WEBIDL_TYPE_LONGLONG:
+ WARN("Unhandled type WEBIDL_TYPE_LONGLONG");
+ break;
+
+ case WEBIDL_TYPE_LONG:
+ /* int32_t */
+ fprintf(binding->outfile, "\tint32_t %s = 0;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_STRING:
+ /* JSString * */
+ fprintf(binding->outfile,
+ "\tJSString *%s = NULL;\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SEQUENCE:
+ WARN("Unhandled type WEBIDL_TYPE_SEQUENCE");
+ break;
+
+ case WEBIDL_TYPE_OBJECT:
+ /* JSObject * */
+ fprintf(binding->outfile, "\tJSObject *%s = NULL;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_DATE:
+ WARN("Unhandled type WEBIDL_TYPE_DATE");
+ break;
+
+ case WEBIDL_TYPE_VOID:
+ /* specifically requires no value */
+ break;
+
+ default:
+ break;
+ }
+ return 0;
+}
/** creates all the variable definitions
*
@@ -145,9 +361,6 @@ output_variable_definitions(struct binding *binding,
struct webidl_node *arg_type_ident = NULL;
enum webidl_type webidl_arg_type;
- /* return value */
- fprintf(binding->outfile, "\tjsval jsretval = JSVAL_VOID;\n");
-
/* input variables */
arglist_node = webidl_node_find_type(operation_list,
NULL,
@@ -197,7 +410,7 @@ output_variable_definitions(struct binding *binding,
NULL,
WEBIDL_NODE_TYPE_IDENT);
- fprintf(stderr,
+ fprintf(stderr,
"User type: %s:%s %s\n",
webidl_node_gettext(operation_ident),
webidl_node_gettext(arg_type_ident),
@@ -448,6 +661,9 @@ static int webidl_operator_body_cb(struct webidl_node *node, void *ctx)
fprintf(binding->outfile,
"{\n");
+ /* return value declaration */
+ output_return_declaration(binding, "jsret", webidl_node_getnode(node));
+
output_variable_definitions(binding, webidl_node_getnode(node));
if (binding->has_private) {
@@ -475,15 +691,16 @@ static int webidl_operator_body_cb(struct webidl_node *node, void *ctx)
genbind_node_getnode(operation_node));
} else {
- fprintf(stderr,
- "Warning: function/operation %s.%s has no implementation\n",
+ fprintf(stderr,
+ "warning: operation %s.%s has no implementation\n",
binding->interface,
webidl_node_gettext(ident_node));
}
+ output_return(binding, "jsret", webidl_node_getnode(node));
+
/* set return value an return true */
fprintf(binding->outfile,
- "\tJSAPI_SET_RVAL(cx, vp, jsretval);\n"
"\treturn JS_TRUE;\n"
"}\n\n");
}
diff --git a/src/jsapi-libdom-property.c b/src/jsapi-libdom-property.c
index 6083bb9..b5f30b9 100644
--- a/src/jsapi-libdom-property.c
+++ b/src/jsapi-libdom-property.c
@@ -140,48 +140,217 @@ output_property_spec(struct binding *binding)
return res;
}
-static int webidl_property_body_cb(struct webidl_node *node, void *ctx)
+#define WARN(msg, args...) fprintf(stderr, "%s: warning:"msg"\n", __func__, ## args);
+
+static int output_return(struct binding *binding,
+ const char *ident,
+ struct webidl_node *node)
{
- struct binding *binding = ctx;
- struct webidl_node *ident_node;
- struct webidl_node *modifier_node;
- struct genbind_node *property_node;
+ struct webidl_node *type_node = NULL;
+ struct webidl_node *type_base = NULL;
+ enum webidl_type webidl_arg_type;
- ident_node = webidl_node_find_type(webidl_node_getnode(node),
- NULL,
- WEBIDL_NODE_TYPE_IDENT);
- if (ident_node == NULL) {
- /* properties must have an operator
- * http://www.w3.org/TR/WebIDL/#idl-attributes
- */
- return 1;
- }
+ type_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
- modifier_node = webidl_node_find_type(webidl_node_getnode(node),
+ type_base = webidl_node_find_type(webidl_node_getnode(type_node),
NULL,
- WEBIDL_NODE_TYPE_MODIFIER);
+ WEBIDL_NODE_TYPE_TYPE_BASE);
+ webidl_arg_type = webidl_node_getint(type_base);
- if (webidl_node_getint(modifier_node) != WEBIDL_TYPE_READONLY) {
- /* no readonly so a set function is required */
+ switch (webidl_arg_type) {
+ case WEBIDL_TYPE_USER:
+ /* User type are represented with jsobject */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ /* JSBool */
fprintf(binding->outfile,
- "static JSBool JSAPI_PROPERTYSET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n",
- webidl_node_gettext(ident_node));
+ "\tJS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(%s));\n",
+ ident);
+
+ break;
+
+ case WEBIDL_TYPE_BYTE:
+ WARN("Unhandled type WEBIDL_TYPE_BYTE");
+ break;
+
+ case WEBIDL_TYPE_OCTET:
+ WARN("Unhandled type WEBIDL_TYPE_OCTET");
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ /* double */
fprintf(binding->outfile,
- "{\n"
- " return JS_FALSE;\n"
- "}\n\n");
+ "\tJS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ WARN("Unhandled type WEBIDL_TYPE_SHORT");
+ break;
+
+ case WEBIDL_TYPE_LONGLONG:
+ WARN("Unhandled type WEBIDL_TYPE_LONGLONG");
+ break;
+
+ case WEBIDL_TYPE_LONG:
+ /* int32_t */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, INT_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_STRING:
+ /* JSString * */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, STRING_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SEQUENCE:
+ WARN("Unhandled type WEBIDL_TYPE_SEQUENCE");
+ break;
+
+ case WEBIDL_TYPE_OBJECT:
+ /* JSObject * */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_DATE:
+ WARN("Unhandled type WEBIDL_TYPE_DATE");
+ break;
+
+ case WEBIDL_TYPE_VOID:
+ /* specifically requires no value */
+ break;
+
+ default:
+ break;
}
- /* property getter */
+ return 0;
+}
+
+
+/* generate variable declaration of the correct type with appropriate default */
+static int output_return_declaration(struct binding *binding,
+ const char *ident,
+ struct webidl_node *node)
+{
+ struct webidl_node *type_node = NULL;
+ struct webidl_node *type_base = NULL;
+ struct webidl_node *type_name = NULL;
+ enum webidl_type webidl_arg_type;
+
+ type_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
+
+ type_base = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE_BASE);
+
+ webidl_arg_type = webidl_node_getint(type_base);
+
+ switch (webidl_arg_type) {
+ case WEBIDL_TYPE_USER:
+ /* User type are represented with jsobject */
+ type_name = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_IDENT);
+ fprintf(binding->outfile,
+ "\tJSObject *%s = NULL; /* %s */\n",
+ ident,
+ webidl_node_gettext(type_name));
+
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ /* JSBool */
+ fprintf(binding->outfile, "\tJSBool %s = JS_FALSE;\n",ident);
+
+ break;
+
+ case WEBIDL_TYPE_BYTE:
+ WARN("Unhandled type WEBIDL_TYPE_BYTE");
+ break;
+
+ case WEBIDL_TYPE_OCTET:
+ WARN("Unhandled type WEBIDL_TYPE_OCTET");
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ /* double */
+ fprintf(binding->outfile, "\tdouble %s = 0;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ WARN("Unhandled type WEBIDL_TYPE_SHORT");
+ break;
+
+ case WEBIDL_TYPE_LONGLONG:
+ WARN("Unhandled type WEBIDL_TYPE_LONGLONG");
+ break;
+
+ case WEBIDL_TYPE_LONG:
+ /* int32_t */
+ fprintf(binding->outfile, "\tint32_t %s = 0;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_STRING:
+ /* JSString * */
+ fprintf(binding->outfile,
+ "\tJSString *%s = NULL;\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SEQUENCE:
+ WARN("Unhandled type WEBIDL_TYPE_SEQUENCE");
+ break;
+
+ case WEBIDL_TYPE_OBJECT:
+ /* JSObject * */
+ fprintf(binding->outfile, "\tJSObject *%s = NULL;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_DATE:
+ WARN("Unhandled type WEBIDL_TYPE_DATE");
+ break;
+
+ case WEBIDL_TYPE_VOID:
+ /* specifically requires no value */
+ break;
+
+ default:
+ break;
+ }
+ return 0;
+}
+
+static int output_property_getter(struct binding *binding,
+ struct webidl_node *node,
+ const char *ident)
+{
+ struct genbind_node *property_node;
+
fprintf(binding->outfile,
"static JSBool JSAPI_PROPERTYGET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n"
"{\n",
- webidl_node_gettext(ident_node));
+ ident);
- /* return value */
- fprintf(binding->outfile, "\tjsval jsretval = JSVAL_NULL;\n");
+ /* return value declaration */
+ output_return_declaration(binding, "jsret", node);
if (binding->has_private) {
/* get context */
@@ -193,14 +362,14 @@ static int webidl_property_body_cb(struct webidl_node *node, void *ctx)
"\t\t&JSClass_%s,\n"
"\t\tNULL);\n"
"\tif (private == NULL)\n"
- "\t\treturn JS_FALSE;\n\n",
+ "\t\treturn JS_FALSE;\n\n",
binding->interface);
}
property_node = genbind_node_find_type_ident(binding->gb_ast,
NULL,
GENBIND_NODE_TYPE_GETTER,
- webidl_node_gettext(ident_node));
+ ident);
if (property_node != NULL) {
/* binding source block */
@@ -218,33 +387,68 @@ static int webidl_property_body_cb(struct webidl_node *node, void *ctx)
internal_node = genbind_node_find_type_ident(genbind_node_getnode(binding_node),
NULL,
GENBIND_NODE_TYPE_BINDING_INTERNAL,
- webidl_node_gettext(ident_node));
+ ident);
}
if (internal_node != NULL) {
/** @todo fetching from internal entries ought to be type sensitive */
fprintf(binding->outfile,
- "\tjsretval = OBJECT_TO_JSVAL(private->%s);\n",
- webidl_node_gettext(ident_node));
+ "\tjsret = private->%s;\n",
+ ident);
} else {
- fprintf(stderr,
- "Warning: property/attribute getter %s.%s has no implementation\n",
+ fprintf(stderr,
+ "warning: attribute getter %s.%s has no implementation\n",
binding->interface,
- webidl_node_gettext(ident_node));
+ ident);
}
}
+ output_return(binding, "jsret", node);
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, jsretval);\n"
- "\treturn JS_TRUE;\n");
+ "\treturn JS_TRUE;\n"
+ "}\n\n");
+
+ return 0;
+}
+
+static int webidl_property_body_cb(struct webidl_node *node, void *ctx)
+{
+ struct binding *binding = ctx;
+ struct webidl_node *ident_node;
+ struct webidl_node *modifier_node;
- fprintf(binding->outfile, "}\n\n");
+ ident_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ WEBIDL_NODE_TYPE_IDENT);
+ if (ident_node == NULL) {
+ /* properties must have an operator
+ * http://www.w3.org/TR/WebIDL/#idl-attributes
+ */
+ return 1;
+ }
+ modifier_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ WEBIDL_NODE_TYPE_MODIFIER);
- return 0;
+
+ if (webidl_node_getint(modifier_node) != WEBIDL_TYPE_READONLY) {
+ /* no readonly so a set function is required */
+
+ fprintf(binding->outfile,
+ "static JSBool JSAPI_PROPERTYSET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n",
+ webidl_node_gettext(ident_node));
+ fprintf(binding->outfile,
+ "{\n"
+ " return JS_FALSE;\n"
+ "}\n\n");
+ }
+
+ /* property getter */
+ return output_property_getter(binding, node, webidl_node_gettext(ident_node));
}
/* callback to emit implements property bodys */
-----------------------------------------------------------------------
Summary of changes:
src/jsapi-libdom-operator.c | 231 ++++++++++++++++++++++++++++++++++-
src/jsapi-libdom-property.c | 282 +++++++++++++++++++++++++++++++++++++------
2 files changed, 467 insertions(+), 46 deletions(-)
diff --git a/src/jsapi-libdom-operator.c b/src/jsapi-libdom-operator.c
index 748ea4c..a20f377 100644
--- a/src/jsapi-libdom-operator.c
+++ b/src/jsapi-libdom-operator.c
@@ -17,6 +17,9 @@
#include "webidl-ast.h"
#include "jsapi-libdom.h"
+#define WARN(msg, args...) fprintf(stderr, "%s: warning:"msg"\n", __func__, ## args);
+
+
static int webidl_func_spec_cb(struct webidl_node *node, void *ctx)
{
struct binding *binding = ctx;
@@ -125,6 +128,219 @@ int output_function_spec(struct binding *binding)
return res;
}
+static int output_return(struct binding *binding,
+ const char *ident,
+ struct webidl_node *node)
+{
+ struct webidl_node *arglist_node = NULL;
+ struct webidl_node *type_node = NULL;
+ struct webidl_node *type_base = NULL;
+ enum webidl_type webidl_arg_type;
+
+ arglist_node = webidl_node_find_type(node,
+ NULL,
+ WEBIDL_NODE_TYPE_LIST);
+
+ if (arglist_node == NULL) {
+ return -1; /* @todo check if this is broken AST */
+ }
+
+ type_node = webidl_node_find_type(webidl_node_getnode(arglist_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
+
+ type_base = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE_BASE);
+
+ webidl_arg_type = webidl_node_getint(type_base);
+
+ switch (webidl_arg_type) {
+ case WEBIDL_TYPE_USER:
+ /* User type are represented with jsobject */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ ident);
+
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ /* JSBool */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(%s));\n",
+ ident);
+
+ break;
+
+ case WEBIDL_TYPE_BYTE:
+ WARN("Unhandled type WEBIDL_TYPE_BYTE");
+ break;
+
+ case WEBIDL_TYPE_OCTET:
+ WARN("Unhandled type WEBIDL_TYPE_OCTET");
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ /* double */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ WARN("Unhandled type WEBIDL_TYPE_SHORT");
+ break;
+
+ case WEBIDL_TYPE_LONGLONG:
+ WARN("Unhandled type WEBIDL_TYPE_LONGLONG");
+ break;
+
+ case WEBIDL_TYPE_LONG:
+ /* int32_t */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, INT_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_STRING:
+ /* JSString * */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, STRING_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SEQUENCE:
+ WARN("Unhandled type WEBIDL_TYPE_SEQUENCE");
+ break;
+
+ case WEBIDL_TYPE_OBJECT:
+ /* JSObject * */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_DATE:
+ WARN("Unhandled type WEBIDL_TYPE_DATE");
+ break;
+
+ case WEBIDL_TYPE_VOID:
+ /* specifically requires no value */
+ break;
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+
+/* generate variable declaration of the correct type with appropriate default */
+static int output_return_declaration(struct binding *binding,
+ const char *ident,
+ struct webidl_node *node)
+{
+ struct webidl_node *arglist_node = NULL;
+ struct webidl_node *type_node = NULL;
+ struct webidl_node *type_base = NULL;
+ struct webidl_node *type_name = NULL;
+ enum webidl_type webidl_arg_type;
+
+ arglist_node = webidl_node_find_type(node,
+ NULL,
+ WEBIDL_NODE_TYPE_LIST);
+
+ if (arglist_node == NULL) {
+ return -1; /* @todo check if this is broken AST */
+ }
+
+ type_node = webidl_node_find_type(webidl_node_getnode(arglist_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
+
+ type_base = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE_BASE);
+
+ webidl_arg_type = webidl_node_getint(type_base);
+
+ switch (webidl_arg_type) {
+ case WEBIDL_TYPE_USER:
+ /* User type are represented with jsobject */
+ type_name = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_IDENT);
+ fprintf(binding->outfile,
+ "\tJSObject *%s = NULL; /* %s */\n",
+ ident,
+ webidl_node_gettext(type_name));
+
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ /* JSBool */
+ fprintf(binding->outfile, "\tJSBool %s = JS_FALSE;\n",ident);
+
+ break;
+
+ case WEBIDL_TYPE_BYTE:
+ WARN("Unhandled type WEBIDL_TYPE_BYTE");
+ break;
+
+ case WEBIDL_TYPE_OCTET:
+ WARN("Unhandled type WEBIDL_TYPE_OCTET");
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ /* double */
+ fprintf(binding->outfile, "\tdouble %s = 0;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ WARN("Unhandled type WEBIDL_TYPE_SHORT");
+ break;
+
+ case WEBIDL_TYPE_LONGLONG:
+ WARN("Unhandled type WEBIDL_TYPE_LONGLONG");
+ break;
+
+ case WEBIDL_TYPE_LONG:
+ /* int32_t */
+ fprintf(binding->outfile, "\tint32_t %s = 0;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_STRING:
+ /* JSString * */
+ fprintf(binding->outfile,
+ "\tJSString *%s = NULL;\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SEQUENCE:
+ WARN("Unhandled type WEBIDL_TYPE_SEQUENCE");
+ break;
+
+ case WEBIDL_TYPE_OBJECT:
+ /* JSObject * */
+ fprintf(binding->outfile, "\tJSObject *%s = NULL;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_DATE:
+ WARN("Unhandled type WEBIDL_TYPE_DATE");
+ break;
+
+ case WEBIDL_TYPE_VOID:
+ /* specifically requires no value */
+ break;
+
+ default:
+ break;
+ }
+ return 0;
+}
/** creates all the variable definitions
*
@@ -145,9 +361,6 @@ output_variable_definitions(struct binding *binding,
struct webidl_node *arg_type_ident = NULL;
enum webidl_type webidl_arg_type;
- /* return value */
- fprintf(binding->outfile, "\tjsval jsretval = JSVAL_VOID;\n");
-
/* input variables */
arglist_node = webidl_node_find_type(operation_list,
NULL,
@@ -197,7 +410,7 @@ output_variable_definitions(struct binding *binding,
NULL,
WEBIDL_NODE_TYPE_IDENT);
- fprintf(stderr,
+ fprintf(stderr,
"User type: %s:%s %s\n",
webidl_node_gettext(operation_ident),
webidl_node_gettext(arg_type_ident),
@@ -448,6 +661,9 @@ static int webidl_operator_body_cb(struct webidl_node *node, void *ctx)
fprintf(binding->outfile,
"{\n");
+ /* return value declaration */
+ output_return_declaration(binding, "jsret", webidl_node_getnode(node));
+
output_variable_definitions(binding, webidl_node_getnode(node));
if (binding->has_private) {
@@ -475,15 +691,16 @@ static int webidl_operator_body_cb(struct webidl_node *node, void *ctx)
genbind_node_getnode(operation_node));
} else {
- fprintf(stderr,
- "Warning: function/operation %s.%s has no implementation\n",
+ fprintf(stderr,
+ "warning: operation %s.%s has no implementation\n",
binding->interface,
webidl_node_gettext(ident_node));
}
+ output_return(binding, "jsret", webidl_node_getnode(node));
+
/* set return value an return true */
fprintf(binding->outfile,
- "\tJSAPI_SET_RVAL(cx, vp, jsretval);\n"
"\treturn JS_TRUE;\n"
"}\n\n");
}
diff --git a/src/jsapi-libdom-property.c b/src/jsapi-libdom-property.c
index 6083bb9..b5f30b9 100644
--- a/src/jsapi-libdom-property.c
+++ b/src/jsapi-libdom-property.c
@@ -140,48 +140,217 @@ output_property_spec(struct binding *binding)
return res;
}
-static int webidl_property_body_cb(struct webidl_node *node, void *ctx)
+#define WARN(msg, args...) fprintf(stderr, "%s: warning:"msg"\n", __func__, ## args);
+
+static int output_return(struct binding *binding,
+ const char *ident,
+ struct webidl_node *node)
{
- struct binding *binding = ctx;
- struct webidl_node *ident_node;
- struct webidl_node *modifier_node;
- struct genbind_node *property_node;
+ struct webidl_node *type_node = NULL;
+ struct webidl_node *type_base = NULL;
+ enum webidl_type webidl_arg_type;
- ident_node = webidl_node_find_type(webidl_node_getnode(node),
- NULL,
- WEBIDL_NODE_TYPE_IDENT);
- if (ident_node == NULL) {
- /* properties must have an operator
- * http://www.w3.org/TR/WebIDL/#idl-attributes
- */
- return 1;
- }
+ type_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
- modifier_node = webidl_node_find_type(webidl_node_getnode(node),
+ type_base = webidl_node_find_type(webidl_node_getnode(type_node),
NULL,
- WEBIDL_NODE_TYPE_MODIFIER);
+ WEBIDL_NODE_TYPE_TYPE_BASE);
+ webidl_arg_type = webidl_node_getint(type_base);
- if (webidl_node_getint(modifier_node) != WEBIDL_TYPE_READONLY) {
- /* no readonly so a set function is required */
+ switch (webidl_arg_type) {
+ case WEBIDL_TYPE_USER:
+ /* User type are represented with jsobject */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ /* JSBool */
fprintf(binding->outfile,
- "static JSBool JSAPI_PROPERTYSET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n",
- webidl_node_gettext(ident_node));
+ "\tJS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(%s));\n",
+ ident);
+
+ break;
+
+ case WEBIDL_TYPE_BYTE:
+ WARN("Unhandled type WEBIDL_TYPE_BYTE");
+ break;
+
+ case WEBIDL_TYPE_OCTET:
+ WARN("Unhandled type WEBIDL_TYPE_OCTET");
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ /* double */
fprintf(binding->outfile,
- "{\n"
- " return JS_FALSE;\n"
- "}\n\n");
+ "\tJS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ WARN("Unhandled type WEBIDL_TYPE_SHORT");
+ break;
+
+ case WEBIDL_TYPE_LONGLONG:
+ WARN("Unhandled type WEBIDL_TYPE_LONGLONG");
+ break;
+
+ case WEBIDL_TYPE_LONG:
+ /* int32_t */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, INT_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_STRING:
+ /* JSString * */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, STRING_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SEQUENCE:
+ WARN("Unhandled type WEBIDL_TYPE_SEQUENCE");
+ break;
+
+ case WEBIDL_TYPE_OBJECT:
+ /* JSObject * */
+ fprintf(binding->outfile,
+ "\tJS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(%s));\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_DATE:
+ WARN("Unhandled type WEBIDL_TYPE_DATE");
+ break;
+
+ case WEBIDL_TYPE_VOID:
+ /* specifically requires no value */
+ break;
+
+ default:
+ break;
}
- /* property getter */
+ return 0;
+}
+
+
+/* generate variable declaration of the correct type with appropriate default */
+static int output_return_declaration(struct binding *binding,
+ const char *ident,
+ struct webidl_node *node)
+{
+ struct webidl_node *type_node = NULL;
+ struct webidl_node *type_base = NULL;
+ struct webidl_node *type_name = NULL;
+ enum webidl_type webidl_arg_type;
+
+ type_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
+
+ type_base = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE_BASE);
+
+ webidl_arg_type = webidl_node_getint(type_base);
+
+ switch (webidl_arg_type) {
+ case WEBIDL_TYPE_USER:
+ /* User type are represented with jsobject */
+ type_name = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_IDENT);
+ fprintf(binding->outfile,
+ "\tJSObject *%s = NULL; /* %s */\n",
+ ident,
+ webidl_node_gettext(type_name));
+
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ /* JSBool */
+ fprintf(binding->outfile, "\tJSBool %s = JS_FALSE;\n",ident);
+
+ break;
+
+ case WEBIDL_TYPE_BYTE:
+ WARN("Unhandled type WEBIDL_TYPE_BYTE");
+ break;
+
+ case WEBIDL_TYPE_OCTET:
+ WARN("Unhandled type WEBIDL_TYPE_OCTET");
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ /* double */
+ fprintf(binding->outfile, "\tdouble %s = 0;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ WARN("Unhandled type WEBIDL_TYPE_SHORT");
+ break;
+
+ case WEBIDL_TYPE_LONGLONG:
+ WARN("Unhandled type WEBIDL_TYPE_LONGLONG");
+ break;
+
+ case WEBIDL_TYPE_LONG:
+ /* int32_t */
+ fprintf(binding->outfile, "\tint32_t %s = 0;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_STRING:
+ /* JSString * */
+ fprintf(binding->outfile,
+ "\tJSString *%s = NULL;\n",
+ ident);
+ break;
+
+ case WEBIDL_TYPE_SEQUENCE:
+ WARN("Unhandled type WEBIDL_TYPE_SEQUENCE");
+ break;
+
+ case WEBIDL_TYPE_OBJECT:
+ /* JSObject * */
+ fprintf(binding->outfile, "\tJSObject *%s = NULL;\n", ident);
+ break;
+
+ case WEBIDL_TYPE_DATE:
+ WARN("Unhandled type WEBIDL_TYPE_DATE");
+ break;
+
+ case WEBIDL_TYPE_VOID:
+ /* specifically requires no value */
+ break;
+
+ default:
+ break;
+ }
+ return 0;
+}
+
+static int output_property_getter(struct binding *binding,
+ struct webidl_node *node,
+ const char *ident)
+{
+ struct genbind_node *property_node;
+
fprintf(binding->outfile,
"static JSBool JSAPI_PROPERTYGET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n"
"{\n",
- webidl_node_gettext(ident_node));
+ ident);
- /* return value */
- fprintf(binding->outfile, "\tjsval jsretval = JSVAL_NULL;\n");
+ /* return value declaration */
+ output_return_declaration(binding, "jsret", node);
if (binding->has_private) {
/* get context */
@@ -193,14 +362,14 @@ static int webidl_property_body_cb(struct webidl_node *node, void *ctx)
"\t\t&JSClass_%s,\n"
"\t\tNULL);\n"
"\tif (private == NULL)\n"
- "\t\treturn JS_FALSE;\n\n",
+ "\t\treturn JS_FALSE;\n\n",
binding->interface);
}
property_node = genbind_node_find_type_ident(binding->gb_ast,
NULL,
GENBIND_NODE_TYPE_GETTER,
- webidl_node_gettext(ident_node));
+ ident);
if (property_node != NULL) {
/* binding source block */
@@ -218,33 +387,68 @@ static int webidl_property_body_cb(struct webidl_node *node, void *ctx)
internal_node = genbind_node_find_type_ident(genbind_node_getnode(binding_node),
NULL,
GENBIND_NODE_TYPE_BINDING_INTERNAL,
- webidl_node_gettext(ident_node));
+ ident);
}
if (internal_node != NULL) {
/** @todo fetching from internal entries ought to be type sensitive */
fprintf(binding->outfile,
- "\tjsretval = OBJECT_TO_JSVAL(private->%s);\n",
- webidl_node_gettext(ident_node));
+ "\tjsret = private->%s;\n",
+ ident);
} else {
- fprintf(stderr,
- "Warning: property/attribute getter %s.%s has no implementation\n",
+ fprintf(stderr,
+ "warning: attribute getter %s.%s has no implementation\n",
binding->interface,
- webidl_node_gettext(ident_node));
+ ident);
}
}
+ output_return(binding, "jsret", node);
fprintf(binding->outfile,
- "\tJS_SET_RVAL(cx, vp, jsretval);\n"
- "\treturn JS_TRUE;\n");
+ "\treturn JS_TRUE;\n"
+ "}\n\n");
+
+ return 0;
+}
+
+static int webidl_property_body_cb(struct webidl_node *node, void *ctx)
+{
+ struct binding *binding = ctx;
+ struct webidl_node *ident_node;
+ struct webidl_node *modifier_node;
- fprintf(binding->outfile, "}\n\n");
+ ident_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ WEBIDL_NODE_TYPE_IDENT);
+ if (ident_node == NULL) {
+ /* properties must have an operator
+ * http://www.w3.org/TR/WebIDL/#idl-attributes
+ */
+ return 1;
+ }
+ modifier_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ WEBIDL_NODE_TYPE_MODIFIER);
- return 0;
+
+ if (webidl_node_getint(modifier_node) != WEBIDL_TYPE_READONLY) {
+ /* no readonly so a set function is required */
+
+ fprintf(binding->outfile,
+ "static JSBool JSAPI_PROPERTYSET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n",
+ webidl_node_gettext(ident_node));
+ fprintf(binding->outfile,
+ "{\n"
+ " return JS_FALSE;\n"
+ "}\n\n");
+ }
+
+ /* property getter */
+ return output_property_getter(binding, node, webidl_node_gettext(ident_node));
}
/* callback to emit implements property bodys */
--
NetSurf Generator for JavaScript bindings
10 years, 4 months