nextFuncID uint32 = 1
)
-var _ Wrapper = Func{} // Func must implement Wrapper
-
// Func is a wrapped Go function to be called by JavaScript.
type Func struct {
Value // the JavaScript function that invokes the Go function
// 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
-// 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".
// Values can be checked for equality with the Equal method.
type Value struct {
typeFlagFunction
)
-// JSValue implements Wrapper interface.
-func (v Value) JSValue() Value {
- return v
-}
-
func makeValue(r ref) Value {
var gcPtr *ref
typeFlag := (r >> 32) & 7
// Panics if x is not one of the expected types.
func ValueOf(x interface{}) Value {
switch x := x.(type) {
- case Value: // should precede Wrapper to avoid a loop
+ case Value:
return x
- case Wrapper:
- return x.JSValue()
+ case Func:
+ return x.Value
case nil:
return valueNull
case bool: