@@ -26,6 +26,7 @@ import (
26
26
"fmt"
27
27
"regexp"
28
28
"runtime"
29
+ "strconv"
29
30
"text/template"
30
31
"unsafe"
31
32
@@ -63,17 +64,18 @@ func (f V8Function) Call(args ...interface{}) (interface{}, error) {
63
64
})
64
65
arguments .WriteString ("(" + buf .String () + ")" )
65
66
} else {
66
- obj , ok := arg .(V8Object )
67
- if ok {
68
- // arg is a JavaScript object
67
+ if obj , ok := arg .(V8Object ); ok {
69
68
arguments .WriteString (obj .Name )
70
- } else {
71
- // arg is a Go object; marshal to JSON
72
- b , err := json .Marshal (arg )
73
- if err != nil {
74
- return nil , err
69
+ } else if num , ok := arg .(float64 ); ok {
70
+ arguments .WriteString (fmt .Sprintf ("%v" , num ))
71
+ } else if bln , ok := arg .(bool ); ok {
72
+ if bln {
73
+ arguments .WriteString ("true" )
74
+ } else {
75
+ arguments .WriteString ("false" )
75
76
}
76
- arguments .WriteString (string (b ))
77
+ } else if str , ok := arg .(string ); ok {
78
+ arguments .WriteString (str )
77
79
}
78
80
}
79
81
if i != len (args )- 1 {
@@ -108,6 +110,23 @@ func _go_v8_callback(contextId uint32, functionName *C.char, v8Objects *C.v8data
108
110
case C .v8function :
109
111
argv = append (argv , V8Function {ctx , C .GoString (obj .repr )})
110
112
break
113
+ case C .v8number :
114
+ if f , err := strconv .ParseFloat (C .GoString (obj .repr ), 64 ); err == nil {
115
+ argv = append (argv , f )
116
+ } else {
117
+ argv = append (argv , 0.0 )
118
+ }
119
+ break
120
+ case C .v8string :
121
+ argv = append (argv , C .GoString (obj .repr ))
122
+ break
123
+ case C .v8boolean :
124
+ if C .GoString (obj .repr ) == "true" {
125
+ argv = append (argv , true )
126
+ } else {
127
+ argv = append (argv , false )
128
+ }
129
+ break
111
130
default :
112
131
// Should be a JSON string, so pass it as-is
113
132
argv = append (argv , C .GoString (obj .repr ))
0 commit comments