MCPcopy
hub / github.com/gopherjs/gopherjs / MakeWrapper

Function MakeWrapper

js/js.go:139–154  ·  view source on GitHub ↗

MakeWrapper creates a JavaScript object which has wrappers for the exported methods of i. Use explicit getter and setter methods to expose struct fields to JavaScript.

(i any)

Source from the content-addressed store, hash-verified

137
138// MakeWrapper creates a JavaScript object which has wrappers for the exported methods of i. Use explicit getter and setter methods to expose struct fields to JavaScript.
139func MakeWrapper(i any) *Object {
140 v := InternalObject(i)
141 o := Global.Get("Object").New()
142 o.Set("__internal_object__", v)
143 methods := v.Get("constructor").Get("methods")
144 for i := 0; i < methods.Length(); i++ {
145 m := methods.Index(i)
146 if m.Get("pkg").String() != "" { // not exported
147 continue
148 }
149 o.Set(m.Get("name").String(), func(args ...*Object) *Object {
150 return Global.Call("$externalizeFunction", v.Get(m.Get("prop").String()), m.Get("typ"), true).Call("apply", v, args)
151 })
152 }
153 return o
154}
155
156// MakeFullWrapper creates a JavaScript object which has wrappers for the exported
157// methods of i, and, where i is a (pointer to a) struct value, wrapped getters

Callers 1

TestMakeWrapperFunction · 0.92

Calls 8

InternalObjectFunction · 0.85
GetMethod · 0.65
IndexMethod · 0.65
StringMethod · 0.65
NewMethod · 0.45
SetMethod · 0.45
LengthMethod · 0.45
CallMethod · 0.45

Tested by 1

TestMakeWrapperFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…