Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Go bindings for the javascriptcore library (used in Webkit).

branch: master
Octocat-spinner-32 examples Fix examples. November 03, 2013
Octocat-spinner-32 .gitignore Example code now runs correctly. October 26, 2013
Octocat-spinner-32 .hgignore Added a .hgignore to filter out all of the files generated by cgo. March 03, 2011
Octocat-spinner-32 .kateproject Add a kateproject. November 03, 2013
Octocat-spinner-32 .travis.yml Add Travis-CI support October 27, 2013
Octocat-spinner-32 README.md Update README.md January 05, 2014
Octocat-spinner-32 base.go Clean up and document base.go October 27, 2013
Octocat-spinner-32 base_test.go Move functions off *Context and onto *Value. November 03, 2013
Octocat-spinner-32 callback.c Tests are passing October 25, 2013
Octocat-spinner-32 callback.h Rewrite of support for reflectin native Go object's into JavaScript. … March 28, 2011
Octocat-spinner-32 context.go Tests are passing October 25, 2013
Octocat-spinner-32 context_test.go Move functions off *Context and onto *Value. November 03, 2013
Octocat-spinner-32 errors.go Move functions off *Context and onto *Value. November 03, 2013
Octocat-spinner-32 native.go Move functions off *Context and onto *Value. November 03, 2013
Octocat-spinner-32 native_test.go Move more onto *Object. November 03, 2013
Octocat-spinner-32 object.go Move more onto *Object. November 03, 2013
Octocat-spinner-32 object_test.go Move more onto *Object. November 03, 2013
Octocat-spinner-32 reflect.go Fix up and document Context.NewValue October 27, 2013
Octocat-spinner-32 reflect_test.go Move more onto *Object. November 03, 2013
Octocat-spinner-32 string.go Fix up Value and Object code; add conversion to Go value October 27, 2013
Octocat-spinner-32 string_test.go Fix up Value and Object code; add conversion to Go value October 27, 2013
Octocat-spinner-32 value.go Move more onto *Object. November 03, 2013
Octocat-spinner-32 value_test.go Move functions off *Context and onto *Value. November 03, 2013
README.md

Go JavaScript Bindings

Highly experiemental, I'm not even sure these work currently. Original author is Robery Johnstone, and his mercurial repository can be found at https://bitbucket.org/rj/golang-javascriptcore/. I have updated the bindings to work with the latest changes to the reflect API, bits of it manually. The entire test suite minus one function (finally!) passes.

Update (2013/10/16): The test suite does not work at all, but it compiles again with go 1.0. Feel free to hack away at this if you think it might be useful :).

Update (2013/12/26): Thanks to @sqs, the test suite now passes. This library should still be considered "experimental", but should work.

Install

go get github.com/crazy2be/gojs

Use:

package main

import (
    "github.com/crazy2be/gojs"
    "fmt"
)

func main() {
    ctx := gojs.NewContext()
    defer ctx.Release()

    ret, err := ctx.EvaluateScript("['hello', 'world'].join(' ')", nil, ".", 0)

    if err != nil {
        fmt.Println("Script had an error :(", ctx.ToStringOrDie(err))
        return
    }

    if ret == nil {
        fmt.Println("Nothing returned...")
        return
    }

    retstr := ctx.ToStringOrDie(ret)

    fmt.Println(retstr)
}

TODOs

(for anyone interested)

  1. Get the test suite to pass ;)
  2. Move as many functions as possible off of context. We should be able to make a nicely broken-down API where the conceptual weight is lower. For example, all of the functions that take obj *Object as the first parameter should really just be functions on *Object directly.
  3. ???
  4. PROFIT! (i.e. make something cool).

Documentation

There's not much documentation, because the original had no documentation. If I find a use for this beyond curiousity, I might add that as I go. Current documentation generated by godoc is available at http://godoc.org/github.com/crazy2be/gojs.

Something went wrong with that request. Please try again.