GithubHelp home page GithubHelp logo

go-v8's Introduction

go-v8

WHATS:

Go bindings for V8

UPDATE for V8 3.21

Only got this going against v8 for OSX. Build V8 for OSX as described by https://code.google.com/p/v8/wiki/BuildingWithGYP Copy $(V8SRCROOT)/include/ files to /usr/local/include Copy $(V8SRCROOT)/native/out/libv8* files to /usr/local/lib

Issues:

# go test
# testmain
github.com/mattn/go-v8(__DATA/__datacoal_nt): unexpected reloc for dynamic symbol _ZTVN10__cxxabiv117__class_type_infoE
github.com/mattn/go-v8(__DATA/__datacoal_nt): unhandled relocation for _ZTVN10__cxxabiv117__class_type_infoE (type 28 rtype 120)
FAIL    github.com/mattn/go-v8 [build failed]

INSTALL:

WIN32

# To Build v8 go package:
# make v8wrap.dll
# go install

# To run go-v8 tests:
# go test

# To run example go exec:
# cd example
# copy v8wrap.dll
# go build example.go
# ./example

LINUX

# To Build v8 go package:
# make libv8wrap.so
# go install

# To run go-v8 tests:
# LD_LIBRARY_PATH=. go test

# To run example go exec:
# cd example
# go build example.go
# LD_LIBRARY_PATH=.. ./example

MAC OS X

# To Build v8 go package:
# make libv8wrap.so
# go install

# To run go-v8 tests:
# DYLD_LIBRARY_PATH=. go test

# To run example go exec:
# cd example
# go build example.go
# DYLD_LIBRARY_PATH=.. ./example

LICENSE:

under the MIT License: http://mattn.mit-license.org/2013

AUTHOR:

  • Yasuhiro Matsumoto

go-v8's People

Contributors

cwc avatar jasondelponte avatar ksx123 avatar mattn avatar ngoyal avatar sixthgear avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-v8's Issues

README should be updated to mention OS X support

I attempted to build with Mac OS 10.8.2 and succeeded with no issues.
The build and install instructions for Linux work as written with the one exception that DYLD_LIBRARY_PATH should be used instead of LD_LIBRARY_PATH. The tests and examples work as expected.

Perhaps you want to mention this in the README? I used the homebrew version of v8 for the record.

Cannot build libv8wrap.so

When I tried the install process as described in the README, I couldn't build libv8wrap.so:

[karol@szabbook 11-12-06 20:52 Code/go-v8] gomake libv8wrap.so
g++ -shared -o libv8wrap.so -I. v8wrap.cc -lv8
/usr/bin/ld: /tmp/ccZN2vuP.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/ccZN2vuP.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [libv8wrap.so] Error 1

I use the go build from the Arch Linux repository.

build instructions for windows are outdated

I wanted to give go-v8 a try, but I am in front of a windows PC right now and the build instructions for windows in the README seem to be outdated. Support for make v8wrap.dll was removed with 0900d9a. Is Windows still a supported platform of this project?

Compilation problem

I'm getting following errors on compilation:

g++ `go env GOGCCFLAGS` -I. -c v8wrap.cc -lv8
v8wrap.cc: In function ‘std::string to_json(v8::Handle<v8::Value>)’:
v8wrap.cc:22:19: error: no matching function for call to ‘v8::HandleScope::HandleScope()’
   v8::HandleScope scope;
                   ^
v8wrap.cc:22:19: note: candidates are:
In file included from v8wrap.cc:1:0:
/usr/include/v8.h:783:3: note: v8::HandleScope::HandleScope(const v8::HandleScope&)
   HandleScope(const HandleScope&);
   ^
/usr/include/v8.h:783:3: note:   candidate expects 1 argument, 0 provided
/usr/include/v8.h:756:3: note: v8::HandleScope::HandleScope(v8::Isolate*)
   HandleScope(Isolate* isolate);
   ^

[...] loads of other errors [...]

v8wrap.cc:200:19: error: no matching function for call to ‘v8::HandleScope::HandleScope()’
   v8::HandleScope scope;
                   ^
v8wrap.cc:200:19: note: candidates are:
In file included from v8wrap.cc:1:0:
/usr/include/v8.h:783:3: note: v8::HandleScope::HandleScope(const v8::HandleScope&)
   HandleScope(const HandleScope&);
   ^
/usr/include/v8.h:783:3: note:   candidate expects 1 argument, 0 provided
/usr/include/v8.h:756:3: note: v8::HandleScope::HandleScope(v8::Isolate*)
   HandleScope(Isolate* isolate);
   ^
/usr/include/v8.h:756:3: note:   candidate expects 1 argument, 0 provided
Makefile:6: recipe for target 'libv8wrap.a' failed
make: *** [libv8wrap.a] Error 1

Is it possible that the package does not compile with newer versions of v8? I'm using version 3.21.18.

Additionally: there is no libv8wrap.so target in the Makefile, it's called libv8wrap.a.

Is this discontinued?

Could not install with current v8. Many errors has been occurred.
Is there update plan to apply current v8?

installation

I might be doing this wrong, as far as I can tell I have all of the dependencies install, I have tried this a few different ways but I'm not sure what this mean.

