rogchap / v8go

Execute JavaScript from Go
https://rogchap.com/v8go
BSD 3-Clause "New" or "Revised" License
3.22k stars 221 forks source link

v8.Value becomes manually releaseable #361

Closed fizx closed 1 year ago

fizx commented 1 year ago

This allows long-lived contexts that call go functions without leaking memory. Typically, you'd want to use the following pattern for go functions that don't allow values to escape.

printfn := v8.NewFunctionTemplate(iso, func(info *v8.FunctionCallbackInfo) *v8.Value {
    defer info.Release()
    fmt.Printf("%+v\n", info.Args())
    return nil
})
codecov[bot] commented 1 year ago

Codecov Report

Base: 95.23% // Head: 95.28% // Increases project coverage by +0.04% :tada:

Coverage data is based on head (fbe0f6e) compared to base (1f00b50). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #361 +/- ## ========================================== + Coverage 95.23% 95.28% +0.04% ========================================== Files 17 17 Lines 588 594 +6 ========================================== + Hits 560 566 +6 Misses 19 19 Partials 9 9 ``` | [Impacted Files](https://codecov.io/gh/rogchap/v8go/pull/361?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | | |---|---|---| | [context.go](https://codecov.io/gh/rogchap/v8go/pull/361?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29udGV4dC5nbw==) | `100.00% <100.00%> (ø)` | | | [function\_template.go](https://codecov.io/gh/rogchap/v8go/pull/361?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-ZnVuY3Rpb25fdGVtcGxhdGUuZ28=) | `94.11% <100.00%> (+0.36%)` | :arrow_up: | | [value.go](https://codecov.io/gh/rogchap/v8go/pull/361?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-dmFsdWUuZ28=) | `94.85% <100.00%> (+0.02%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.