Skip to content

Commit

Permalink
Attempt to fix build and travis for V8 6.7 and using gn instead of make.
Browse files Browse the repository at this point in the history
  • Loading branch information
augustoroman committed Mar 17, 2018
1 parent eadea8c commit 0479fb0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 31 deletions.
2 changes: 1 addition & 1 deletion example_bind_test.go
Expand Up @@ -36,7 +36,7 @@ func ExampleContext_Bind() {

// output:
// hello.js:2> Hello World!
// hello.js:3> function () { return "x" }
// hello.js:3> function() { return "x" }
// hello.js:4> 1,2,3
}

Expand Down
8 changes: 1 addition & 7 deletions symlink.sh
Expand Up @@ -20,13 +20,7 @@ if [[ ! -d "${V8_DIR}/include" ]]; then
exit 1
fi

if [[ "$(go env GOOS)" -eq "linux" ]]; then
V8_LIBS="out/native/obj.target/src"
elif [[ "$(go env GOOS)" -eq "darwin" ]]; then
V8_LIBS="out/native"
else
V8_LIBS="out/native" # take a guess
fi
V8_LIBS="out.gn/x64.release/obj"

if [[ ! -d "${V8_DIR}/${V8_LIBS}" ]]; then
echo "ERROR: ${V8_DIR}/${V8_LIBS} directory does not exist." >&2
Expand Down
3 changes: 2 additions & 1 deletion travis-install-linux.sh
Expand Up @@ -17,7 +17,8 @@ fetch v8
cd v8
git checkout ${V8_VERSION}
gclient sync
make -j 4 native GYPFLAGS="-Dv8_use_external_startup_data=0 -Dv8_enable_i18n_support=0 -Dv8_enable_gdbjit=0"
tools/dev/v8gen.py x64.release -- v8_use_external_startup_data=false v8_enable_i18n_support=false v8_enable_gdbjit=false v8_static_library=true is_component_build=false
ninja -C out.gn/x64.release v8_libbase v8_libplatform v8_base v8_snapshot
popd
./symlink.sh ${CHROMIUM_DIR}/v8
go install .
2 changes: 1 addition & 1 deletion v8.go
Expand Up @@ -12,7 +12,7 @@ package v8
// #include <string.h>
// #include "v8_c_bridge.h"
// #cgo CXXFLAGS: -I${SRCDIR} -I${SRCDIR}/include -std=c++11
// #cgo LDFLAGS: -L${SRCDIR}/libv8 -lv8_base -lv8_libbase -lv8_snapshot -lv8_libsampler -lv8_libplatform -ldl -pthread
// #cgo LDFLAGS: -L${SRCDIR}/libv8 -lv8_base -lv8_libbase -lv8_snapshot -lv8_libplatform -ldl -pthread
import "C"

