Mercurial > code
view C++/modules/Js/Js.cpp @ 398:94bfe7ba9a13
Js:
- Rename some functions
- Cleanup a lot
- Add more documentation
- Add specialization of getProperty and getGlobal to void to push on the
stack
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 30 Sep 2015 19:59:12 +0200 |
parents | 69adcefe73ae |
children | ca5e4360f79a |
line wrap: on
line source
/* * Js.cpp -- JS API for irccd and Duktape helpers * * Copyright (c) 2013, 2014, 2015 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "Js.h" using namespace std::string_literals; namespace js { ErrorInfo Context::error(int index) { ErrorInfo error; index = duk_normalize_index(m_handle.get(), index); duk_get_prop_string(m_handle.get(), index, "name"); error.name = duk_to_string(m_handle.get(), -1); duk_get_prop_string(m_handle.get(), index, "message"); error.message = duk_to_string(m_handle.get(), -1); duk_get_prop_string(m_handle.get(), index, "fileName"); error.fileName = duk_to_string(m_handle.get(), -1); duk_get_prop_string(m_handle.get(), index, "lineNumber"); error.lineNumber = duk_to_int(m_handle.get(), -1); duk_get_prop_string(m_handle.get(), index, "stack"); error.stack = duk_to_string(m_handle.get(), -1); duk_pop_n(m_handle.get(), 5); return error; } void Context::pcall(unsigned nargs) { if (duk_pcall(m_handle.get(), nargs) != 0) { ErrorInfo info = error(-1); duk_pop(m_handle.get()); throw info; } } void Context::peval() { if (duk_peval(m_handle.get()) != 0) { ErrorInfo info = error(-1); duk_pop(m_handle.get()); throw info; } } } // !js