• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang js.MakeWrapper函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/gopherjs/gopherjs/js.MakeWrapper函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeWrapper函数的具体用法?Golang MakeWrapper怎么用?Golang MakeWrapper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MakeWrapper函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Board

func (p *Playback) Board(i int) *js.Object {
	return js.MakeWrapper(p.Boards[i])
}
开发者ID:bcspragu,项目名称:Gobots,代码行数:3,代码来源:replayer.go


示例17: RiveScript

func RiveScript() *js.Object {
	return js.MakeWrapper(rivescript.New())
}
开发者ID:aichaos,项目名称:rsgb,代码行数:3,代码来源:main.go


示例18: New

func New(name string) *js.Object {
	return js.MakeWrapper(&Pet{name})
}
开发者ID:lukevers,项目名称:gulp-gopherjs,代码行数:3,代码来源:gopherjs.go


示例19: UGCPolicy

func UGCPolicy(name string) *js.Object {
	return js.MakeWrapper(bluemonday.UGCPolicy())
}
开发者ID:mdp,项目名称:bluemonday-js,代码行数:3,代码来源:main.go


示例20: GetReplayFromString

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))
}
开发者ID:gophergala2016,项目名称:Gobots,代码行数:6,代码来源:main.go



注:本文中的github.com/gopherjs/gopherjs/js.MakeWrapper函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang js.Object类代码示例发布时间:2022-05-23
下一篇:
Golang js.InternalObject函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap