本文整理汇总了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")
})
}()
})
}
}
示例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)
}
示例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
}
示例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))
}
示例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))
}
示例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
}
示例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))
}
示例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
}
示例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))
}
示例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)
}()
}
示例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)
}
}()
}
示例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
}
示例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))
},
)
}
示例14: New
func New() *js.Object {
return js.MakeWrapper(&BibTeX{})
}
示例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()
}
}