-
Notifications
You must be signed in to change notification settings - Fork 1
/
module.go
89 lines (71 loc) · 1.51 KB
/
module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package gomini
import (
"github.com/go-errors/errors"
"path/filepath"
)
func newOrigin(filename string) Origin {
path := filepath.Dir(filename)
filename = filepath.Base(filename)
return &moduleOrigin{
path: path,
filename: filename,
}
}
type moduleOrigin struct {
path string
filename string
}
func (o *moduleOrigin) Filename() string {
return o.filename
}
func (o *moduleOrigin) Path() string {
return o.path
}
func (o *moduleOrigin) FullPath() string {
return filepath.Clean(filepath.Join(o.path, o.filename))
}
type module struct {
id string
name string
origin Origin
bundle Bundle
exports Object
kernel bool
}
func newModule(moduleId, name string, origin Origin, bundle Bundle) (*module, error) {
if moduleId == "" {
return nil, errors.New("illegal empty moduleId")
}
module := &module{
id: moduleId,
name: name,
origin: origin,
bundle: bundle,
exports: bundle.Sandbox().NewObject(),
}
return module, nil
}
func (m *module) ID() string {
return m.id
}
func (m *module) Name() string {
return m.name
}
func (m *module) Origin() Origin {
return m.origin
}
func (m *module) Bundle() Bundle {
return m.bundle
}
func (m *module) IsAccessible(caller Bundle) error {
return m.bundle.Sandbox().IsAccessible(m, caller)
}
func (m *module) getModuleExports() Object {
return m.exports
}
func (m *module) export(value Value, target interface{}) error {
return m.bundle.Sandbox().Export(value, target)
}
func (m *module) setName(name string) {
m.name = name
}