diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-07-18 23:31:03 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-07-18 23:31:03 +0100 |
commit | 4e125c6e82444e5e4a08dbbe1a910551eb5b6f41 (patch) | |
tree | 698d93dbc58ce088e2e43029260503753c130736 /javascript/duktape | |
parent | 3b9df4f79655f80acbb508f85181f795319801a9 (diff) | |
download | netsurf-4e125c6e82444e5e4a08dbbe1a910551eb5b6f41.tar.gz netsurf-4e125c6e82444e5e4a08dbbe1a910551eb5b6f41.tar.bz2 |
REWORK: DODGY CRAP FOR VINCE
Diffstat (limited to 'javascript/duktape')
-rw-r--r-- | javascript/duktape/document.c | 69 | ||||
-rw-r--r-- | javascript/duktape/element.c | 50 | ||||
-rw-r--r-- | javascript/duktape/event_target.c | 44 | ||||
-rw-r--r-- | javascript/duktape/html_element.c | 50 | ||||
-rw-r--r-- | javascript/duktape/html_unknown_element.c | 50 | ||||
-rw-r--r-- | javascript/duktape/node.c | 52 | ||||
-rw-r--r-- | javascript/duktape/private.h | 41 | ||||
-rw-r--r-- | javascript/duktape/prototypes.h | 13 | ||||
-rw-r--r-- | javascript/duktape/window.c | 96 |
9 files changed, 465 insertions, 0 deletions
diff --git a/javascript/duktape/document.c b/javascript/duktape/document.c new file mode 100644 index 000000000..07b8becd3 --- /dev/null +++ b/javascript/duktape/document.c @@ -0,0 +1,69 @@ +/* DO NOT USE, DODGY BIT FOR VINCE */ + +#include <dom/dom.h> + +#include "utils/log.h" +#include "utils/corestrings.h" +#include "render/html_internal.h" +#include "utils/libdom.h" + +#include "javascript/dukky.h" + +DUKKY_FUNC_INIT(document, struct dom_document *document) +{ + DUKKY_FUNC_T(node, __init)(ctx, &priv->parent, (struct dom_node *)document); + LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv); +} + +DUKKY_FUNC_FINI(document) +{ + /* do any document finalisation here, priv ptr exists */ + LOG("Finalise %p", duk_get_heapptr(ctx, 0)); + DUKKY_FUNC_T(node, __fini)(ctx, &priv->parent); +} + +static DUKKY_FUNC(document, __constructor) +{ + DUKKY_CREATE_PRIVATE(document); + DUKKY_FUNC_T(document, __init)(ctx, priv, + duk_get_pointer(ctx, 1)); + duk_set_top(ctx, 1); + return 1; +} + +static DUKKY_FUNC(document, __destructor) +{ + DUKKY_SAFE_GET_PRIVATE(document, 0); + DUKKY_FUNC_T(document, __fini)(ctx, priv); + free(priv); + return 0; +} + +static DUKKY_FUNC(document, write) +{ + DUKKY_GET_METHOD_PRIVATE(document); + struct html_content *htmlc; + duk_size_t text_len; + const char *text = duk_get_lstring(ctx, 0, &text_len); + dom_exception err; + err = dom_node_get_user_data(priv->parent.node, + corestring_dom___ns_key_html_content_data, + &htmlc); + if (err == DOM_NO_ERR && htmlc->parser != NULL) { + dom_hubbub_parser_insert_chunk(htmlc->parser, (uint8_t *)text, text_len); + } + return 0; +} + +DUKKY_FUNC(document, __proto) +{ + /* Populate document's prototypical functionality */ + DUKKY_ADD_METHOD(document, write, 1); + /* Set this prototype's prototype (left-parent)*/ + DUKKY_GET_PROTOTYPE(node); + duk_set_prototype(ctx, 0); + /* And the initialiser/finalizer */ + DUKKY_SET_DESTRUCTOR(0, document); + DUKKY_SET_CONSTRUCTOR(0, document, 1); + return 1; /* The proto object */ +} diff --git a/javascript/duktape/element.c b/javascript/duktape/element.c new file mode 100644 index 000000000..f495d8621 --- /dev/null +++ b/javascript/duktape/element.c @@ -0,0 +1,50 @@ +/* DO NOT USE, DODGY BIT FOR VINCE */ + +#include <dom/dom.h> + +#include "utils/log.h" + +#include "javascript/dukky.h" + +DUKKY_FUNC_INIT(element, struct dom_element *element) +{ + DUKKY_FUNC_T(node, __init)(ctx, &priv->parent, (struct dom_node *)element); + LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv); +} + +DUKKY_FUNC_FINI(element) +{ + /* do any element finalisation here, priv ptr exists */ + LOG("Finalise %p", duk_get_heapptr(ctx, 0)); + DUKKY_FUNC_T(node, __fini)(ctx, &priv->parent); +} + +static DUKKY_FUNC(element, __constructor) +{ + DUKKY_CREATE_PRIVATE(element); + DUKKY_FUNC_T(element, __init)(ctx, priv, + duk_get_pointer(ctx, 1)); + duk_set_top(ctx, 1); + return 1; +} + +static DUKKY_FUNC(element, __destructor) +{ + DUKKY_SAFE_GET_PRIVATE(element, 0); + DUKKY_FUNC_T(element, __fini)(ctx, priv); + free(priv); + return 0; +} + +DUKKY_FUNC(element, __proto) +{ + /* Populate element's prototypical functionality */ + + /* Set this prototype's prototype (left-parent)*/ + DUKKY_GET_PROTOTYPE(node); + duk_set_prototype(ctx, 0); + /* And the initialiser/finalizer */ + DUKKY_SET_DESTRUCTOR(0, element); + DUKKY_SET_CONSTRUCTOR(0, element, 1); + return 1; /* The proto object */ +} diff --git a/javascript/duktape/event_target.c b/javascript/duktape/event_target.c new file mode 100644 index 000000000..669d0fd4f --- /dev/null +++ b/javascript/duktape/event_target.c @@ -0,0 +1,44 @@ +/* DO NOT USE, DODGY EXAMPLE FOR VINCE */ + +#include "utils/log.h" + +#include <dom/dom.h> + +#include "javascript/dukky.h" + +DUKKY_FUNC_INIT(event_target) +{ + LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv); +} + +DUKKY_FUNC_FINI(event_target) +{ + /* do any event_target finalisation here, priv ptr exists */ + LOG("Finalise %p", duk_get_heapptr(ctx, 0)); +} + +static DUKKY_FUNC(event_target, __constructor) +{ + DUKKY_CREATE_PRIVATE(event_target); + DUKKY_FUNC_T(event_target, __init)(ctx, priv); + return 1; +} + +static DUKKY_FUNC(event_target, __destructor) +{ + DUKKY_SAFE_GET_PRIVATE(event_target, 0); + DUKKY_FUNC_T(event_target, __fini)(ctx, priv); + free(priv); + return 0; +} + +DUKKY_FUNC(event_target, __proto) +{ + /* Populate event_target's prototypical functionality */ + + /* Set this prototype's prototype (left-parent)*/ + /* And the initialiser/finalizer */ + DUKKY_SET_DESTRUCTOR(0, event_target); + DUKKY_SET_CONSTRUCTOR(0, event_target, 0); + return 1; /* The proto object */ +} diff --git a/javascript/duktape/html_element.c b/javascript/duktape/html_element.c new file mode 100644 index 000000000..c129866e4 --- /dev/null +++ b/javascript/duktape/html_element.c @@ -0,0 +1,50 @@ +/* DO NOT USE, DODGY BIT FOR VINCE */ + +#include <dom/dom.h> + +#include "utils/log.h" + +#include "javascript/dukky.h" + +DUKKY_FUNC_INIT(html_element, struct dom_html_element *html_element) +{ + DUKKY_FUNC_T(element, __init)(ctx, &priv->parent, (struct dom_element *)html_element); + LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv); +} + +DUKKY_FUNC_FINI(html_element) +{ + /* do any html_element finalisation here, priv ptr exists */ + LOG("Finalise %p", duk_get_heapptr(ctx, 0)); + DUKKY_FUNC_T(element, __fini)(ctx, &priv->parent); +} + +static DUKKY_FUNC(html_element, __constructor) +{ + DUKKY_CREATE_PRIVATE(html_element); + DUKKY_FUNC_T(html_element, __init)(ctx, priv, + duk_get_pointer(ctx, 1)); + duk_set_top(ctx, 1); + return 1; +} + +static DUKKY_FUNC(html_element, __destructor) +{ + DUKKY_SAFE_GET_PRIVATE(html_element, 0); + DUKKY_FUNC_T(html_element, __fini)(ctx, priv); + free(priv); + return 0; +} + +DUKKY_FUNC(html_element, __proto) +{ + /* Populate html_element's prototypical functionality */ + + /* Set this prototype's prototype (left-parent)*/ + DUKKY_GET_PROTOTYPE(element); + duk_set_prototype(ctx, 0); + /* And the initialiser/finalizer */ + DUKKY_SET_DESTRUCTOR(0, html_element); + DUKKY_SET_CONSTRUCTOR(0, html_element, 1); + return 1; /* The proto object */ +} diff --git a/javascript/duktape/html_unknown_element.c b/javascript/duktape/html_unknown_element.c new file mode 100644 index 000000000..e728b4831 --- /dev/null +++ b/javascript/duktape/html_unknown_element.c @@ -0,0 +1,50 @@ +/* DO NOT USE, DODGY BIT FOR VINCE */ + +#include <dom/dom.h> + +#include "utils/log.h" + +#include "javascript/dukky.h" + +DUKKY_FUNC_INIT(html_unknown_element, struct dom_html_element *html_unknown_element) +{ + DUKKY_FUNC_T(html_element, __init)(ctx, &priv->parent, html_unknown_element); + LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv); +} + +DUKKY_FUNC_FINI(html_unknown_element) +{ + /* do any html_unknown_element finalisation here, priv ptr exists */ + LOG("Finalise %p", duk_get_heapptr(ctx, 0)); + DUKKY_FUNC_T(html_element, __fini)(ctx, &priv->parent); +} + +static DUKKY_FUNC(html_unknown_element, __constructor) +{ + DUKKY_CREATE_PRIVATE(html_unknown_element); + DUKKY_FUNC_T(html_unknown_element, __init)(ctx, priv, + duk_get_pointer(ctx, 1)); + duk_set_top(ctx, 1); + return 1; +} + +static DUKKY_FUNC(html_unknown_element, __destructor) +{ + DUKKY_SAFE_GET_PRIVATE(html_unknown_element, 0); + DUKKY_FUNC_T(html_unknown_element, __fini)(ctx, priv); + free(priv); + return 0; +} + +DUKKY_FUNC(html_unknown_element, __proto) +{ + /* Populate html_unknown_element's prototypical functionality */ + + /* Set this prototype's prototype (left-parent)*/ + DUKKY_GET_PROTOTYPE(html_element); + duk_set_prototype(ctx, 0); + /* And the initialiser/finalizer */ + DUKKY_SET_DESTRUCTOR(0, html_unknown_element); + DUKKY_SET_CONSTRUCTOR(0, html_unknown_element, 1); + return 1; /* The proto object */ +} diff --git a/javascript/duktape/node.c b/javascript/duktape/node.c new file mode 100644 index 000000000..5a0bc0e1a --- /dev/null +++ b/javascript/duktape/node.c @@ -0,0 +1,52 @@ +/* DO NOT USE, DODGY BIT FOR VINCE */ + +#include <dom/dom.h> + +#include "utils/log.h" + +#include "javascript/dukky.h" + +DUKKY_FUNC_INIT(node, struct dom_node *node) +{ + DUKKY_FUNC_T(event_target, __init)(ctx, &priv->parent); + LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv); + priv->node = dom_node_ref(node); +} + +DUKKY_FUNC_FINI(node) +{ + /* do any node finalisation here, priv ptr exists */ + LOG("Finalise %p", duk_get_heapptr(ctx, 0)); + dom_node_unref(priv->node); + DUKKY_FUNC_T(event_target, __fini)(ctx, &priv->parent); +} + +static DUKKY_FUNC(node, __constructor) +{ + DUKKY_CREATE_PRIVATE(node); + DUKKY_FUNC_T(node, __init)(ctx, priv, + duk_get_pointer(ctx, 1)); + duk_set_top(ctx, 1); + return 1; +} + +static DUKKY_FUNC(node, __destructor) +{ + DUKKY_SAFE_GET_PRIVATE(node, 0); + DUKKY_FUNC_T(node, __fini)(ctx, priv); + free(priv); + return 0; +} + +DUKKY_FUNC(node, __proto) +{ + /* Populate node's prototypical functionality */ + + /* Set this prototype's prototype (left-parent)*/ + DUKKY_GET_PROTOTYPE(event_target); + duk_set_prototype(ctx, 0); + /* And the initialiser/finalizer */ + DUKKY_SET_DESTRUCTOR(0, node); + DUKKY_SET_CONSTRUCTOR(0, node, 1); + return 1; /* The proto object */ +} diff --git a/javascript/duktape/private.h b/javascript/duktape/private.h new file mode 100644 index 000000000..5d5a070c3 --- /dev/null +++ b/javascript/duktape/private.h @@ -0,0 +1,41 @@ +#ifndef DUKKY_PRIVATE_H +#define DUKKY_PRIVATE_H + +struct browser_window; +struct html_content; +struct dom_node; +struct dom_element; +struct dom_document; +struct dom_html_element; + +typedef struct { +} event_target_private_t; + +typedef struct { + event_target_private_t parent; + struct browser_window *win; + struct html_content *htmlc; +} window_private_t; + +typedef struct { + event_target_private_t parent; + struct dom_node *node; +} node_private_t; + +typedef struct { + node_private_t parent; +} element_private_t; + +typedef struct { + element_private_t parent; +} html_element_private_t; + +typedef struct { + html_element_private_t parent; +} html_unknown_element_private_t; + +typedef struct { + node_private_t parent; +} document_private_t; + +#endif diff --git a/javascript/duktape/prototypes.h b/javascript/duktape/prototypes.h new file mode 100644 index 000000000..380b74111 --- /dev/null +++ b/javascript/duktape/prototypes.h @@ -0,0 +1,13 @@ +#ifndef DUKTAPE_PROTOTYPES_H +#define DUKTAPE_PROTOTYPES_H + +DUKKY_DECLARE_INTERFACE(event_target); +DUKKY_DECLARE_INTERFACE(window, struct browser_window *, struct html_content *); +DUKKY_DECLARE_INTERFACE(node, struct dom_node *); +DUKKY_DECLARE_INTERFACE(document, struct dom_document *); +DUKKY_DECLARE_INTERFACE(element, struct dom_element *); +DUKKY_DECLARE_INTERFACE(html_element, struct dom_html_element *); +DUKKY_DECLARE_INTERFACE(html_unknown_element, struct dom_html_element *); + +#endif + diff --git a/javascript/duktape/window.c b/javascript/duktape/window.c new file mode 100644 index 000000000..efba5851c --- /dev/null +++ b/javascript/duktape/window.c @@ -0,0 +1,96 @@ +/* DO NOT USE, DODGY BIT FOR VINCE */ + +#include <dom/dom.h> + +#include "utils/log.h" + +#include "javascript/dukky.h" + +#include "desktop/browser.h" +#include "render/html.h" +#include "render/html_internal.h" +#include "utils/nsurl.h" + +DUKKY_FUNC_INIT(window, struct browser_window *win, + struct html_content *htmlc) +{ + DUKKY_FUNC_T(event_target, __init)(ctx, &priv->parent); + LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv); + /* element window */ + priv->win = win; + priv->htmlc = htmlc; + LOG("win=%p htmlc=%p", priv->win, priv->htmlc); + + LOG("URL is %s", nsurl_access(browser_window_get_url(priv->win))); + + /* populate window.window */ + duk_dup(ctx, 0); + duk_put_prop_string(ctx, 0, "window"); +} + +DUKKY_FUNC_FINI(window) +{ + /* do any window finalisation here, priv ptr exists */ + LOG("Finalise %p", duk_get_heapptr(ctx, 0)); + DUKKY_FUNC_T(event_target, __fini)(ctx, &priv->parent); +} + +static DUKKY_FUNC(window, __constructor) +{ + DUKKY_CREATE_PRIVATE(window); + DUKKY_FUNC_T(window, __init)(ctx, priv, + duk_get_pointer(ctx, 1), + duk_get_pointer(ctx, 2)); + duk_set_top(ctx, 1); + return 1; +} + +static DUKKY_FUNC(window, __destructor) +{ + DUKKY_SAFE_GET_PRIVATE(window, 0); + DUKKY_FUNC_T(window, __fini)(ctx, priv); + free(priv); + return 0; +} + +static DUKKY_GETTER(window,document) +{ + DUKKY_GET_METHOD_PRIVATE(window); + LOG("priv=%p", priv); + duk_push_this(ctx); + duk_get_prop_string(ctx, -1, PROP_NAME(window, document)); + if (!duk_is_undefined(ctx, -1)) { + return 1; + } else { + duk_pop(ctx); + } + dom_document *doc = priv->htmlc->document; + duk_push_pointer(ctx, doc); + if (dukky_create_object(ctx, PROTO_NAME(document), 1) != DUK_EXEC_SUCCESS) { + LOG("ERROR"); + } + duk_push_this(ctx); + duk_dup(ctx, -2); + duk_put_prop_string(ctx, -2, PROP_NAME(window, document)); + duk_pop(ctx); + return 1; +} + +static DUKKY_SETTER(window,document) +{ + LOG("BWUAhAHAHAHAHA FUCK OFF"); + return 0; +} + +DUKKY_FUNC(window, __proto) +{ + /* Populate window's prototypical functionality */ + DUKKY_POPULATE_FULL_PROPERTY(window, document); + /* Set this prototype's prototype (left-parent)*/ + DUKKY_GET_PROTOTYPE(event_target); + duk_set_prototype(ctx, 0); + /* And the initialiser/finalizer */ + DUKKY_SET_DESTRUCTOR(0, window); + DUKKY_SET_CONSTRUCTOR(0, window, 2); + return 1; /* The proto object */ +} |