Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96e63c3

Browse files
committed
Ensure that js-tagged fields are scalars
1 parent ddd73a1 commit 96e63c3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

analysis/passes/embedjsobject/embedjsobject.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
3939
if _, ok := reflect.StructTag(tv).Lookup("js"); !ok {
4040
return true
4141
}
42+
switch field.Type.(type) {
43+
case *ast.ArrayType, *ast.MapType, *ast.FuncType, *ast.ChanType, *ast.StructType:
44+
pass.Reportf(field.Pos(), "non-scalar types not permitted in structs that embed js.Object")
45+
}
4246
fieldList := findFieldList(stack)
4347
for i, field := range fieldList.List {
4448
if len(field.Names) > 0 {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package directjsobject
2+
3+
import (
4+
"github.com/gopherjs/gopherjs/js"
5+
)
6+
7+
type _ struct {
8+
*js.Object
9+
Slice []int `js:"slice"` // want "non-scalar types not permitted in structs that embed js.Object"
10+
Array [10]int `js:"array"` // want "non-scalar types not permitted in structs that embed js.Object"
11+
Map map[int]int `js:"map"` // want "non-scalar types not permitted in structs that embed js.Object"
12+
Func func() `js:"func"` // want "non-scalar types not permitted in structs that embed js.Object"
13+
Chan chan int `js:"chan"` // want "non-scalar types not permitted in structs that embed js.Object"
14+
Struct struct{} `js:"struct"` // want "non-scalar types not permitted in structs that embed js.Object"
15+
}

0 commit comments

Comments
 (0)