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)
| 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. |
| 139 | func 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 |
searching dependent graphs…