diff --git a/runtime/v8/bridge/bridge.go b/runtime/v8/bridge/bridge.go index 6f4430d3..3aadbc2f 100644 --- a/runtime/v8/bridge/bridge.go +++ b/runtime/v8/bridge/bridge.go @@ -2,8 +2,10 @@ package bridge import ( "fmt" + "io" "math/big" + "github.com/gin-gonic/gin" jsoniter "github.com/json-iterator/go" "github.com/yaoapp/kun/exception" "rogchap.com/v8go" @@ -155,6 +157,12 @@ func GoValues(jsValues []*v8go.Value, ctx *v8go.Context) ([]interface{}, error) // * | ✅ | struct | object | // * | ✅ | bridge.PromiseT | object(Promise) | // * | ✅ | bridge.FunctionT | function | +// * | ✅ | io.Writer | object(external) | +// * | ✅ | io.Reader | object(external) | +// * | ✅ | io.ReadCloser | object(external) | +// * | ✅ | io.WriteCloser | object(external) | +// * | ✅ | *gin.Context | object(external) | +// * | ✅ | *gin.ResponseWriter | object(external) | // * |----------------------------------------------------------- func JsValue(ctx *v8go.Context, value interface{}) (*v8go.Value, error) { @@ -219,6 +227,10 @@ func JsValue(ctx *v8go.Context, value interface{}) (*v8go.Value, error) { case UndefinedT: return v8go.Undefined(ctx.Isolate()), nil + // For io stream + case io.Writer, io.Reader, io.ReadCloser, io.WriteCloser, gin.ResponseWriter, *gin.Context: + return v8go.NewExternal(ctx.Isolate(), v) + default: return jsValueParse(ctx, v) } @@ -258,6 +270,7 @@ func jsValueParse(ctx *v8go.Context, value interface{}) (*v8go.Value, error) { // * | ✅ | array | []interface{} | // * | ✅ | object(Promise) | bridge.PromiseT | // * | ✅ | function | bridge.FunctionT | +// * | ✅ | object(external) | interface{} | // * |----------------------------------------------------------- func GoValue(value *v8go.Value, ctx *v8go.Context) (interface{}, error) { diff --git a/runtime/v8/functions/process/process.go b/runtime/v8/functions/process/process.go index 95b2a8de..6966c5f9 100644 --- a/runtime/v8/functions/process/process.go +++ b/runtime/v8/functions/process/process.go @@ -30,9 +30,12 @@ func exec(info *v8go.FunctionCallbackInfo) *v8go.Value { goArgs := []interface{}{} if len(jsArgs) > 1 { - goArgs, err = bridge.GoValues(jsArgs[1:], info.Context()) - if err != nil { - return bridge.JsException(info.Context(), err) + for _, arg := range jsArgs[1:] { + v, err := bridge.GoValue(arg, info.Context()) + if err != nil { + return bridge.JsException(info.Context(), err) + } + goArgs = append(goArgs, v) } }