Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several leaks in tests #225

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestContextExec(t *testing.T) {

iso := ctx.Isolate()
ctx2 := v8.NewContext(iso)
defer ctx2.Close()
_, err = ctx2.RunScript(`add`, "ctx2.js")
if err == nil {
t.Error("error expected but was <nil>")
Expand Down
2 changes: 2 additions & 0 deletions function_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestFunctionCallbackInfoThis(t *testing.T) {
t.Parallel()

iso := v8.NewIsolate()
defer iso.Dispose()

foo := v8.NewObjectTemplate(iso)
foo.Set("name", "foobar")
Expand All @@ -102,6 +103,7 @@ func TestFunctionCallbackInfoThis(t *testing.T) {
global.Set("foo", foo)

ctx := v8.NewContext(iso, global)
defer ctx.Close()
ctx.RunScript("foo.bar()", "")

v, _ := this.Get("name")
Expand Down
6 changes: 4 additions & 2 deletions function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ func TestFunctionCall(t *testing.T) {
t.Parallel()

ctx := v8.NewContext()
defer ctx.Isolate().Dispose()
iso := ctx.Isolate()
defer iso.Dispose()
defer ctx.Close()

_, err := ctx.RunScript("function add(a, b) { return a + b; }", "")
fatalIf(t, err)
addValue, err := ctx.Global().Get("add")
fatalIf(t, err)
iso := ctx.Isolate()

arg1, err := v8.NewValue(iso, int32(1))
fatalIf(t, err)
Expand Down Expand Up @@ -73,9 +73,11 @@ func TestFunctionCallWithObjectReceiver(t *testing.T) {
t.Parallel()

iso := v8.NewIsolate()
defer iso.Dispose()
global := v8.NewObjectTemplate(iso)

ctx := v8.NewContext(iso, global)
defer ctx.Close()
val, err := ctx.RunScript(`class Obj { constructor(input) { this.input = input } print() { return this.input.toString() } }; new Obj("some val")`, "")
fatalIf(t, err)
obj, err := val.AsObject()
Expand Down
3 changes: 2 additions & 1 deletion isolate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ func TestIsolateGarbageCollection(t *testing.T) {

tmpl := v8.NewObjectTemplate(iso)
tmpl.Set("foo", "bar")
v8.NewContext(iso, tmpl)
ctx := v8.NewContext(iso, tmpl)

ctx.Close()
iso.Dispose()

runtime.GC()
Expand Down
2 changes: 2 additions & 0 deletions object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func TestObjectMethodCall(t *testing.T) {

ctx := v8.NewContext()
iso := ctx.Isolate()
defer iso.Dispose()
defer ctx.Close()
val, _ := ctx.RunScript(`class Obj { constructor(input) { this.input = input, this.prop = "" } print() { return this.input.toString() } }; new Obj("some val")`, "")
obj, _ := val.AsObject()
val, err := obj.MethodCall("print")
Expand Down