@@ -25,7 +25,7 @@ func init() {
2525 used (structType {})
2626}
2727
28- // TODO(grantnelson-wf): After this is in the go1.21 branch, remove it, this is just to minimize diffs .
28+ // TODO(grantnelson-wf): This is just to minimize diffs. After this is merged into the go1.21 branch, remove it.
2929func jsType (typ * abi.Type ) * js.Object {
3030 return typ .JsType ()
3131}
@@ -40,11 +40,6 @@ func jsPtrTo(t Type) *js.Object {
4040 return toAbiType (t ).JsPtrTo ()
4141}
4242
43- // TODO(grantnelson-wf): After this is in the go1.21 branch, remove it, this is just to minimize diffs.
44- func reflectType (typ * js.Object ) rtype {
45- return toRType (abi .ReflectType (typ ))
46- }
47-
4843//gopherjs:purge The name type is mostly unused, replaced by abi.Name, except in pkgPath which we don't implement.
4944type name struct {
5045 bytes * byte
@@ -69,40 +64,29 @@ func (t rtype) typeOff(off typeOff) *abi.Type {
6964 return t .TypeOff (off )
7065}
7166
72- // TODO(grantnelson-wf): After this is in the go1.21 branch, remove it, this is just to minimize diffs.
73- func isWrapped (typ * abi.Type ) bool {
74- return typ .IsWrapped ()
75- }
76-
77- // TODO(grantnelson-wf): After this is in the go1.21 branch, remove it, this is just to minimize diffs.
78- func copyStruct (dst , src * js.Object , typ * abi.Type ) {
79- abi .CopyStruct (dst , src , typ )
80- }
81-
8267//gopherjs:new
83- func makeValue (t Type , v * js.Object , fl flag ) Value {
84- rt := t .common ()
68+ func makeValue (t * abi.Type , v * js.Object , fl flag ) Value {
8569 switch t .Kind () {
8670 case abi .Array , abi .Struct , abi .Pointer :
87- return Value {rt , unsafe .Pointer (v .Unsafe ()), fl | flag (t .Kind ())}
71+ return Value {t , unsafe .Pointer (v .Unsafe ()), fl | flag (t .Kind ())}
8872 }
89- return Value {rt , unsafe .Pointer (js .Global .Call ("$newDataPointer" , v , rt .JsPtrTo ()).Unsafe ()), fl | flag (t .Kind ()) | flagIndir }
73+ return Value {t , unsafe .Pointer (js .Global .Call ("$newDataPointer" , v , t .JsPtrTo ()).Unsafe ()), fl | flag (t .Kind ()) | flagIndir }
9074}
9175
9276//gopherjs:replace
9377func TypeOf (i any ) Type {
9478 if i == nil {
9579 return nil
9680 }
97- return reflectType ( js .InternalObject (i ).Get ("constructor" ))
81+ return toRType ( abi . ReflectType ( js .InternalObject (i ).Get ("constructor" ) ))
9882}
9983
10084//gopherjs:replace
10185func ValueOf (i any ) Value {
10286 if i == nil {
10387 return Value {}
10488 }
105- return makeValue (reflectType (js .InternalObject (i ).Get ("constructor" )), js .InternalObject (i ).Get ("$val" ), 0 )
89+ return makeValue (abi . ReflectType (js .InternalObject (i ).Get ("constructor" )), js .InternalObject (i ).Get ("$val" ), 0 )
10690}
10791
10892//gopherjs:replace
@@ -140,7 +124,7 @@ func methodReceiver(op string, v Value, i int) (fn unsafe.Pointer) {
140124 prop = js .Global .Call ("$methodSet" , jsType (v .typ )).Index (i ).Get ("prop" ).String ()
141125 }
142126 rcvr := v .object ()
143- if isWrapped ( v .typ ) {
127+ if v .typ . IsWrapped ( ) {
144128 rcvr = jsType (v .typ ).New (rcvr )
145129 }
146130 fn = unsafe .Pointer (rcvr .Get (prop ).Unsafe ())
@@ -157,10 +141,10 @@ func valueInterface(v Value) any {
157141 v = makeMethodValue ("Interface" , v )
158142 }
159143
160- if isWrapped ( v .typ ) {
144+ if v .typ . IsWrapped ( ) {
161145 if v .flag & flagIndir != 0 && v .Kind () == abi .Struct {
162146 cv := jsType (v .typ ).Call ("zero" )
163- copyStruct (cv , v .object (), v .typ )
147+ abi . CopyStruct (cv , v .object (), v .typ )
164148 return any (unsafe .Pointer (jsType (v .typ ).New (cv ).Unsafe ()))
165149 }
166150 return any (unsafe .Pointer (jsType (v .typ ).New (v .object ()).Unsafe ()))
@@ -173,10 +157,12 @@ func ifaceE2I(t *abi.Type, src any, dst unsafe.Pointer) {
173157 abi .IfaceE2I (t , src , dst )
174158}
175159
160+ // TODO(grantnelson-wf): methodName returns the name of the calling method,
161+ // assumed to be two stack frames above. Determine if we can get this value now
162+ // and if methodName is needed
163+ //
176164//gopherjs:replace
177165func methodName () string {
178- // TODO(grantnelson-wf): methodName returns the name of the calling method,
179- // assumed to be two stack frames above.
180166 return "?FIXME?"
181167}
182168
@@ -188,7 +174,7 @@ func makeMethodValue(op string, v Value) Value {
188174
189175 fn := methodReceiver (op , v , int (v .flag )>> flagMethodShift )
190176 rcvr := v .object ()
191- if isWrapped ( v .typ ) {
177+ if v .typ . IsWrapped ( ) {
192178 rcvr = jsType (v .typ ).New (rcvr )
193179 }
194180 fv := js .MakeFunc (func (this * js.Object , arguments []* js.Object ) any {
0 commit comments