From 102abe5760fb20ec0b4c09e12c83cdd7704c27a5 Mon Sep 17 00:00:00 2001 From: Michael Nutt Date: Fri, 11 Feb 2022 13:33:45 -0500 Subject: [PATCH 1/2] Add failing test for referencing object template inside callback function --- object_template_leak_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 object_template_leak_test.go diff --git a/object_template_leak_test.go b/object_template_leak_test.go new file mode 100644 index 00000000..04bd0119 --- /dev/null +++ b/object_template_leak_test.go @@ -0,0 +1,36 @@ +// Copyright 2021 Roger Chapman and the v8go contributors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Ignore leaks within Go standard libraries http/https support code. +// The getaddrinfo detected leaks can be avoided using GODEBUG=netdns=go but +// currently there are more for loading system root certificates on macOS. +//go:build !leakcheck || !darwin +// +build !leakcheck !darwin + +package v8go_test + +import ( + "testing" + + v8 "rogchap.com/v8go" +) + +func TestObjectTemplateLeakCheck(t *testing.T) { + isolate := v8.NewIsolate() + global := v8.NewObjectTemplate(isolate) + + cb := func(info *v8.FunctionCallbackInfo) *v8.Value { + // referencing global seems to be the cause of the leak + _ = global + + return v8.Null(isolate) + } + + global.Set("fn", v8.NewFunctionTemplate(isolate, cb), v8.ReadOnly) + + context := v8.NewContext(isolate, global) + context.Close() + + isolate.Dispose() +} From 71fcd863dc7a4503066f13cb6c65af849dedfdaf Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Fri, 11 Feb 2022 15:03:21 -0500 Subject: [PATCH 2/2] Move ObjectTemplate leak test into object_template_test.go since the ignore leaks conditional build was cargo culted from another test file which isn't relevenat here. --- object_template_leak_test.go | 36 ------------------------------------ object_template_test.go | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 36 deletions(-) delete mode 100644 object_template_leak_test.go diff --git a/object_template_leak_test.go b/object_template_leak_test.go deleted file mode 100644 index 04bd0119..00000000 --- a/object_template_leak_test.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2021 Roger Chapman and the v8go contributors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Ignore leaks within Go standard libraries http/https support code. -// The getaddrinfo detected leaks can be avoided using GODEBUG=netdns=go but -// currently there are more for loading system root certificates on macOS. -//go:build !leakcheck || !darwin -// +build !leakcheck !darwin - -package v8go_test - -import ( - "testing" - - v8 "rogchap.com/v8go" -) - -func TestObjectTemplateLeakCheck(t *testing.T) { - isolate := v8.NewIsolate() - global := v8.NewObjectTemplate(isolate) - - cb := func(info *v8.FunctionCallbackInfo) *v8.Value { - // referencing global seems to be the cause of the leak - _ = global - - return v8.Null(isolate) - } - - global.Set("fn", v8.NewFunctionTemplate(isolate, cb), v8.ReadOnly) - - context := v8.NewContext(isolate, global) - context.Close() - - isolate.Dispose() -} diff --git a/object_template_test.go b/object_template_test.go index 76ca2f01..b7dfa467 100644 --- a/object_template_test.go +++ b/object_template_test.go @@ -156,3 +156,22 @@ func TestObjectTemplate_garbageCollection(t *testing.T) { runtime.GC() } + +func TestObjectTemplate_leakCheck(t *testing.T) { + isolate := v8.NewIsolate() + global := v8.NewObjectTemplate(isolate) + + cb := func(info *v8.FunctionCallbackInfo) *v8.Value { + // referencing global seems to be the cause of the leak + _ = global + + return v8.Null(isolate) + } + + global.Set("fn", v8.NewFunctionTemplate(isolate, cb), v8.ReadOnly) + + context := v8.NewContext(isolate, global) + context.Close() + + isolate.Dispose() +}