Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"github.com/buke/quickjs-go"
polyfill "github.com/flatlaughte/quickjs-go-polyfill"
)
func main() {
// Create a new runtime
rt := quickjs.NewRuntime()
defer rt.Close()
// Create a new context
ctx := rt.NewContext()
defer ctx.Close()
// Inject polyfills to the context
polyfill.InjectAll(ctx)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json; utf-8")
_, _ = w.Write([]byte(`{"status": true}`))
}))
ret, _ := ctx.Eval(fmt.Sprintf(`
setTimeout(() => {
fetch('%s', {Method: 'GET'}).then(response => response.json()).then(data => {
console.log(data.status);
});
}, 50);
`, srv.URL))
defer ret.Free()
ctx.Loop()
}
Output: true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var HQgbHI = zVrsFe()
View Source
var IHWVjC = tAApqp()
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.