import (
Expand Down
56 changes: 35 additions & 21 deletions v8_c_bridge.cc
Expand Up @@ -74,7 +74,7 @@ std::string str(v8::Local<v8::Value> value) {
return *s;
}

std::string report_exception(v8::Isolate* isolate, v8::TryCatch& try_catch) {
std::string report_exception(v8::Isolate* isolate, v8::Local<v8::Context> ctx, v8::TryCatch& try_catch) {
std::stringstream ss;
ss << "Uncaught exception: ";

Expand All @@ -84,18 +84,32 @@ std::string report_exception(v8::Isolate* isolate, v8::TryCatch& try_catch) {
if (!try_catch.Message().IsEmpty()) {
if (!try_catch.Message()->GetScriptResourceName()->IsUndefined()) {
ss << std::endl
<< "at " << str(try_catch.Message()->GetScriptResourceName()) << ":"
<< try_catch.Message()->GetLineNumber() << ":"
<< try_catch.Message()->GetStartColumn() << std::endl
<< " " << str(try_catch.Message()->GetSourceLine()) << std::endl
<< " ";
int start = try_catch.Message()->GetStartColumn();
int end = try_catch.Message()->GetEndColumn();
for (int i = 0; i < start; i++) {
ss << " ";
<< "at " << str(try_catch.Message()->GetScriptResourceName());

v8::Maybe<int> line_no = try_catch.Message()->GetLineNumber(ctx);
v8::Maybe<int> start = try_catch.Message()->GetStartColumn(ctx);
v8::Maybe<int> end = try_catch.Message()->GetEndColumn(ctx);
v8::MaybeLocal<v8::String> sourceLine = try_catch.Message()->GetSourceLine(ctx);

if (line_no.IsJust()) {
ss << ":" << line_no.ToChecked();
}
if (start.IsJust()) {
ss << ":" << start.ToChecked();
}
if (!sourceLine.IsEmpty()) {
ss << std::endl
<< " " << str(sourceLine.ToLocalChecked());
}
for (int i = start; i < end; i++) {
ss << "^";
if (start.IsJust() && end.IsJust()) {
ss << std::endl
<< " ";
for (int i = 0; i < start.ToChecked(); i++) {
ss << " ";
}
for (int i = start.ToChecked(); i < end.ToChecked(); i++) {
ss << "^";
}
}
}
}
Expand Down Expand Up @@ -139,7 +153,7 @@ ContextPtr v8_Isolate_NewContext(IsolatePtr isolate_ptr) {
ISOLATE_SCOPE(static_cast<v8::Isolate*>(isolate_ptr));
v8::HandleScope handle_scope(isolate);

v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
isolate->SetCaptureStackTraceForUncaughtExceptions(true);

v8::Local<v8::ObjectTemplate> globals = v8::ObjectTemplate::New(isolate);

Expand All @@ -150,7 +164,7 @@ ContextPtr v8_Isolate_NewContext(IsolatePtr isolate_ptr) {
}
void v8_Isolate_Terminate(IsolatePtr isolate_ptr) {
v8::Isolate* isolate = static_cast<v8::Isolate*>(isolate_ptr);
v8::V8::TerminateExecution(isolate);
isolate->TerminateExecution();
}
void v8_Isolate_Release(IsolatePtr isolate_ptr) {
if (isolate_ptr == nullptr) {
Expand All @@ -167,7 +181,7 @@ ValueErrorPair v8_Context_Run(ContextPtr ctxptr, const char* code, const char* f
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Context::Scope context_scope(ctx->ptr.Get(isolate));
v8::TryCatch try_catch;
v8::TryCatch try_catch(isolate);
try_catch.SetVerbose(false);

filename = filename ? filename : "(no file)";
Expand All @@ -179,14 +193,14 @@ ValueErrorPair v8_Context_Run(ContextPtr ctxptr, const char* code, const char* f
v8::String::NewFromUtf8(isolate, filename));

if (script.IsEmpty()) {
res.error_msg = DupString(report_exception(isolate, try_catch));
res.error_msg = DupString(report_exception(isolate, ctx->ptr.Get(isolate), try_catch));
return res;
}

v8::Local<v8::Value> result = script->Run();

if (result.IsEmpty()) {
res.error_msg = DupString(report_exception(isolate, try_catch));
res.error_msg = DupString(report_exception(isolate, ctx->ptr.Get(isolate), try_catch));
} else {
res.Value = static_cast<PersistentValuePtr>(new Value(isolate, result));
}
Expand Down Expand Up @@ -386,7 +400,7 @@ ValueErrorPair v8_Value_Call(ContextPtr ctxptr,
int argc, PersistentValuePtr* argvptr) {
VALUE_SCOPE(ctxptr);

v8::TryCatch try_catch;
v8::TryCatch try_catch(isolate);
try_catch.SetVerbose(false);

v8::Local<v8::Value> func_val = static_cast<Value*>(funcptr)->Get(isolate);
Expand All @@ -412,7 +426,7 @@ ValueErrorPair v8_Value_Call(ContextPtr ctxptr,
delete[] argv;

if (result.IsEmpty()) {
return (ValueErrorPair){nullptr, DupString(report_exception(isolate, try_catch))};
return (ValueErrorPair){nullptr, DupString(report_exception(isolate, ctx, try_catch))};
}

return (ValueErrorPair){
Expand All @@ -426,7 +440,7 @@ ValueErrorPair v8_Value_New(ContextPtr ctxptr,
int argc, PersistentValuePtr* argvptr) {
VALUE_SCOPE(ctxptr);

v8::TryCatch try_catch;
v8::TryCatch try_catch(isolate);
try_catch.SetVerbose(false);

v8::Local<v8::Value> func_val = static_cast<Value*>(funcptr)->Get(isolate);
Expand All @@ -445,7 +459,7 @@ ValueErrorPair v8_Value_New(ContextPtr ctxptr,
delete[] argv;

if (result.IsEmpty()) {
return (ValueErrorPair){nullptr, DupString(report_exception(isolate, try_catch))};
return (ValueErrorPair){nullptr, DupString(report_exception(isolate, ctx, try_catch))};
}

return (ValueErrorPair){
Expand Down

0 comments on commit 0479fb0

Please sign in to comment.