From c6e2d619e1cd12f629b0fb536fec844ccb7eae6e Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 31 Jul 2015 12:03:57 +0200 Subject: [PATCH] Buildfix for MacOS. --- libjsengine/JSV8Engine.cpp | 69 +++++++++++++++++++------------------- libjsengine/PrettyPrint.js | 2 +- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/libjsengine/JSV8Engine.cpp b/libjsengine/JSV8Engine.cpp index 77976a724..1a75a4620 100644 --- a/libjsengine/JSV8Engine.cpp +++ b/libjsengine/JSV8Engine.cpp @@ -32,13 +32,14 @@ using namespace std; using namespace dev; using namespace dev::eth; +using namespace v8; namespace dev { namespace eth { -static char const* toCString(v8::String::Utf8Value const& _value) +static char const* toCString(String::Utf8Value const& _value) { if (*_value) return *_value; @@ -47,12 +48,12 @@ static char const* toCString(v8::String::Utf8Value const& _value) // 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 -void reportException(v8::TryCatch* _tryCatch) +void reportException(TryCatch* _tryCatch) { - v8::HandleScope handle_scope; - v8::String::Utf8Value exception(_tryCatch->Exception()); + HandleScope handle_scope; + String::Utf8Value exception(_tryCatch->Exception()); char const* exceptionString = toCString(exception); - v8::Handle message = _tryCatch->Message(); + Handle message = _tryCatch->Message(); // V8 didn't provide any extra information about this error; just // print the exception. @@ -61,13 +62,13 @@ void reportException(v8::TryCatch* _tryCatch) else { // Print (filename):(line number): (message). - v8::String::Utf8Value filename(message->GetScriptResourceName()); + String::Utf8Value filename(message->GetScriptResourceName()); char const* filenameString = toCString(filename); int linenum = message->GetLineNumber(); printf("%s:%i: %s\n", filenameString, linenum, exceptionString); // Print line of source code. - v8::String::Utf8Value sourceline(message->GetSourceLine()); + String::Utf8Value sourceline(message->GetSourceLine()); char const* sourcelineString = toCString(sourceline); printf("%s\n", sourcelineString); @@ -83,7 +84,7 @@ void reportException(v8::TryCatch* _tryCatch) printf("\n"); - v8::String::Utf8Value stackTrace(_tryCatch->StackTrace()); + String::Utf8Value stackTrace(_tryCatch->StackTrace()); if (stackTrace.length() > 0) { char const* stackTraceString = toCString(stackTrace); @@ -92,13 +93,14 @@ void reportException(v8::TryCatch* _tryCatch) } } -v8::Handle ConsoleLog(v8::Arguments const& _args) +Handle ConsoleLog(Arguments const& _args) { - auto engine = reinterpret_cast(v8::External::Unwrap(_args.Data())); + Local wrap = Local::Cast(_args.Data()); + auto engine = reinterpret_cast(wrap->Value()); JSV8Printer printer(*engine); for (int i = 0; i < _args.Length(); ++i) printf("%s\n", printer.prettyPrint(_args[i]).cstr()); - return v8::Undefined(); + return Undefined(); } @@ -107,7 +109,7 @@ class JSV8Scope public: JSV8Scope(): m_handleScope(), - m_context(v8::Context::New(NULL, v8::ObjectTemplate::New())), + m_context(Context::New(NULL, ObjectTemplate::New())), m_contextScope(m_context) { m_context->Enter(); @@ -119,12 +121,12 @@ public: m_context.Dispose(); } - v8::Persistent const& context() const { return m_context; } + Persistent const& context() const { return m_context; } private: - v8::HandleScope m_handleScope; - v8::Persistent m_context; - v8::Context::Scope m_contextScope; + HandleScope m_handleScope; + Persistent m_context; + Context::Scope m_contextScope; }; } @@ -138,7 +140,7 @@ JSString JSV8Value::toString() const else if (m_value->IsUndefined()) return "undefined"; - v8::String::Utf8Value str(m_value); + String::Utf8Value str(m_value); return toCString(str); } @@ -154,16 +156,13 @@ JSV8Engine::JSV8Engine(): m_scope(new JSV8Scope()) eval("web3 = require('web3');"); eval(admin.c_str()); - auto consoleTemplate = v8::ObjectTemplate::New(); - for (auto property: {"log", "debug", "error"}) - consoleTemplate->Set( - v8::String::New(property), - v8::FunctionTemplate::New(ConsoleLog, v8::External::Wrap(this)) - ); - context()->Global()->Set( - v8::String::New("console"), - consoleTemplate->NewInstance() - ); + auto consoleTemplate = ObjectTemplate::New(); + + Local function = FunctionTemplate::New(ConsoleLog, External::New(this)); + consoleTemplate->Set(String::New("debug"), function); + consoleTemplate->Set(String::New("log"), function); + consoleTemplate->Set(String::New("error"), function); + context()->Global()->Set(String::New("console"), consoleTemplate->NewInstance()); } JSV8Engine::~JSV8Engine() @@ -173,18 +172,18 @@ JSV8Engine::~JSV8Engine() JSV8Value JSV8Engine::eval(char const* _cstr) const { - v8::TryCatch tryCatch; - v8::Local source = v8::String::New(_cstr); - v8::Local name(v8::String::New("(shell)")); - v8::ScriptOrigin origin(name); - v8::Handle script = v8::Script::Compile(source, &origin); + TryCatch tryCatch; + Local source = String::New(_cstr); + Local name(String::New("(shell)")); + ScriptOrigin origin(name); + Handle