Browse Source

throwing exception if we cannot print jsvalue

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
553676bc9e
  1. 4
      libjsengine/JSEngine.h
  2. 4
      libjsengine/JSV8Engine.cpp
  3. 4
      libjsengine/JSV8Printer.cpp

4
libjsengine/JSEngine.h

@ -21,12 +21,16 @@
*/
#pragma once
#include <exception>
namespace dev
{
namespace eth
{
class JSException: public std::exception {};
class JSPrintException: public JSException { char const* what() const noexcept { return "Cannot print expression!"; } };
class JSString
{
public:

4
libjsengine/JSV8Engine.cpp

@ -35,7 +35,9 @@ namespace eth
static char const* toCString(v8::String::Utf8Value const& _value)
{
return *_value ? *_value : "<string conversion failed>";
if (*_value)
return *_value;
throw JSPrintException();
}
// from: https://github.com/v8/v8-git-mirror/blob/master/samples/shell.cc

4
libjsengine/JSV8Printer.cpp

@ -43,5 +43,7 @@ JSString JSV8Printer::prettyPrint(JSV8Value const& _value) const
v8::Local<v8::Value> values[1] = {v8::Local<v8::Value>::New(_value.value())};
v8::Local<v8::Value> res = func->Call(func, 1, values);
v8::String::Utf8Value str(res);
return *str ? *str : "<pretty print conversion failed>";
if (*str)
return *str;
throw JSPrintException();
}

Loading…
Cancel
Save