Skip to content

Commit

Permalink
Merge pull request #10 from gopherjs/scalar
Browse files Browse the repository at this point in the history
Ensure that js-tagged fields are scalars
  • Loading branch information
flimzy authored Aug 4, 2023
2 parents ddd73a1 + 96e63c3 commit 034497c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions analysis/passes/embedjsobject/embedjsobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
if _, ok := reflect.StructTag(tv).Lookup("js"); !ok {
return true
}
switch field.Type.(type) {
case *ast.ArrayType, *ast.MapType, *ast.FuncType, *ast.ChanType, *ast.StructType:
pass.Reportf(field.Pos(), "non-scalar types not permitted in structs that embed js.Object")
}
fieldList := findFieldList(stack)
for i, field := range fieldList.List {
if len(field.Names) > 0 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package directjsobject

import (
"github.com/gopherjs/gopherjs/js"
)

type _ struct {
*js.Object
Slice []int `js:"slice"` // want "non-scalar types not permitted in structs that embed js.Object"
Array [10]int `js:"array"` // want "non-scalar types not permitted in structs that embed js.Object"
Map map[int]int `js:"map"` // want "non-scalar types not permitted in structs that embed js.Object"
Func func() `js:"func"` // want "non-scalar types not permitted in structs that embed js.Object"
Chan chan int `js:"chan"` // want "non-scalar types not permitted in structs that embed js.Object"
Struct struct{} `js:"struct"` // want "non-scalar types not permitted in structs that embed js.Object"
}

0 comments on commit 034497c

Please sign in to comment.