diff --git a/internal/entity/file_js_wasm.go b/internal/entity/file_js_wasm.go index ec8c66fee6..1ec38f8973 100644 --- a/internal/entity/file_js_wasm.go +++ b/internal/entity/file_js_wasm.go @@ -2,14 +2,10 @@ package entity -import ( - "syscall/js" -) - -func (f *File) MarshalJavaScript() js.Value { - return js.ValueOf(map[string]any{ +func (f *File) MarshalJavaScript() any { + return map[string]any{ "file_path": f.FilePath, "size": f.FullSize(), "pcln_size": f.PclnSize(), - }) + } } diff --git a/internal/entity/package_js_wasm.go b/internal/entity/package_js_wasm.go index 5c19c3870e..2ae044251c 100644 --- a/internal/entity/package_js_wasm.go +++ b/internal/entity/package_js_wasm.go @@ -3,32 +3,30 @@ package entity import ( - "syscall/js" - "github.com/samber/lo" ) -func (m PackageMap) MarshalJavaScript() js.Value { +func (m PackageMap) MarshalJavaScript() any { ret := map[string]any{} for k, v := range m { ret[k] = v.MarshalJavaScript() } - return js.ValueOf(ret) + return ret } -func (p *Package) MarshalJavaScript() js.Value { +func (p *Package) MarshalJavaScript() any { var symbols, files []any symbols = lo.Map(p.Symbols, func(s *Symbol, _ int) any { return s.MarshalJavaScript() }) files = lo.Map(p.Files, func(f *File, _ int) any { return f.MarshalJavaScript() }) - return js.ValueOf(map[string]any{ + return map[string]any{ "name": p.Name, "type": p.Type, "size": p.Size, "symbols": symbols, "subPackages": p.SubPackages.MarshalJavaScript(), "files": files, - }) + } } diff --git a/internal/entity/section_js_wasm.go b/internal/entity/section_js_wasm.go index 4ec3c40546..b09f22c6e9 100644 --- a/internal/entity/section_js_wasm.go +++ b/internal/entity/section_js_wasm.go @@ -2,12 +2,8 @@ package entity -import ( - "syscall/js" -) - -func (s Section) MarshalJavaScript() js.Value { - return js.ValueOf(map[string]any{ +func (s Section) MarshalJavaScript() any { + return map[string]any{ "name": s.Name, "size": s.Size, "file_size": s.FileSize, @@ -18,5 +14,5 @@ func (s Section) MarshalJavaScript() js.Value { "addr_end": s.AddrEnd, "only_in_memory": s.OnlyInMemory, "debug": s.Debug, - }) + } } diff --git a/internal/entity/symbol_js_wasm.go b/internal/entity/symbol_js_wasm.go index a73ce433bc..888e5a3b01 100644 --- a/internal/entity/symbol_js_wasm.go +++ b/internal/entity/symbol_js_wasm.go @@ -2,15 +2,11 @@ package entity -import ( - "syscall/js" -) - -func (s *Symbol) MarshalJavaScript() js.Value { - return js.ValueOf(map[string]any{ +func (s *Symbol) MarshalJavaScript() any { + return map[string]any{ "name": s.Name, "addr": s.Addr, "size": s.Size, "type": s.Type, - }) + } } diff --git a/internal/printer/wasm/obj_js_wasm.go b/internal/printer/wasm/obj_js_wasm.go index 54cda397a2..223e58652a 100644 --- a/internal/printer/wasm/obj_js_wasm.go +++ b/internal/printer/wasm/obj_js_wasm.go @@ -9,5 +9,7 @@ import ( ) func JavaScript(r *result.Result) js.Value { - return r.MarshalJavaScript() + ret := r.MarshalJavaScript() + + return js.ValueOf(ret) } diff --git a/internal/result/result_js_wasm.go b/internal/result/result_js_wasm.go index 6cbd7654b5..1f1213db78 100644 --- a/internal/result/result_js_wasm.go +++ b/internal/result/result_js_wasm.go @@ -3,23 +3,21 @@ package result import ( - "syscall/js" - "github.com/samber/lo" "github.com/Zxilly/go-size-analyzer/internal/entity" ) -func (r *Result) MarshalJavaScript() js.Value { +func (r *Result) MarshalJavaScript() any { var sections []any sections = lo.Map(r.Sections, func(s *entity.Section, _ int) any { return s.MarshalJavaScript() }) - return js.ValueOf(map[string]any{ + return map[string]any{ "name": r.Name, "size": r.Size, "packages": r.Packages.MarshalJavaScript(), "sections": sections, - }) + } } diff --git a/internal/result/result_js_wasm_test.go b/internal/result/result_js_wasm_test.go index 0047227b2c..be10be8af1 100644 --- a/internal/result/result_js_wasm_test.go +++ b/internal/result/result_js_wasm_test.go @@ -34,8 +34,7 @@ func TestResultMarshalJavaScript(t *testing.T) { // use JSON.stringify to compare the result JSON := js.Global().Get("JSON") - stringify := JSON.Get("stringify") - jsonValue := stringify.Invoke(jsValue).String() + jsonValue := JSON.Call("stringify", jsValue).String() assert.JSONEq(t, testdataJSON, jsonValue) }