Mercurial > code
changeset 421:d046379137f3
Js:
- add deleteProperty
- add hasProperty
- add more documentation
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 08 Oct 2015 14:15:27 +0200 |
parents | 0631c4bd56f9 |
children | f32aaed52c93 |
files | C++/modules/Js/Js.h |
diffstat | 1 files changed, 95 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/modules/Js/Js.h Thu Oct 08 14:04:59 2015 +0200 +++ b/C++/modules/Js/Js.h Thu Oct 08 14:15:27 2015 +0200 @@ -51,6 +51,15 @@ */ using ContextPtr = duk_context *; +/* + * Basic types to manipulate with the stack + * ------------------------------------------------------------------ + * + * The following types can be used in some of the operations like Context::push or Context::is, they are defined + * usually as empty classes to determine the appropriate action to execute. + * + * For example, `ctx.push(js::Object{})` will push an empty object into the stack. + /** * @class Object * @brief Empty class tag for push() function. @@ -107,9 +116,19 @@ T *object; }; +/* + * Extended type manipulation + * ------------------------------------------------------------------ + * + * The following types are different as there are no equivalent in the native Duktape API, they are available for + * convenience. + */ + /** * @class Function * @brief Duktape/C function definition. + * + * This class wraps the std::function as a Duktape/C function by storing a copied pointer. */ class Function { public: @@ -343,6 +362,82 @@ } /** + * Delete a property. + * + * @param index the object index + * @return true if deleted + * @note Wrapper of duk_del_prop + */ + inline bool deleteProperty(int index) + { + return duk_del_prop(m_handle.get(), index); + } + + /** + * Delete a property by index. + * + * @param index the object index + * @param position the property index + * @return true if deleted + * @note Wrapper of duk_del_prop_index + */ + inline bool deleteProperty(int index, int position) + { + return duk_del_prop_index(m_handle.get(), index, position); + } + + /** + * Delete a property by name. + * + * @param index the object index + * @param name the property name + * @return true if deleted + * @note Wrapper of duk_del_prop_string + */ + inline bool deleteProperty(int index, const std::string &name) + { + return duk_del_prop_string(m_handle.get(), index, name.c_str()); + } + + /** + * Check if the object as a property. + * + * @param index the object index + * @return true if has + * @note Wrapper of duk_has_prop + */ + inline bool hasProperty(int index) + { + return duk_has_prop(m_handle.get(), index); + } + + /** + * Check if the object as a property by index. + * + * @param index the object index + * @param position the property index + * @return true if has + * @note Wrapper of duk_has_prop_index + */ + inline bool hasProperty(int index, int position) + { + return duk_has_prop_index(m_handle.get(), index, position); + } + + /** + * Check if the object as a property by string + * + * @param index the object index + * @param name the property name + * @return true if has + * @note Wrapper of duk_has_prop_string + */ + inline bool hasProperty(int index, const std::string &name) + { + return duk_has_prop_string(m_handle.get(), index, name.c_str()); + } + + /** * Get the type of the value at the specified index. * * @param ctx the context