Skip to content

Commit 6c0daa7

Browse files
neelanceRichard Musiol
authored and
Richard Musiol
committed
syscall/js: remove Wrapper interface
This change removes the js.Wrapper interface for performance reasons. See proposal #44006 for details. This is a breaking change, but syscall/js is exempt from Go's compatibility promise. Fixes #44006 Change-Id: I968cd14b1e61cc72ea9f84240b6bd29e8b8ae673 Reviewed-on: https://go-review.googlesource.com/c/go/+/356430 Trust: Richard Musiol <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]>
1 parent 267abbe commit 6c0daa7

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

src/syscall/js/func.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ var (
1515
nextFuncID uint32 = 1
1616
)
1717

18-
var _ Wrapper = Func{} // Func must implement Wrapper
19-
2018
// Func is a wrapped Go function to be called by JavaScript.
2119
type Func struct {
2220
Value // the JavaScript function that invokes the Go function

src/syscall/js/js.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ type ref uint64
2828
// nanHead are the upper 32 bits of a ref which are set if the value is not encoded as an IEEE 754 number (see above).
2929
const nanHead = 0x7FF80000
3030

31-
// Wrapper is implemented by types that are backed by a JavaScript value.
32-
type Wrapper interface {
33-
// JSValue returns a JavaScript value associated with an object.
34-
JSValue() Value
35-
}
36-
3731
// Value represents a JavaScript value. The zero value is the JavaScript value "undefined".
3832
// Values can be checked for equality with the Equal method.
3933
type Value struct {
@@ -51,11 +45,6 @@ const (
5145
typeFlagFunction
5246
)
5347

54-
// JSValue implements Wrapper interface.
55-
func (v Value) JSValue() Value {
56-
return v
57-
}
58-
5948
func makeValue(r ref) Value {
6049
var gcPtr *ref
6150
typeFlag := (r >> 32) & 7
@@ -162,10 +151,10 @@ func Global() Value {
162151
// Panics if x is not one of the expected types.
163152
func ValueOf(x interface{}) Value {
164153
switch x := x.(type) {
165-
case Value: // should precede Wrapper to avoid a loop
154+
case Value:
166155
return x
167-
case Wrapper:
168-
return x.JSValue()
156+
case Func:
157+
return x.Value
169158
case nil:
170159
return valueNull
171160
case bool:

0 commit comments

Comments
 (0)