diff --git a/go.mod b/go.mod index 3ce888fa084..087793d62da 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/PuerkitoBio/goquery v1.8.0 github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 github.com/andybalholm/brotli v1.0.4 - github.com/dop251/goja v0.0.0-20220705101429-189bfeb9f530 + github.com/dop251/goja v0.0.0-20220714114325-87952593a54c github.com/fatih/color v1.13.0 github.com/golang/protobuf v1.5.2 github.com/gorilla/websocket v1.5.0 diff --git a/go.sum b/go.sum index 88d1eb73e0b..7a60bdd4963 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 h1:Izz0+t1Z5nI16/II7vuEo/nHjodOg0p7+OiDpjX5t1E= github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= -github.com/dop251/goja v0.0.0-20220705101429-189bfeb9f530 h1:936YSsrki8Z6H48PPFbATV674Gpmh444xXaX+O5wwFQ= -github.com/dop251/goja v0.0.0-20220705101429-189bfeb9f530/go.mod h1:TQJQ+ZNyFVvUtUEtCZxBhfWiH7RJqR3EivNmvD6Waik= +github.com/dop251/goja v0.0.0-20220714114325-87952593a54c h1:OtwWjp/Il88H3JTvdrdaPo7Gw3ZUu2O+PWOzlE7yNOk= +github.com/dop251/goja v0.0.0-20220714114325-87952593a54c/go.mod h1:TQJQ+ZNyFVvUtUEtCZxBhfWiH7RJqR3EivNmvD6Waik= github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= diff --git a/vendor/github.com/dop251/goja/runtime.go b/vendor/github.com/dop251/goja/runtime.go index 7e816505467..474cec151a9 100644 --- a/vendor/github.com/dop251/goja/runtime.go +++ b/vendor/github.com/dop251/goja/runtime.go @@ -1367,6 +1367,9 @@ func (r *Runtime) RunProgram(p *Program) (result Value, err error) { if x := recover(); x != nil { if ex, ok := x.(*uncatchableException); ok { err = ex.err + if len(r.vm.callStack) == 0 { + r.leaveAbrupt() + } } else { panic(x) } @@ -1423,6 +1426,8 @@ func (r *Runtime) CaptureCallStack(depth int, stack []StackFrame) []StackFrame { } // Interrupt a running JavaScript. The corresponding Go call will return an *InterruptedError containing v. +// If the interrupt propagates until the stack is empty the currently queued promise resolve/reject jobs will be cleared +// without being executed. This is the same time they would be executed otherwise. // Note, it only works while in JavaScript code, it does not interrupt native Go functions (which includes all built-ins). // If the runtime is currently not running, it will be immediately interrupted on the next Run*() call. // To avoid that use ClearInterrupt() @@ -2329,6 +2334,9 @@ func AssertFunction(v Value) (Callable, bool) { if x := recover(); x != nil { if ex, ok := x.(*uncatchableException); ok { err = ex.err + if len(obj.runtime.vm.callStack) == 0 { + obj.runtime.leaveAbrupt() + } } else { panic(x) } @@ -2613,7 +2621,7 @@ func (r *Runtime) getHash() *maphash.Hash { return r.hash } -// called when the top level function returns (i.e. control is passed outside the Runtime). +// called when the top level function returns normally (i.e. control is passed outside the Runtime). func (r *Runtime) leave() { for { jobs := r.jobQueue @@ -2627,6 +2635,12 @@ func (r *Runtime) leave() { } } +// called when the top level function returns (i.e. control is passed outside the Runtime) but it was due to an interrupt +func (r *Runtime) leaveAbrupt() { + r.jobQueue = nil + r.ClearInterrupt() +} + func nilSafe(v Value) Value { if v != nil { return v diff --git a/vendor/github.com/dop251/goja/vm.go b/vendor/github.com/dop251/goja/vm.go index 4e332ff1183..3f617a24e43 100644 --- a/vendor/github.com/dop251/goja/vm.go +++ b/vendor/github.com/dop251/goja/vm.go @@ -419,8 +419,6 @@ func (vm *vm) run() { iface: vm.interruptVal, } v.stack = vm.captureStack(nil, 0) - atomic.StoreUint32(&vm.interrupted, 0) - vm.interruptVal = nil vm.interruptLock.Unlock() panic(&uncatchableException{ err: v, diff --git a/vendor/modules.txt b/vendor/modules.txt index f2e5e726c64..3d55ec3994d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -23,7 +23,7 @@ github.com/davecgh/go-spew/spew ## explicit github.com/dlclark/regexp2 github.com/dlclark/regexp2/syntax -# github.com/dop251/goja v0.0.0-20220705101429-189bfeb9f530 +# github.com/dop251/goja v0.0.0-20220714114325-87952593a54c ## explicit; go 1.14 github.com/dop251/goja github.com/dop251/goja/ast