...
1 package playwright
2
3 import (
4 "sync"
5 )
6
7 type channelOwner struct {
8 sync.RWMutex
9 eventEmitter
10 objectType string
11 guid string
12 channel *channel
13 objects map[string]*channelOwner
14 connection *connection
15 initializer map[string]interface{}
16 parent *channelOwner
17 }
18
19 func (c *channelOwner) dispose() {
20
21 if c.parent != nil {
22 delete(c.parent.objects, c.guid)
23 }
24 delete(c.connection.objects, c.guid)
25
26
27 for _, object := range c.objects {
28 object.dispose()
29 }
30 c.objects = make(map[string]*channelOwner)
31 }
32
33 func (c *channelOwner) createChannelOwner(self interface{}, parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) {
34 c.objectType = objectType
35 c.guid = guid
36 c.parent = parent
37 c.objects = make(map[string]*channelOwner)
38 c.initializer = initializer
39 if c.parent != nil {
40 c.connection = parent.connection
41 c.parent.objects[guid] = c
42 }
43 if c.connection != nil {
44 c.connection.objects[guid] = c
45 }
46 c.channel = newChannel(c.connection, guid)
47 c.channel.object = self
48 c.initEventEmitter()
49 }
50
51 type rootChannelOwner struct {
52 channelOwner
53 }
54
55 func (r *rootChannelOwner) initialize() (*Playwright, error) {
56 result, err := r.channel.Send("initialize", map[string]interface{}{
57 "sdkLanguage": "javascript",
58 })
59 if err != nil {
60 return nil, err
61 }
62 return fromChannel(result).(*Playwright), nil
63 }
64
65 func newRootChannelOwner(connection *connection) *rootChannelOwner {
66 c := &rootChannelOwner{}
67 c.connection = connection
68 c.createChannelOwner(c, nil, "Root", "", make(map[string]interface{}))
69 return c
70 }
71
View as plain text