示例#1
0
func launch(mga *Agent) {
	js.Global.Set("agent", js.MakeWrapper(mga))

	if isBackgroundPage() {
		log.Printf("Starting agent")
		js.Global.Get("chrome").
			Get("runtime").
			Get("onConnectExternal").
			Call("addListener", func(port *js.Object) {
				p := NewAgentPort(port)
				go agent.ServeAgent(mga, p)
			})
	} else if isOptionsPage() {
		js.Global.Get("document").
			Call("addEventListener", "DOMContentLoaded", func() {
				go func() {
					textarea := js.Global.Get("document").
						Call("getElementById", "keys")
					textarea.Set("textContent", mga.PubKeys())
					textarea.Get("style").Set("height",
						textarea.Get("scrollHeight").String()+"px")
					textarea.Call("addEventListener", "click", func() {
						textarea.Call("focus")
						textarea.Call("select")
					})
				}()
			})
	}
}
示例#2
0
文件: main.go 项目: bcspragu/Gobots
func GetPlayback(base64Playback string) *js.Object {
	var p engine.Playback
	buf := bytes.NewReader([]byte(base64Playback))
	r := base64.NewDecoder(base64.StdEncoding, buf)
	gob.NewDecoder(r).Decode(&p)
	return js.MakeWrapper(&p)
}
示例#3
0
// Js creates a JS wrapper object for this promise that includes the 'then'
// method required by the Promises/A+ spec.
func (p *Promise) Js() *js.Object {
	o := js.MakeWrapper(p)
	o.Set("then", func(success, failure *js.Object) *js.Object {
		return p.Then(jsCallback(success), jsCallback(failure)).Js()
	})
	return o
}
示例#4
0
func GetReplay(url string) *js.Object {
	resp, _ := http.Get(url)
	defer resp.Body.Close()
	d, _ := ioutil.ReadAll(resp.Body)
	msg, _ := capnp.Unmarshal(d)
	r, _ := botapi.ReadRootReplay(msg)
	return js.MakeWrapper(engine.NewReplay(r))
}
示例#5
0
func TestMakeWrapper(t *testing.T) {
	m := &M{42}
	if !js.Global.Call("eval", `(function(m) { return m.Method({x: 1})["y"] === "z"; })`).Invoke(js.MakeWrapper(m)).Bool() {
		t.Fail()
	}

	if js.MakeWrapper(m).Interface() != m {
		t.Fail()
	}

	f := func(m *M) {
		if m.f != 42 {
			t.Fail()
		}
	}
	js.Global.Call("eval", `(function(f, m) { f(m); })`).Invoke(f, js.MakeWrapper(m))
}
示例#6
0
文件: main.go 项目: kevinherro/Exis
func (d *Domain) LinkDomain(name string) *js.Object {
	n := Domain{
		coreDomain: d.coreDomain.LinkDomain(name),
		app:        d.app,
	}

	n.wrapped = js.MakeWrapper(&n)
	return n.wrapped
}
示例#7
0
func main() {
	srv := NewServer()

	srv.RegisterModule(natural.Module)
	srv.RegisterModule(nlparser.Module)

	must(srv.EnableModule("natural"))
	must(srv.EnableModule("nlparser"))

	js.Global.Set("SarifServer", js.MakeWrapper(srv))
}
示例#8
0
func (s *Server) NewSocketConn() *js.Object {
	conn := s.Broker.NewLocalConn()

	sock := &Socket{conn: conn}
	sock.object = js.MakeWrapper(sock)
	sock.object.Set("send", sock.object.Get("Send"))
	sock.object.Set("readyState", 0)
	go sock.readLoop()

	return sock.object
}
示例#9
0
func validate(input *js.Object) *js.Object {
	data := js.Global.Get("JSON").Call("stringify", input).String()

	var obj interface{}
	if err := json.Unmarshal([]byte(data), &obj); err != nil {
		panic(err)
	}

	result := jsonapivalidator.Validate(obj)
	return js.MakeWrapper(newJSResult(result))
}
示例#10
0
func loginSaved(username, authData string, appkey string, cb *js.Object) {
	go func() {
		key, _ := base64.StdEncoding.DecodeString(appkey)
		data, _ := base64.StdEncoding.DecodeString(authData)
		conn, _ := MakeConn()
		sController, err := spotcontrol.LoginConnectionSaved(username, data, key, "spotcontrol", conn)
		if err != nil {
			cb.Invoke(nil, "", "login failed")
		}
		c := &controllerWrapper{controller: sController}
		cb.Invoke(js.MakeWrapper(c), authData, nil)
	}()
}
示例#11
0
func login(username, password, appkey string, cb *js.Object) {
	go func() {
		key, _ := base64.StdEncoding.DecodeString(appkey)
		conn, _ := MakeConn()
		sController, err := spotcontrol.LoginConnection(username, password, key, "spotcontrol", conn)
		if err != nil {
			cb.Invoke(nil, "", "login failed")
		} else {
			authData := sController.SavedCredentials
			c := &controllerWrapper{controller: sController}
			cb.Invoke(js.MakeWrapper(c), base64.StdEncoding.EncodeToString(authData), nil)
		}
	}()
}
示例#12
0
文件: main.go 项目: newgogo/Exis
func New(name string) *js.Object {
	core.ExternalGenerator = idGenerator{}

	a := &App{
		registrations: make(map[uint64]*js.Object),
		subscriptions: make(map[uint64]*js.Object),
	}

	d := Domain{
		coreDomain: core.NewDomain(name, nil),
		app:        a,
	}

	d.wrapped = js.MakeWrapper(&d)
	return d.wrapped
}
func init() {
	// Create a JavaScript wrapper function that the host can use to invoke the
	// HostInitialize function with a WKWebViewBridge
	js.Global.Set(
		"_GIBWKWebViewBridgeInitialize",
		func(message64 *js.Object) {
			// Get the messenger object
			// NOTE: For some reason, we can't get the postMessage method on
			// this object and use Invoke(...) on it directly, it just doesn't
			// work.  I don't know why, but for some reason doing
			// Call("postMessage", ...) does work.
			hostMessenger := js.Global.Get(
				"webkit",
			).Get(
				"messageHandlers",
			).Get(
				"_GIBWKWebViewBridgeMessageHandler",
			)

			// Create a new WKWebViewBridge
			bridge := &WKWebViewBridge{
				hostMessenger: hostMessenger,
				sequences:     newSequencer(),
			}

			// Create a wrapper for the host to interface with for sending
			// results
			js.Global.Set("_GIBWKWebViewBridge", js.MakeWrapper(bridge))

			// Decode the initialization message
			messageBytes, err := base64.StdEncoding.DecodeString(
				message64.String(),
			)
			if err != nil {
				panic("unable to decode initialization message")
			}

			// Call HostInitialize
			HostInitialize(bridge, string(messageBytes))
		},
	)
}
示例#14
0
func New() *js.Object {
	return js.MakeWrapper(&BibTeX{})
}
示例#15
0
func TestMakeWrapper(t *testing.T) {
	if !js.Global.Call("eval", `(function(m) { return m.Method({x: 1})["y"] === "z"; })`).Invoke(js.MakeWrapper(&M{42})).Bool() {
		t.Fail()
	}
}
示例#16
0
func (p *Playback) Board(i int) *js.Object {
	return js.MakeWrapper(p.Boards[i])
}
示例#17
0
文件: main.go 项目: aichaos/rsgb
func RiveScript() *js.Object {
	return js.MakeWrapper(rivescript.New())
}
示例#18
0
func New(name string) *js.Object {
	return js.MakeWrapper(&Pet{name})
}
示例#19
0
文件: main.go 项目: mdp/bluemonday-js
func UGCPolicy(name string) *js.Object {
	return js.MakeWrapper(bluemonday.UGCPolicy())
}
示例#20
0
func GetReplayFromString(replayString string) *js.Object {
	// Will it work? It's not Unicode clean
	msg, _ := capnp.Unmarshal([]byte(replayString))
	r, _ := botapi.ReadRootReplay(msg)
	return js.MakeWrapper(engine.NewReplay(r))
}