Skip to content

Commit

Permalink
Fix several leaks in tests (rogchap#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanahsmith authored Nov 8, 2021
1 parent 24e3ca7 commit a582436
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
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

0 comments on commit a582436

Please sign in to comment.