Skip to content

Commit

Permalink
[change] Integrate the new v8go api
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Dec 25, 2023
1 parent a24529d commit 4a381bb
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 892 deletions.
16 changes: 6 additions & 10 deletions api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,31 +217,27 @@ func (path Path) runStreamScript(ctx context.Context, c *gin.Context, getArgs fu
}
defer v8ctx.Close()

// make a new bridge function
ssEventT := v8go.NewFunctionTemplate(v8ctx.Isolate(), func(info *v8go.FunctionCallbackInfo) *v8go.Value {
v8ctx.WithFunction("ssEvent", func(info *v8go.FunctionCallbackInfo) *v8go.Value {
args := info.Args()
if len(args) != 2 {
return v8go.Null(v8ctx.Isolate())
return v8go.Null(info.Context().Isolate())
}

name := args[0].String()
message, err := bridge.GoValue(args[1], info.Context())
if err != nil {
return v8go.Null(v8ctx.Isolate())
return v8go.Null(info.Context().Isolate())
}

onEvent(name, message)
return v8go.Null(v8ctx.Isolate())
return v8go.Null(info.Context().Isolate())
})

cancelT := v8go.NewFunctionTemplate(v8ctx.Isolate(), func(info *v8go.FunctionCallbackInfo) *v8go.Value {
v8ctx.WithFunction("cancel", func(info *v8go.FunctionCallbackInfo) *v8go.Value {
onCancel()
return v8go.Null(v8ctx.Isolate())
return v8go.Null(info.Context().Isolate())
})

v8ctx.Global().Set("ssEvent", ssEventT.GetFunction(v8ctx.Context))
v8ctx.Global().Set("cancel", cancelT.GetFunction(v8ctx.Context))

args := getArgs(c)
_, err = v8ctx.CallWith(ctx, method, args...)
if err != nil {
Expand Down
269 changes: 0 additions & 269 deletions runtime/v8/benchmark_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion runtime/v8/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func ShareData(ctx *v8go.Context) (*Share, error) {

iso, ok := data["ISO"].(string) // Isolate ID
if !ok {
root = false
iso = ""
}

return &Share{
Expand Down
Loading

0 comments on commit 4a381bb

Please sign in to comment.