$ go build
# github.com/mattn/go-v8
Undefined symbols for architecture x86_64:
  "_v8_create", referenced from:
      __cgo_c1f1ec10ebea_Cfunc_v8_create in v8.cgo2.o
     (maybe you meant: __cgo_c1f1ec10ebea_Cfunc_v8_create)
  "_v8_error", referenced from:
      __cgo_c1f1ec10ebea_Cfunc_v8_error in v8.cgo2.o
     (maybe you meant: __cgo_c1f1ec10ebea_Cfunc_v8_error)
  "_v8_execute", referenced from:
      __cgo_c1f1ec10ebea_Cfunc_v8_execute in v8.cgo2.o
     (maybe you meant: __cgo_c1f1ec10ebea_Cfunc_v8_execute)
  "_v8_get_array_item", referenced from:
      __cgo_c1f1ec10ebea_Cfunc_v8_get_array_item in v8.cgo2.o
     (maybe you meant: __cgo_c1f1ec10ebea_Cfunc_v8_get_array_item)
  "_v8_init", referenced from:
      __cgo_c1f1ec10ebea_Cfunc_v8_callback_init in v8.cgo2.o
  "_v8_release", referenced from:
      __cgo_c1f1ec10ebea_Cfunc_v8_release in v8.cgo2.o
     (maybe you meant: __cgo_c1f1ec10ebea_Cfunc_v8_release)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

I'm on a mac with
go 1.1.2
libv8-3.16.14.3-x86_64

Goinstallation error

Trying to goinstall on my Arch Linux (with go from the repo) gives me the following:

? goinstall github.com/mattn/go-v8
goinstall: encoding/json: go/build: package could not be found locally ($GOPATH not set)
goinstall: errors: go/build: package could not be found locally ($GOPATH not set)
goinstall: text/template: go/build: package could not be found locally ($GOPATH not set)

Seems like some of the required packages have changed names since the last commit. Or am I mistaken?

install error

Hi, I am trying to make the project but I get the error:

~/gocode/src/go-v8 $ go build

/usr/bin/ld: cannot find -lv8wrap
collect2: ld returned 1 exit status

Do you know what I am missing? thank you.

Timeouts and Intervals

I would like to implement setTimeout and setInterval. The version that I have created below works but it is blocking anything in the JS from running. I'm new to Go but it seems like the v8 instance needs to be in a go routine and separated from normal execution. Here is my code, am I doing something wrong or is there something else I need to be doing related to the v8 VM to get this working?

js.AddFunc("_set_timeout", func(args ...interface{}) (interface{}, error){
    delay := time.Duration(args[1].(float64)) * time.Millisecond
    ticker := time.NewTicker(delay)
    quit := make(chan struct{})
    go func() {
        for {
            select {
                case <- ticker.C:
                    args[0].(v8.Function).Call()
                case <- quit:
                    ticker.Stop()
                    return
            }
        }
    }()
    time.Sleep(delay)
    close(quit)
    return "", nil
}) 

Testsuite does not work

Hey :)

I just started working with (and on) go-v8 and I'm currently unable to run the test suite.
I usually hate opening issues without including a fix, but I feel I'm not knowledgable enough about v8 to fix this v8-specific problem on my own. I was hoping we could take a stab at it together.

Symptoms

I'm working on 2 system:

  • Ubuntu 12.10, go version 1.0.3, libv8 3.8.9.20-2
  • Mac OS X 10.8.2, go version 1.0.3, libv8 3.16.14

On both systems the test suite fails like this.

Analysis

After some investigation I found, that this test fails as well (even if executed separately):

func TestMultipleContexts(t *testing.T) {
    _ = NewContext()
    _ = NewContext()
}

The first NewContext() call works just fine (and I get a working context in which JavaScript can be executed etc. But if I want to instantiate a second context it fails before the actual C++ constructor is being called.

It turns out that if I comment Line 118 in v8wrap.cc the error disappears.

class V8Context {
  // ...
  private:
    // ...
    //v8::HandleScope handle_scope_; 
    // ...
}

I tried to reason what this member variable is for, but it is never used and looking at the corresponding commit didn't help either. It seems though that the implicit initialization of this member variable is causing v8 to abort.

After commenting that line, I can now instantiate a second context. But the tests still fail. Differently, though:

  • OS X
-- FAIL: TestAddFunc (0.00 seconds)
v8_test.go:68:  Unexpected arg 0 type, expecting float64
        panic: interface conversion: interface is string, not float64 [recovered]
    panic: interface conversion: interface is string, not float64
  • Ubuntu
--- FAIL: TestAddFunc (0.00 seconds)
v8_test.go:63:  Unexpected arg 0 type, expecting float64
        unexpected fault address 0xfffffffffffffffb
throw: fault
[signal 0xb code=0x1 addr=0xfffffffffffffffb pc=0x7fb53be77693]

I hope, you can help me with this :)

Communication between VMs

Go-v8 is seemingly working great, but it seems to be missing features that would make it useful to real apps like adding functions to existing JS objects, or prototypes, or returning Go objects to JS or any way to give JS a type of application context.

If I want to use JS as a scripting language for things that really run in Go I need to create objects from JS but actually exist in Go. What is passed back to JS could be a pointer or a duplicate representation but I'm not understanding how I can do anything more than basic function calls with what is provided.

I would like to recreate some of the features that the browser has but I can't imagine how I would enable something like this.

var image = new Image()
image.onload = function(){
    console.log(image.width)
}
image.src = "path to image"

In this example the Image object would have to be something in Go. That object could be constructed and would have to be able to be modified like how the onload is added. The image.src is really a setter, that starts the load and the width is really only populated after the image is loaded.

Are there future plans for adding other types of interaction? Are there other projects in other languages that maybe I can help port over? Or maybe I am missing something and all of this is possible with what is already created and I am missing something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.