diff options
Diffstat (limited to 'content/handlers/javascript/duktape')
-rw-r--r-- | content/handlers/javascript/duktape/CSSRule.bnd | 22 | ||||
-rw-r--r-- | content/handlers/javascript/duktape/CSSStyleSheet.bnd | 22 | ||||
-rw-r--r-- | content/handlers/javascript/duktape/Console.bnd | 2 | ||||
-rw-r--r-- | content/handlers/javascript/duktape/DOMSettableTokenList.bnd | 44 | ||||
-rw-r--r-- | content/handlers/javascript/duktape/DOMTokenList.bnd | 163 | ||||
-rw-r--r-- | content/handlers/javascript/duktape/Element.bnd | 31 | ||||
-rw-r--r-- | content/handlers/javascript/duktape/ImageData.bnd | 2 | ||||
-rw-r--r-- | content/handlers/javascript/duktape/dukky.c | 8 | ||||
-rw-r--r-- | content/handlers/javascript/duktape/netsurf.bnd | 6 | ||||
-rw-r--r-- | content/handlers/javascript/duktape/polyfill.js | 18 |
10 files changed, 312 insertions, 6 deletions
diff --git a/content/handlers/javascript/duktape/CSSRule.bnd b/content/handlers/javascript/duktape/CSSRule.bnd new file mode 100644 index 000000000..555023c85 --- /dev/null +++ b/content/handlers/javascript/duktape/CSSRule.bnd @@ -0,0 +1,22 @@ +/* CSS Rule binding for NetSurf using duktape and libcss/libdom + * + * Copyright 2022 Daniel Silverstone <dsilvers@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 + */ + +/* Note, for now this exists purely to block warnings, eventually + * rules will have to come from stylesheets etc. + */ + +class CSSRule { + private bool unused; +}; + +init CSSRule() +%{ + priv->unused = true; +%} diff --git a/content/handlers/javascript/duktape/CSSStyleSheet.bnd b/content/handlers/javascript/duktape/CSSStyleSheet.bnd new file mode 100644 index 000000000..9167b8afa --- /dev/null +++ b/content/handlers/javascript/duktape/CSSStyleSheet.bnd @@ -0,0 +1,22 @@ +/* CSS Stylesheet binding for NetSurf using duktape and libcss/libdom + * + * Copyright 2022 Daniel Silverstone <dsilvers@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 + */ + +/* Note, for now this exists purely to block warnings, eventually + * stylesheets will have to come from documents etc. + */ + +class CSSStyleSheet { + private bool unused; +}; + +init CSSStyleSheet() +%{ + priv->unused = true; +%} diff --git a/content/handlers/javascript/duktape/Console.bnd b/content/handlers/javascript/duktape/Console.bnd index 74601d6d4..89d13cfad 100644 --- a/content/handlers/javascript/duktape/Console.bnd +++ b/content/handlers/javascript/duktape/Console.bnd @@ -182,7 +182,7 @@ method Console::timeEnd() duk_del_prop(ctx, 0); duk_push_string(ctx, "Timer elapsed: "); duk_insert(ctx, 0); - duk_push_sprintf(ctx, "%lu ms", (duk_uint_t)(time_ms - old_time_ms)); + duk_push_sprintf(ctx, "%u ms", (duk_uint_t)(time_ms - old_time_ms)); write_log_entry(ctx, priv->group, BW_CS_FLAG_LEVEL_INFO); return 0; %} diff --git a/content/handlers/javascript/duktape/DOMSettableTokenList.bnd b/content/handlers/javascript/duktape/DOMSettableTokenList.bnd new file mode 100644 index 000000000..ac5c7062a --- /dev/null +++ b/content/handlers/javascript/duktape/DOMSettableTokenList.bnd @@ -0,0 +1,44 @@ +/* DOMTokenList binding for browser using duktape and libdom + * + * Copyright 2015 Vincent Sanders <vince@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 + */ + +class DOMSettableTokenList { +}; + +init DOMSettableTokenList(struct dom_tokenlist *tokens::tokens); + +getter DOMSettableTokenList::value() +%{ + dom_exception exc; + dom_string *value; + + exc = dom_tokenlist_get_value(priv->parent.tokens, &value); + if (exc != DOM_NO_ERR) return 0; /* coerced to undefined */ + + duk_push_lstring(ctx, dom_string_data(value), dom_string_length(value)); + dom_string_unref(value); + + return 1; +%} + +setter DOMSettableTokenList::value() +%{ + dom_exception exc; + dom_string *value; + duk_size_t slen; + const char *s = duk_require_lstring(ctx, 0, &slen); + + exc = dom_string_create_interned((const uint8_t *)s, slen, &value); + if (exc != DOM_NO_ERR) return 0; + + exc = dom_tokenlist_set_value(priv->parent.tokens, value); + dom_string_unref(value); + + return 0; +%}
\ No newline at end of file diff --git a/content/handlers/javascript/duktape/DOMTokenList.bnd b/content/handlers/javascript/duktape/DOMTokenList.bnd new file mode 100644 index 000000000..928d9ef35 --- /dev/null +++ b/content/handlers/javascript/duktape/DOMTokenList.bnd @@ -0,0 +1,163 @@ +/* DOMTokenList binding for browser using duktape and libdom + * + * Copyright 2015 Vincent Sanders <vince@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 + */ + +class DOMTokenList { + private struct dom_tokenlist *tokens; +}; + +init DOMTokenList(struct dom_tokenlist *tokens) +%{ + priv->tokens = tokens; + dom_tokenlist_ref(tokens); +%} + +fini DOMTokenList() +%{ + dom_tokenlist_unref(priv->tokens); +%} + +getter DOMTokenList::length() +%{ + dom_exception err; + uint32_t len; + + err = dom_tokenlist_get_length(priv->tokens, &len); + + if (err != DOM_NO_ERR) return 0; /* coerced to undefined */ + + duk_push_uint(ctx, (duk_uint_t)len); + + return 1; +%} + +method DOMTokenList::item() +%{ + unsigned long i = duk_to_uint(ctx, 0); + dom_exception err; + dom_string *value; + + err = dom_tokenlist_item(priv->tokens, i, &value); + + if (err != DOM_NO_ERR) return 0; /* coerced to undefined */ + + if (value == NULL) { + duk_push_null(ctx); + return 1; + } + + duk_push_lstring(ctx, dom_string_data(value), dom_string_length(value)); + dom_string_unref(value); + + return 1; +%} + +method DOMTokenList::add() +%{ + dom_exception exc; + dom_string *value; + duk_size_t slen; + const char *s; + duk_idx_t spos; + + for (spos = 0; spos < duk_get_top(ctx); ++spos) { + s = duk_safe_to_lstring(ctx, spos, &slen); + + duk_safe_to_lstring(ctx, 0, &slen); + + exc = dom_string_create_interned((const uint8_t *)s, slen, &value); + if (exc != DOM_NO_ERR) return 0; + + exc = dom_tokenlist_add(priv->tokens, value); + dom_string_unref(value); + } + + return 0; +%} + +method DOMTokenList::remove() +%{ + dom_exception exc; + dom_string *value; + duk_size_t slen; + const char *s; + duk_idx_t spos; + + for (spos = 0; spos < duk_get_top(ctx); ++spos) { + s = duk_safe_to_lstring(ctx, spos, &slen); + + duk_safe_to_lstring(ctx, 0, &slen); + + exc = dom_string_create_interned((const uint8_t *)s, slen, &value); + if (exc != DOM_NO_ERR) return 0; + + exc = dom_tokenlist_remove(priv->tokens, value); + dom_string_unref(value); + } + + return 0; +%} + +method DOMTokenList::contains() +%{ + dom_exception exc; + dom_string *value; + duk_size_t slen; + const char *s = duk_safe_to_lstring(ctx, 0, &slen); + bool present = false; + + exc = dom_string_create_interned((const uint8_t *)s, slen, &value); + if (exc != DOM_NO_ERR) return 0; + + exc = dom_tokenlist_contains(priv->tokens, value, &present); + dom_string_unref(value); + if (exc != DOM_NO_ERR) return 0; + + duk_push_boolean(ctx, present); + + return 1; +%} + +method DOMTokenList::toggle() +%{ + dom_exception exc; + dom_string *value; + duk_size_t slen; + const char *s = duk_require_lstring(ctx, 0, &slen); + bool toggle_set = duk_get_top(ctx) > 1; + bool toggle = duk_opt_boolean(ctx, 1, 0); + bool present; + + exc = dom_string_create_interned((const uint8_t *)s, slen, &value); + if (exc != DOM_NO_ERR) return 0; + + exc = dom_tokenlist_contains(priv->tokens, value, &present); + if (exc != DOM_NO_ERR) { + dom_string_unref(value); + return 0; + } + + /* Decision matrix is based on present, toggle_set, and toggle */ + if (toggle_set) { + if (toggle) { + exc = dom_tokenlist_add(priv->tokens, value); + } else { + exc = dom_tokenlist_remove(priv->tokens, value); + } + } else { + if (present) { + exc = dom_tokenlist_add(priv->tokens, value); + } else { + exc = dom_tokenlist_remove(priv->tokens, value); + } + } + dom_string_unref(value); + + return 0; +%}
\ No newline at end of file diff --git a/content/handlers/javascript/duktape/Element.bnd b/content/handlers/javascript/duktape/Element.bnd index a965a6ceb..ff0686fd9 100644 --- a/content/handlers/javascript/duktape/Element.bnd +++ b/content/handlers/javascript/duktape/Element.bnd @@ -392,6 +392,37 @@ setter Element::className () return 0; %} +getter Element::classList () +%{ + dom_exception exc; + dom_tokenlist *tokens; + + duk_set_top(ctx, 0); + duk_push_this(ctx); + duk_get_prop_string(ctx, 0, MAGIC(classList)); + + if (duk_is_undefined(ctx, -1)) { + duk_pop(ctx); + exc = dom_tokenlist_create((dom_element *)priv->parent.node, corestring_dom_class, &tokens); + if (exc != DOM_NO_ERR) return 0; /* Coerced to undefined */ + + /* Create a settable tokenlist - While the IDL says this isn't settable, all browsers + * seem to make it settable, so we'll permit it too + */ + duk_push_pointer(ctx, tokens); + if (dukky_create_object(ctx, PROTO_NAME(DOMSETTABLETOKENLIST), 1) != DUK_EXEC_SUCCESS) { + dom_tokenlist_unref(tokens); + NSLOG(dukky, DEBUG, "Unable to create DOMSettableTokenList object"); + return 0; /* Coerced to undefined */ + } + dom_tokenlist_unref(tokens); + duk_dup(ctx, -1); + duk_put_prop_string(ctx, 0, MAGIC(classList)); + } + + return 1; +%} + getter Element::innerHTML() %{ duk_push_lstring(ctx, "", 0); diff --git a/content/handlers/javascript/duktape/ImageData.bnd b/content/handlers/javascript/duktape/ImageData.bnd index 17673d92a..be28cbd77 100644 --- a/content/handlers/javascript/duktape/ImageData.bnd +++ b/content/handlers/javascript/duktape/ImageData.bnd @@ -39,6 +39,6 @@ getter ImageData::data() %{ duk_push_this(ctx); duk_get_prop_string(ctx, -1, MAGIC(DATA)); - duk_push_buffer_object(ctx, -1, 0, priv->width * priv->height * 4, DUK_BUFOBJ_UINT8CLAMPEDARRAY); + duk_push_buffer_object(ctx, -1, 0, priv->width * priv->height * 4llu, DUK_BUFOBJ_UINT8CLAMPEDARRAY); return 1; %} diff --git a/content/handlers/javascript/duktape/dukky.c b/content/handlers/javascript/duktape/dukky.c index 52a9c82cf..a780b0067 100644 --- a/content/handlers/javascript/duktape/dukky.c +++ b/content/handlers/javascript/duktape/dukky.c @@ -385,7 +385,7 @@ static void dukky_html_element_class_from_tag_type(dom_html_element_type type, break; case DOM_HTML_ELEMENT_TYPE__COUNT: assert(type != DOM_HTML_ELEMENT_TYPE__COUNT); - /* fallthrough */ + fallthrough; case DOM_HTML_ELEMENT_TYPE__UNKNOWN: SET_HTML_CLASS(UNKNOWN) break; @@ -1156,7 +1156,7 @@ static void dukky_generic_event_handler(dom_event *evt, void *pw) NSLOG(dukky, DEBUG, "Unable to find the event name"); return; } - NSLOG(dukky, DEBUG, "Event's name is %*s", dom_string_length(name), + NSLOG(dukky, DEBUG, "Event's name is %*s", (int)dom_string_length(name), dom_string_data(name)); exc = dom_event_get_event_phase(evt, &phase); if (exc != DOM_NO_ERR) { @@ -1394,10 +1394,10 @@ void dukky_register_event_listener_for(duk_context *ctx, if (exc != DOM_NO_ERR) { NSLOG(dukky, DEBUG, "Unable to register listener for %p.%*s", ele, - dom_string_length(name), dom_string_data(name)); + (int)dom_string_length(name), dom_string_data(name)); } else { NSLOG(dukky, DEBUG, "have registered listener for %p.%*s", - ele, dom_string_length(name), dom_string_data(name)); + ele, (int)dom_string_length(name), dom_string_data(name)); } dom_event_listener_unref(listen); } diff --git a/content/handlers/javascript/duktape/netsurf.bnd b/content/handlers/javascript/duktape/netsurf.bnd index e47f07d2b..483f3471f 100644 --- a/content/handlers/javascript/duktape/netsurf.bnd +++ b/content/handlers/javascript/duktape/netsurf.bnd @@ -60,6 +60,8 @@ struct dom_html_br_element; #include "Document.bnd" #include "Node.bnd" #include "NodeList.bnd" +#include "DOMTokenList.bnd" +#include "DOMSettableTokenList.bnd" #include "NamedNodeMap.bnd" #include "Element.bnd" #include "HTMLCollection.bnd" @@ -205,3 +207,7 @@ init HTMLPropertiesCollection(struct dom_html_collection *coll); #include "CanvasRenderingContext2D.bnd" #include "ImageData.bnd" +/* CSS Object model */ + +#include "CSSRule.bnd" +#include "CSSStyleSheet.bnd" diff --git a/content/handlers/javascript/duktape/polyfill.js b/content/handlers/javascript/duktape/polyfill.js index 5f0215618..6c85ce1a0 100644 --- a/content/handlers/javascript/duktape/polyfill.js +++ b/content/handlers/javascript/duktape/polyfill.js @@ -83,3 +83,21 @@ if (!Array.from) { }; }()); } + +// DOMTokenList formatter, in theory we can remove this if we do the stringifier IDL support + +DOMTokenList.prototype.toString = function () { + if (this.length == 0) { + return ""; + } + + var ret = this.item(0); + for (var index = 1; index < this.length; index++) { + ret = ret + " " + this.item(index); + } + + return ret; +} + +// Inherit the same toString for settable lists +DOMSettableTokenList.prototype.toString = DOMTokenList.prototype.toString;
\ No newline at end of file |