mirror of
https://github.com/golang/go
synced 2024-11-24 07:40:17 -07:00
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 <neelance@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
This commit is contained in:
parent
267abbe3ba
commit
6c0daa7331
@ -15,8 +15,6 @@ var (
|
|||||||
nextFuncID uint32 = 1
|
nextFuncID uint32 = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Wrapper = Func{} // Func must implement Wrapper
|
|
||||||
|
|
||||||
// Func is a wrapped Go function to be called by JavaScript.
|
// Func is a wrapped Go function to be called by JavaScript.
|
||||||
type Func struct {
|
type Func struct {
|
||||||
Value // the JavaScript function that invokes the Go function
|
Value // the JavaScript function that invokes the Go function
|
||||||
|
@ -28,12 +28,6 @@ type ref uint64
|
|||||||
// 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).
|
// 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).
|
||||||
const nanHead = 0x7FF80000
|
const nanHead = 0x7FF80000
|
||||||
|
|
||||||
// Wrapper is implemented by types that are backed by a JavaScript value.
|
|
||||||
type Wrapper interface {
|
|
||||||
// JSValue returns a JavaScript value associated with an object.
|
|
||||||
JSValue() Value
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value represents a JavaScript value. The zero value is the JavaScript value "undefined".
|
// Value represents a JavaScript value. The zero value is the JavaScript value "undefined".
|
||||||
// Values can be checked for equality with the Equal method.
|
// Values can be checked for equality with the Equal method.
|
||||||
type Value struct {
|
type Value struct {
|
||||||
@ -51,11 +45,6 @@ const (
|
|||||||
typeFlagFunction
|
typeFlagFunction
|
||||||
)
|
)
|
||||||
|
|
||||||
// JSValue implements Wrapper interface.
|
|
||||||
func (v Value) JSValue() Value {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeValue(r ref) Value {
|
func makeValue(r ref) Value {
|
||||||
var gcPtr *ref
|
var gcPtr *ref
|
||||||
typeFlag := (r >> 32) & 7
|
typeFlag := (r >> 32) & 7
|
||||||
@ -162,10 +151,10 @@ func Global() Value {
|
|||||||
// Panics if x is not one of the expected types.
|
// Panics if x is not one of the expected types.
|
||||||
func ValueOf(x interface{}) Value {
|
func ValueOf(x interface{}) Value {
|
||||||
switch x := x.(type) {
|
switch x := x.(type) {
|
||||||
case Value: // should precede Wrapper to avoid a loop
|
case Value:
|
||||||
return x
|
return x
|
||||||
case Wrapper:
|
case Func:
|
||||||
return x.JSValue()
|
return x.Value
|
||||||
case nil:
|
case nil:
|
||||||
return valueNull
|
return valueNull
|
||||||
case bool:
|
case bool:
|
||||||
|
Loading…
Reference in New Issue
Block a user