Skip to content

Commit

Permalink
Intrdouce ObjectCall in v8go that sets recv as obj instead of undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Genevieve L'Esperance committed Aug 25, 2021
1 parent f6aa3b4 commit 0a2dbe9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 16 deletions.
40 changes: 28 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,35 @@ import (
)

func main() {
script, _ := ioutil.ReadFile("script.js")
iso, _ := v8go.NewIsolate() // creates a new JavaScript VM
ctx, _ := v8go.NewContext(iso)
val, _ := ctx.RunScript(string(script), "script.js")
respObj, _ := val.AsObject()
// bodyVal, _ := respObj.Get("body")
textVal, _ := respObj.Get("text")
textFn, _ := textVal.AsFunction()

// body, err := textFn.Call(bodyVal)
body, err := textFn.Call()
script, err := ioutil.ReadFile("script.js")
if err != nil {
panic(err)
}
fmt.Println(body)

iso, err := v8go.NewIsolate()
if err != nil {
panic(err)
}

ctx, err := v8go.NewContext(iso)
if err != nil {
panic(err)
}

val, err := ctx.RunScript(string(script), "script.js")
if err != nil {
panic(err)
}

respObj, err := val.AsObject()
if err != nil {
panic(err)
}

val, err = respObj.Call("text")
if err != nil {
panic(err)
}

fmt.Println(val.String())
}
5 changes: 1 addition & 4 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ class Response {
text() {
return this.body.toString();
}
// text(body) {
// return body.toString();
// }
}

new Response("this body");
new Response("Hello, World");
16 changes: 16 additions & 0 deletions vendor/rogchap.com/v8go/object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions vendor/rogchap.com/v8go/v8go.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/rogchap.com/v8go/v8go.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0a2dbe9

Please sign in to comment.