當前位置: 首頁>>代碼示例>>Golang>>正文


Golang js.MakeWrapper函數代碼示例

本文整理匯總了Golang中github.com/gopherjs/gopherjs/js.MakeWrapper函數的典型用法代碼示例。如果您正苦於以下問題:Golang MakeWrapper函數的具體用法?Golang MakeWrapper怎麽用?Golang MakeWrapper使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MakeWrapper函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: launch

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")
					})
				}()
			})
	}
}
開發者ID:kamronbatman,項目名稱:macgyver,代碼行數:29,代碼來源:main.go

示例2: GetPlayback

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)
}
開發者ID:bcspragu,項目名稱:Gobots,代碼行數:7,代碼來源:main.go

示例3: Js

// 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
}
開發者ID:augustoroman,項目名稱:promise,代碼行數:9,代碼來源:promisify.go

示例4: GetReplay

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))
}
開發者ID:gophergala2016,項目名稱:Gobots,代碼行數:8,代碼來源:main.go

示例5: TestMakeWrapper

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))
}
開發者ID:apihooks,項目名稱:aredis,代碼行數:17,代碼來源:js_test.go

示例6: LinkDomain

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
}
開發者ID:kevinherro,項目名稱:Exis,代碼行數:9,代碼來源:main.go

示例7: main

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))
}
開發者ID:sarifsystems,項目名稱:sarif,代碼行數:11,代碼來源:main.go

示例8: NewSocketConn

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
}
開發者ID:sarifsystems,項目名稱:sarif,代碼行數:11,代碼來源:server.go

示例9: validate

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))
}
開發者ID:aren55555,項目名稱:corroborate,代碼行數:11,代碼來源:main.go

示例10: loginSaved

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)
	}()
}
開發者ID:badfortrains,項目名稱:spotcontrol,代碼行數:13,代碼來源:main.go

示例11: login

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)
		}
	}()
}
開發者ID:badfortrains,項目名稱:spotcontrol,代碼行數:14,代碼來源:main.go

示例12: New

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
}
開發者ID:newgogo,項目名稱:Exis,代碼行數:16,代碼來源:main.go

示例13: init

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))
		},
	)
}
開發者ID:havoc-io,項目名稱:gopherjsipcbridge,代碼行數:42,代碼來源:bridge_wkwebview_js.go

示例14: New

func New() *js.Object {
	return js.MakeWrapper(&BibTeX{})
}
開發者ID:caltechlibrary,項目名稱:bibtex,代碼行數:3,代碼來源:webapp.go

示例15: TestMakeWrapper

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()
	}
}
開發者ID:flimzy,項目名稱:gopherjs,代碼行數:5,代碼來源:js_test.go


注:本文中的github.com/gopherjs/gopherjs/js.MakeWrapper函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。