Skip to content

Commit 2ca5052

Browse files
committed
Merge pull request #21 from ngoyal/master
Build against V8 and README updates
2 parents 56c606d + 72a2841 commit 2ca5052

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ WHATS:
66

77
Go bindings for V8
88

9+
UPDATE for V8 3.21
10+
------------------
11+
12+
Only got this going against v8 for OSX. Build V8 for OSX as described by https://code.google.com/p/v8/wiki/BuildingWithGYP
13+
Copy $(V8SRCROOT)/include/ files to /usr/local/include
14+
Copy $(V8SRCROOT)/native/out/libv8\* files to /usr/local/lib
15+
16+
Issues:
17+
18+
# go test
19+
# testmain
20+
github.com/mattn/go-v8(__DATA/__datacoal_nt): unexpected reloc for dynamic symbol _ZTVN10__cxxabiv117__class_type_infoE
21+
github.com/mattn/go-v8(__DATA/__datacoal_nt): unhandled relocation for _ZTVN10__cxxabiv117__class_type_infoE (type 28 rtype 120)
22+
FAIL github.com/mattn/go-v8 [build failed]
23+
24+
925
INSTALL:
1026
--------
1127

v8.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package v8
22

33
/*
4-
#cgo LDFLAGS: -lv8 -lstdc++
4+
#cgo LDFLAGS: -L. -L/usr/local/lib libv8wrap.a -lv8_base.x64 -lv8 -lv8_nosnapshot.x64 -lstdc++
55
66
#include <stdlib.h>
77
#include "v8wrap.h"

v8wrap.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static volatile v8wrap_callback ___go_v8_callback = NULL;
1919

2020
static std::string
2121
to_json(v8::Handle<v8::Value> value) {
22-
v8::HandleScope scope;
22+
v8::HandleScope scope(v8::Isolate::GetCurrent());
2323
v8::TryCatch try_catch;
2424
v8::Handle<v8::Object> json = v8::Handle<v8::Object>::Cast(
2525
v8::Context::GetCurrent()->Global()->Get(v8::String::New("JSON")));
@@ -34,7 +34,7 @@ to_json(v8::Handle<v8::Value> value) {
3434

3535
v8::Handle<v8::Value>
3636
from_json(std::string str) {
37-
v8::HandleScope scope;
37+
v8::HandleScope scope(v8::Isolate::GetCurrent());
3838
v8::TryCatch try_catch;
3939

4040
v8::Handle<v8::Object> json = v8::Handle<v8::Object>::Cast(
@@ -51,8 +51,8 @@ v8_get_array_item(v8data* array, int index) {
5151
return array[index];
5252
}
5353

54-
v8::Handle<v8::Value>
55-
_go_call(const v8::Arguments& args) {
54+
void
55+
_go_call(const v8::FunctionCallbackInfo<v8::Value>& args) {
5656
v8::Locker v8Locker;
5757
uint32_t id = args[0]->ToUint32()->Value();
5858
v8::String::Utf8Value name(args[1]);
@@ -106,33 +106,34 @@ _go_call(const v8::Arguments& args) {
106106
if (retv != NULL) {
107107
v8::Handle<v8::Value> ret = from_json(retv);
108108
free(retv);
109-
return ret;
109+
args.GetReturnValue().Set(ret);
110110
}
111-
return v8::Undefined();
111+
args.GetReturnValue().Set(v8::Undefined());
112112
}
113113

114114
class V8Context {
115115
public:
116116
V8Context() : err_("") {
117117
v8::Locker v8Locker;
118-
v8::HandleScope scope;
119-
global_ = v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New());
120-
global_->Set(v8::String::New("_go_call"),
118+
v8::Isolate* isolate = v8::Isolate::GetCurrent();
119+
v8::HandleScope scope(isolate);
120+
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
121+
global->Set(v8::String::New("_go_call"),
121122
v8::FunctionTemplate::New(_go_call));
122-
v8::Handle<v8::Context> context = v8::Context::New(NULL, global_);
123-
context_ = v8::Persistent<v8::Context>::New(context);
123+
124+
v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
125+
context_.Reset(isolate, context);
126+
124127
};
125128

126129
virtual ~V8Context() {
127130
context_.Dispose();
128-
global_.Dispose();
129131
};
130-
v8::Handle<v8::Context> context() { return context_; };
132+
v8::Handle<v8::Context> context() { return v8::Handle<v8::Context>::New(v8::Isolate::GetCurrent(), context_); };
131133
const char* err() const { return err_.c_str(); };
132134
void err(const char* e) { this->err_ = std::string(e); }
133135

134136
private:
135-
v8::Persistent<v8::ObjectTemplate> global_;
136137
v8::Persistent<v8::Context> context_;
137138
std::string err_;
138139
};
@@ -197,7 +198,7 @@ char*
197198
v8_execute(void *ctx, char* source) {
198199
v8::Locker v8Locker;
199200
V8Context *context = static_cast<V8Context *>(ctx);
200-
v8::HandleScope scope;
201+
v8::HandleScope scope(v8::Isolate::GetCurrent());
201202
v8::TryCatch try_catch;
202203

203204
v8::Context::Scope context_scope(context->context());

0 commit comments

Comments
 (0)