Browse Source

removed redundant createShellContext function && fixed style of JSV8Engine files

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
36b4b46f66
  1. 30
      libjsengine/JSV8Engine.cpp
  2. 2
      libjsengine/JSV8Engine.h

30
libjsengine/JSV8Engine.cpp

@ -33,19 +33,19 @@ namespace dev
namespace eth namespace eth
{ {
static const char* toCString(v8::String::Utf8Value const& value) static char const* toCString(v8::String::Utf8Value const& _value)
{ {
return *value ? *value : "<string conversion failed>"; return *_value ? *_value : "<string conversion failed>";
} }
// from: https://github.com/v8/v8-git-mirror/blob/master/samples/shell.cc // from: https://github.com/v8/v8-git-mirror/blob/master/samples/shell.cc
// v3.15 from: https://chromium.googlesource.com/v8/v8.git/+/3.14.5.9/samples/shell.cc // v3.15 from: https://chromium.googlesource.com/v8/v8.git/+/3.14.5.9/samples/shell.cc
void reportException(v8::TryCatch* try_catch) void reportException(v8::TryCatch*_try_catch)
{ {
v8::HandleScope handle_scope; v8::HandleScope handle_scope;
v8::String::Utf8Value exception(try_catch->Exception()); v8::String::Utf8Value exception(_try_catch->Exception());
const char* exception_string = toCString(exception); char const* exception_string = toCString(exception);
v8::Handle<v8::Message> message = try_catch->Message(); v8::Handle<v8::Message> message = _try_catch->Message();
// V8 didn't provide any extra information about this error; just // V8 didn't provide any extra information about this error; just
// print the exception. // print the exception.
@ -55,13 +55,13 @@ void reportException(v8::TryCatch* try_catch)
{ {
// Print (filename):(line number): (message). // Print (filename):(line number): (message).
v8::String::Utf8Value filename(message->GetScriptResourceName()); v8::String::Utf8Value filename(message->GetScriptResourceName());
const char* filename_string = toCString(filename); char const* filename_string = toCString(filename);
int linenum = message->GetLineNumber(); int linenum = message->GetLineNumber();
printf("%s:%i: %s\n", filename_string, linenum, exception_string); printf("%s:%i: %s\n", filename_string, linenum, exception_string);
// Print line of source code. // Print line of source code.
v8::String::Utf8Value sourceline(message->GetSourceLine()); v8::String::Utf8Value sourceline(message->GetSourceLine());
const char* sourceline_string = toCString(sourceline); char const* sourceline_string = toCString(sourceline);
printf("%s\n", sourceline_string); printf("%s\n", sourceline_string);
// Print wavy underline (GetUnderline is deprecated). // Print wavy underline (GetUnderline is deprecated).
@ -76,10 +76,10 @@ void reportException(v8::TryCatch* try_catch)
printf("\n"); printf("\n");
v8::String::Utf8Value stack_trace(try_catch->StackTrace()); v8::String::Utf8Value stack_trace(_try_catch->StackTrace());
if (stack_trace.length() > 0) if (stack_trace.length() > 0)
{ {
const char* stack_trace_string = toCString(stack_trace); char const* stack_trace_string = toCString(stack_trace);
printf("%s\n", stack_trace_string); printf("%s\n", stack_trace_string);
} }
} }
@ -94,18 +94,12 @@ public:
} }
}; };
v8::Handle<v8::Context> createShellContext()
{
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
return v8::Context::New(NULL, global);
}
class JSV8Scope class JSV8Scope
{ {
public: public:
JSV8Scope(): JSV8Scope():
m_handleScope(), m_handleScope(),
m_context(createShellContext()), m_context(v8::Context::New(NULL, v8::ObjectTemplate::New())),
m_contextScope(m_context) m_contextScope(m_context)
{ {
m_context->Enter(); m_context->Enter();
@ -157,7 +151,7 @@ JSV8Engine::~JSV8Engine()
delete m_scope; delete m_scope;
} }
JSV8Value JSV8Engine::eval(const char* _cstr) const JSV8Value JSV8Engine::eval(char const* _cstr) const
{ {
v8::HandleScope handleScope; v8::HandleScope handleScope;
v8::TryCatch tryCatch; v8::TryCatch tryCatch;

2
libjsengine/JSV8Engine.h

@ -49,7 +49,7 @@ class JSV8Engine : public JSEngine<JSV8Value>
public: public:
JSV8Engine(); JSV8Engine();
virtual ~JSV8Engine(); virtual ~JSV8Engine();
JSV8Value eval(const char* _cstr) const; JSV8Value eval(char const* _cstr) const;
v8::Handle<v8::Context> const& context() const; v8::Handle<v8::Context> const& context() const;
private: private:

Loading…
Cancel
Save