/* 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;
%}