diff --git a/go.mod b/go.mod index 99ce9480cff..0973704ef90 100644 --- a/go.mod +++ b/go.mod @@ -8,13 +8,12 @@ require ( github.com/PuerkitoBio/goquery v1.9.1 github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 github.com/andybalholm/brotli v1.1.0 - github.com/dop251/goja v0.0.0-20240610225006-393f6d42497b github.com/evanw/esbuild v0.21.2 github.com/fatih/color v1.16.0 github.com/go-sourcemap/sourcemap v2.1.4+incompatible github.com/golang/protobuf v1.5.4 github.com/gorilla/websocket v1.5.1 - github.com/grafana/sobek v0.0.0-20240613124309-cb36746e8fee + github.com/grafana/sobek v0.0.0-20240611084759-1a77bdaf1a4a github.com/grafana/xk6-browser v1.6.0 github.com/grafana/xk6-dashboard v0.7.4 github.com/grafana/xk6-output-prometheus-remote v0.4.0 diff --git a/go.sum b/go.sum index 78cedff99a2..1083c3eb94f 100644 --- a/go.sum +++ b/go.sum @@ -42,8 +42,7 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dlclark/regexp2 v1.9.0 h1:pTK/l/3qYIKaRXuHnEnIf7Y5NxfRPfpb7dis6/gdlVI= github.com/dlclark/regexp2 v1.9.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= -github.com/dop251/goja v0.0.0-20240610225006-393f6d42497b h1:fMKDnOAKCGXSZBphY/ilLtu7cmwMnjqE+xJxUkfkpCY= -github.com/dop251/goja v0.0.0-20240610225006-393f6d42497b/go.mod h1:o31y53rb/qiIAONF7w3FHJZRqqP3fzHUr1HqanthByw= +github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 h1:OFTHt+yJDo/uaIKMGjEKzc3DGhrpQZoqvMUIloZv6ZY= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -83,8 +82,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= -github.com/grafana/sobek v0.0.0-20240613124309-cb36746e8fee h1:KjQPRiLoSZMz+oMdEyh8fE/rurMpx3lpRH8PIR66nzo= -github.com/grafana/sobek v0.0.0-20240613124309-cb36746e8fee/go.mod h1:4uA93vCOP7fFfkAEByuRieuU72pAc5DH05b71yCIVsQ= +github.com/grafana/sobek v0.0.0-20240611084759-1a77bdaf1a4a h1:RE9WtCdu6yQ5kfHA5ophYdf2FSchssXt85USln9eks0= +github.com/grafana/sobek v0.0.0-20240611084759-1a77bdaf1a4a/go.mod h1:tUEHKWaMrxFGrMgjeAH85OEceCGQiSl6a/6Wckj/Vf4= github.com/grafana/xk6-browser v1.6.0 h1:x8ZfBwiUJRRKNEw+Asr5ae9o2gFvYU1Ll/4dDMNIPZ8= github.com/grafana/xk6-browser v1.6.0/go.mod h1:xLaGGhTMHIRsMvkVWFYh9RPy87kG2n4L4Or6DeI8U+o= github.com/grafana/xk6-dashboard v0.7.4 h1:0ZRPTAXW+6A3Xqq/a/OaIZhxUt1SOMwUFff0IPwBHrs= diff --git a/js/bundle_test.go b/js/bundle_test.go index 39526ac79c6..934171aa9ba 100644 --- a/js/bundle_test.go +++ b/js/bundle_test.go @@ -230,7 +230,7 @@ BigInt(1231412444)`, Expr, Error string }{ "Array": {`[]`, "json: cannot unmarshal array into Go value of type lib.Options"}, - "Function": {`function(){}`, "error parsing script options: json: unsupported type: func(goja.FunctionCall) goja.Value"}, + "Function": {`function(){}`, "error parsing script options: json: unsupported type: func(sobek.FunctionCall) sobek.Value"}, } for name, data := range invalidOptions { t.Run(name, func(t *testing.T) { diff --git a/js/compiler/compiler.go b/js/compiler/compiler.go index 27860a5cb9b..f5099020a68 100644 --- a/js/compiler/compiler.go +++ b/js/compiler/compiler.go @@ -14,9 +14,9 @@ import ( "sync" "time" - "github.com/dop251/goja/parser" "github.com/go-sourcemap/sourcemap" "github.com/grafana/sobek" + "github.com/grafana/sobek/parser" "github.com/sirupsen/logrus" "go.k6.io/k6/lib" diff --git a/js/compiler/enhanced.go b/js/compiler/enhanced.go index 228686a4424..0841448c417 100644 --- a/js/compiler/enhanced.go +++ b/js/compiler/enhanced.go @@ -3,9 +3,9 @@ package compiler import ( "path/filepath" - "github.com/dop251/goja/file" - "github.com/dop251/goja/parser" "github.com/evanw/esbuild/pkg/api" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/parser" ) func esbuildTransform(src, filename string) (code string, srcMap []byte, err error) { diff --git a/js/compiler/enhanced_test.go b/js/compiler/enhanced_test.go index 4e06f694d9c..e1c8bd55390 100644 --- a/js/compiler/enhanced_test.go +++ b/js/compiler/enhanced_test.go @@ -4,8 +4,8 @@ import ( "errors" "testing" - "github.com/dop251/goja/parser" "github.com/grafana/sobek" + "github.com/grafana/sobek/parser" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.k6.io/k6/lib" diff --git a/js/tc39/tc39_test.go b/js/tc39/tc39_test.go index 4f334da9667..a5134903722 100644 --- a/js/tc39/tc39_test.go +++ b/js/tc39/tc39_test.go @@ -22,8 +22,8 @@ import ( "testing" "time" - "github.com/dop251/goja/parser" "github.com/grafana/sobek" + "github.com/grafana/sobek/parser" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.k6.io/k6/js/compiler" diff --git a/vendor/github.com/dop251/goja/LICENSE b/vendor/github.com/dop251/goja/LICENSE deleted file mode 100644 index 09c000454f7..00000000000 --- a/vendor/github.com/dop251/goja/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -Copyright (c) 2016 Dmitry Panov - -Copyright (c) 2012 Robert Krimen - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/dop251/goja/README.md b/vendor/github.com/dop251/goja/README.md deleted file mode 100644 index a4d0c09be11..00000000000 --- a/vendor/github.com/dop251/goja/README.md +++ /dev/null @@ -1,334 +0,0 @@ -goja -==== - -ECMAScript 5.1(+) implementation in Go. - -[![Go Reference](https://pkg.go.dev/badge/github.com/dop251/goja.svg)](https://pkg.go.dev/github.com/dop251/goja) - -Goja is an implementation of ECMAScript 5.1 in pure Go with emphasis on standard compliance and -performance. - -This project was largely inspired by [otto](https://github.com/robertkrimen/otto). - -The minimum required Go version is 1.20. - -Features --------- - - * Full ECMAScript 5.1 support (including regex and strict mode). - * Passes nearly all [tc39 tests](https://github.com/tc39/test262) for the features implemented so far. The goal is to - pass all of them. See .tc39_test262_checkout.sh for the latest working commit id. - * Capable of running Babel, Typescript compiler and pretty much anything written in ES5. - * Sourcemaps. - * Most of ES6 functionality, still work in progress, see https://github.com/dop251/goja/milestone/1?closed=1 - -Known incompatibilities and caveats ------------------------------------ - -### WeakMap -WeakMap is implemented by embedding references to the values into the keys. This means that as long -as the key is reachable all values associated with it in any weak maps also remain reachable and therefore -cannot be garbage collected even if they are not otherwise referenced, even after the WeakMap is gone. -The reference to the value is dropped either when the key is explicitly removed from the WeakMap or when the -key becomes unreachable. - -To illustrate this: - -```javascript -var m = new WeakMap(); -var key = {}; -var value = {/* a very large object */}; -m.set(key, value); -value = undefined; -m = undefined; // The value does NOT become garbage-collectable at this point -key = undefined; // Now it does -// m.delete(key); // This would work too -``` - -The reason for it is the limitation of the Go runtime. At the time of writing (version 1.15) having a finalizer -set on an object which is part of a reference cycle makes the whole cycle non-garbage-collectable. The solution -above is the only reasonable way I can think of without involving finalizers. This is the third attempt -(see https://github.com/dop251/goja/issues/250 and https://github.com/dop251/goja/issues/199 for more details). - -Note, this does not have any effect on the application logic, but may cause a higher-than-expected memory usage. - -### WeakRef and FinalizationRegistry -For the reason mentioned above implementing WeakRef and FinalizationRegistry does not seem to be possible at this stage. - -### JSON -`JSON.parse()` uses the standard Go library which operates in UTF-8. Therefore, it cannot correctly parse broken UTF-16 -surrogate pairs, for example: - -```javascript -JSON.parse(`"\\uD800"`).charCodeAt(0).toString(16) // returns "fffd" instead of "d800" -``` - -### Date -Conversion from calendar date to epoch timestamp uses the standard Go library which uses `int`, rather than `float` as per -ECMAScript specification. This means if you pass arguments that overflow int to the `Date()` constructor or if there is -an integer overflow, the result will be incorrect, for example: - -```javascript -Date.UTC(1970, 0, 1, 80063993375, 29, 1, -288230376151711740) // returns 29256 instead of 29312 -``` - -FAQ ---- - -### How fast is it? - -Although it's faster than many scripting language implementations in Go I have seen -(for example it's 6-7 times faster than otto on average) it is not a -replacement for V8 or SpiderMonkey or any other general-purpose JavaScript engine. -You can find some benchmarks [here](https://github.com/dop251/goja/issues/2). - -### Why would I want to use it over a V8 wrapper? - -It greatly depends on your usage scenario. If most of the work is done in javascript -(for example crypto or any other heavy calculations) you are definitely better off with V8. - -If you need a scripting language that drives an engine written in Go so that -you need to make frequent calls between Go and javascript passing complex data structures -then the cgo overhead may outweigh the benefits of having a faster javascript engine. - -Because it's written in pure Go there are no cgo dependencies, it's very easy to build and it -should run on any platform supported by Go. - -It gives you a much better control over execution environment so can be useful for research. - -### Is it goroutine-safe? - -No. An instance of goja.Runtime can only be used by a single goroutine -at a time. You can create as many instances of Runtime as you like but -it's not possible to pass object values between runtimes. - -### Where is setTimeout()? - -setTimeout() assumes concurrent execution of code which requires an execution -environment, for example an event loop similar to nodejs or a browser. -There is a [separate project](https://github.com/dop251/goja_nodejs) aimed at providing some NodeJS functionality, -and it includes an event loop. - -### Can you implement (feature X from ES6 or higher)? - -I will be adding features in their dependency order and as quickly as time permits. Please do not ask -for ETAs. Features that are open in the [milestone](https://github.com/dop251/goja/milestone/1) are either in progress -or will be worked on next. - -The ongoing work is done in separate feature branches which are merged into master when appropriate. -Every commit in these branches represents a relatively stable state (i.e. it compiles and passes all enabled tc39 tests), -however because the version of tc39 tests I use is quite old, it may be not as well tested as the ES5.1 functionality. Because there are (usually) no major breaking changes between ECMAScript revisions -it should not break your existing code. You are encouraged to give it a try and report any bugs found. Please do not submit fixes though without discussing it first, as the code could be changed in the meantime. - -### How do I contribute? - -Before submitting a pull request please make sure that: - -- You followed ECMA standard as close as possible. If adding a new feature make sure you've read the specification, -do not just base it on a couple of examples that work fine. -- Your change does not have a significant negative impact on performance (unless it's a bugfix and it's unavoidable) -- It passes all relevant tc39 tests. - -Current Status --------------- - - * There should be no breaking changes in the API, however it may be extended. - * Some of the AnnexB functionality is missing. - -Basic Example -------------- - -Run JavaScript and get the result value. - -```go -vm := goja.New() -v, err := vm.RunString("2 + 2") -if err != nil { - panic(err) -} -if num := v.Export().(int64); num != 4 { - panic(num) -} -``` - -Passing Values to JS --------------------- -Any Go value can be passed to JS using Runtime.ToValue() method. See the method's [documentation](https://pkg.go.dev/github.com/dop251/goja#Runtime.ToValue) for more details. - -Exporting Values from JS ------------------------- -A JS value can be exported into its default Go representation using Value.Export() method. - -Alternatively it can be exported into a specific Go variable using [Runtime.ExportTo()](https://pkg.go.dev/github.com/dop251/goja#Runtime.ExportTo) method. - -Within a single export operation the same Object will be represented by the same Go value (either the same map, slice or -a pointer to the same struct). This includes circular objects and makes it possible to export them. - -Calling JS functions from Go ----------------------------- -There are 2 approaches: - -- Using [AssertFunction()](https://pkg.go.dev/github.com/dop251/goja#AssertFunction): -```go -const SCRIPT = ` -function sum(a, b) { - return +a + b; -} -` - -vm := goja.New() -_, err := vm.RunString(SCRIPT) -if err != nil { - panic(err) -} -sum, ok := goja.AssertFunction(vm.Get("sum")) -if !ok { - panic("Not a function") -} - -res, err := sum(goja.Undefined(), vm.ToValue(40), vm.ToValue(2)) -if err != nil { - panic(err) -} -fmt.Println(res) -// Output: 42 -``` -- Using [Runtime.ExportTo()](https://pkg.go.dev/github.com/dop251/goja#Runtime.ExportTo): -```go -const SCRIPT = ` -function sum(a, b) { - return +a + b; -} -` - -vm := goja.New() -_, err := vm.RunString(SCRIPT) -if err != nil { - panic(err) -} - -var sum func(int, int) int -err = vm.ExportTo(vm.Get("sum"), &sum) -if err != nil { - panic(err) -} - -fmt.Println(sum(40, 2)) // note, _this_ value in the function will be undefined. -// Output: 42 -``` - -The first one is more low level and allows specifying _this_ value, whereas the second one makes the function look like -a normal Go function. - -Mapping struct field and method names -------------------------------------- -By default, the names are passed through as is which means they are capitalised. This does not match -the standard JavaScript naming convention, so if you need to make your JS code look more natural or if you are -dealing with a 3rd party library, you can use a [FieldNameMapper](https://pkg.go.dev/github.com/dop251/goja#FieldNameMapper): - -```go -vm := goja.New() -vm.SetFieldNameMapper(TagFieldNameMapper("json", true)) -type S struct { - Field int `json:"field"` -} -vm.Set("s", S{Field: 42}) -res, _ := vm.RunString(`s.field`) // without the mapper it would have been s.Field -fmt.Println(res.Export()) -// Output: 42 -``` - -There are two standard mappers: [TagFieldNameMapper](https://pkg.go.dev/github.com/dop251/goja#TagFieldNameMapper) and -[UncapFieldNameMapper](https://pkg.go.dev/github.com/dop251/goja#UncapFieldNameMapper), or you can use your own implementation. - -Native Constructors -------------------- - -In order to implement a constructor function in Go use `func (goja.ConstructorCall) *goja.Object`. -See [Runtime.ToValue()](https://pkg.go.dev/github.com/dop251/goja#Runtime.ToValue) documentation for more details. - -Regular Expressions -------------------- - -Goja uses the embedded Go regexp library where possible, otherwise it falls back to [regexp2](https://github.com/dlclark/regexp2). - -Exceptions ----------- - -Any exception thrown in JavaScript is returned as an error of type *Exception. It is possible to extract the value thrown -by using the Value() method: - -```go -vm := goja.New() -_, err := vm.RunString(` - -throw("Test"); - -`) - -if jserr, ok := err.(*Exception); ok { - if jserr.Value().Export() != "Test" { - panic("wrong value") - } -} else { - panic("wrong type") -} -``` - -If a native Go function panics with a Value, it is thrown as a Javascript exception (and therefore can be caught): - -```go -var vm *Runtime - -func Test() { - panic(vm.ToValue("Error")) -} - -vm = goja.New() -vm.Set("Test", Test) -_, err := vm.RunString(` - -try { - Test(); -} catch(e) { - if (e !== "Error") { - throw e; - } -} - -`) - -if err != nil { - panic(err) -} -``` - -Interrupting ------------- - -```go -func TestInterrupt(t *testing.T) { - const SCRIPT = ` - var i = 0; - for (;;) { - i++; - } - ` - - vm := goja.New() - time.AfterFunc(200 * time.Millisecond, func() { - vm.Interrupt("halt") - }) - - _, err := vm.RunString(SCRIPT) - if err == nil { - t.Fatal("Err is nil") - } - // err is of type *InterruptError and its Value() method returns whatever has been passed to vm.Interrupt() -} -``` - -NodeJS Compatibility --------------------- - -There is a [separate project](https://github.com/dop251/goja_nodejs) aimed at providing some of the NodeJS functionality. diff --git a/vendor/github.com/dop251/goja/.gitignore b/vendor/github.com/grafana/sobek/.gitignore similarity index 100% rename from vendor/github.com/dop251/goja/.gitignore rename to vendor/github.com/grafana/sobek/.gitignore diff --git a/vendor/github.com/dop251/goja/.tc39_test262_checkout.sh b/vendor/github.com/grafana/sobek/.tc39_test262_checkout.sh similarity index 100% rename from vendor/github.com/dop251/goja/.tc39_test262_checkout.sh rename to vendor/github.com/grafana/sobek/.tc39_test262_checkout.sh diff --git a/vendor/github.com/grafana/sobek/README.md b/vendor/github.com/grafana/sobek/README.md index 51d78207ef6..70dc1cdb3f7 100644 --- a/vendor/github.com/grafana/sobek/README.md +++ b/vendor/github.com/grafana/sobek/README.md @@ -1,7 +1,329 @@ -## Sobek +sobek +==== -Is a fork of [goja](https://github.com/dop251/goja) named after the [ancient Egyptian god](https://en.wikipedia.org/wiki/Sobek) of the same name +ECMAScript 5.1(+) implementation in Go. -The fork is currently just aliasing types in order to facilitate the moving of the current k6 codebase and extension to it with less friction. +[![Go Reference](https://pkg.go.dev/badge/github.com/grafana/sobek.svg)](https://pkg.go.dev/github.com/grafana/sobek) -The plan and discussion on the transition can be find in [this issue](https://github.com/grafana/k6/issues/3773). +Sobek is an implementation of ECMAScript 5.1 in pure Go with emphasis on standard compliance and +performance. + +This project is a fork of [goja](https://github.com/dop251/goja). + +This project was largely inspired by [otto](https://github.com/robertkrimen/otto). + +The minimum required Go version is 1.20. + +Features +-------- + + * Full ECMAScript 5.1 support (including regex and strict mode). + * Passes nearly all [tc39 tests](https://github.com/tc39/test262) for the features implemented so far. The goal is to + pass all of them. See .tc39_test262_checkout.sh for the latest working commit id. + * Capable of running Babel, Typescript compiler and pretty much anything written in ES5. + * Sourcemaps. + * Most of ES6 functionality, still work in progress, see https://github.com/grafana/sobek/milestone/1?closed=1 + +Known incompatibilities and caveats +----------------------------------- + +### WeakMap +WeakMap is implemented by embedding references to the values into the keys. This means that as long +as the key is reachable all values associated with it in any weak maps also remain reachable and therefore +cannot be garbage collected even if they are not otherwise referenced, even after the WeakMap is gone. +The reference to the value is dropped either when the key is explicitly removed from the WeakMap or when the +key becomes unreachable. + +To illustrate this: + +```javascript +var m = new WeakMap(); +var key = {}; +var value = {/* a very large object */}; +m.set(key, value); +value = undefined; +m = undefined; // The value does NOT become garbage-collectable at this point +key = undefined; // Now it does +// m.delete(key); // This would work too +``` + +The reason for it is the limitation of the Go runtime. At the time of writing (version 1.15) having a finalizer +set on an object which is part of a reference cycle makes the whole cycle non-garbage-collectable. The solution +above is the only reasonable way I can think of without involving finalizers. This is the third attempt +(see https://github.com/dop251/goja/issues/250 and https://github.com/dop251/goja/issues/199 for more details). + +Note, this does not have any effect on the application logic, but may cause a higher-than-expected memory usage. + +### WeakRef and FinalizationRegistry +For the reason mentioned above implementing WeakRef and FinalizationRegistry does not seem to be possible at this stage. + +### JSON +`JSON.parse()` uses the standard Go library which operates in UTF-8. Therefore, it cannot correctly parse broken UTF-16 +surrogate pairs, for example: + +```javascript +JSON.parse(`"\\uD800"`).charCodeAt(0).toString(16) // returns "fffd" instead of "d800" +``` + +### Date +Conversion from calendar date to epoch timestamp uses the standard Go library which uses `int`, rather than `float` as per +ECMAScript specification. This means if you pass arguments that overflow int to the `Date()` constructor or if there is +an integer overflow, the result will be incorrect, for example: + +```javascript +Date.UTC(1970, 0, 1, 80063993375, 29, 1, -288230376151711740) // returns 29256 instead of 29312 +``` + +FAQ +--- + +### How fast is it? + +Although it's faster than many scripting language implementations in Go I have seen +(for example it's 6-7 times faster than otto on average) it is not a +replacement for V8 or SpiderMonkey or any other general-purpose JavaScript engine. +You can find some benchmarks [here](https://github.com/dop251/goja/issues/2). + +### Why would I want to use it over a V8 wrapper? + +It greatly depends on your usage scenario. If most of the work is done in javascript +(for example crypto or any other heavy calculations) you are definitely better off with V8. + +If you need a scripting language that drives an engine written in Go so that +you need to make frequent calls between Go and javascript passing complex data structures +then the cgo overhead may outweigh the benefits of having a faster javascript engine. + +Because it's written in pure Go there are no cgo dependencies, it's very easy to build and it +should run on any platform supported by Go. + +It gives you a much better control over execution environment so can be useful for research. + +### Is it goroutine-safe? + +No. An instance of sobek.Runtime can only be used by a single goroutine +at a time. You can create as many instances of Runtime as you like but +it's not possible to pass object values between runtimes. + +### Where is setTimeout()? + +setTimeout() assumes concurrent execution of code which requires an execution +environment, for example an event loop similar to nodejs or a browser. + +### Can you implement (feature X from ES6 or higher)? + +I will be adding features in their dependency order and as quickly as time permits. Please do not ask +for ETAs. Features that are open in the [milestone](https://github.com/grafana/sobek/milestone/1) are either in progress +or will be worked on next. + +The ongoing work is done in separate feature branches which are merged into master when appropriate. +Every commit in these branches represents a relatively stable state (i.e. it compiles and passes all enabled tc39 tests), +however because the version of tc39 tests I use is quite old, it may be not as well tested as the ES5.1 functionality. Because there are (usually) no major breaking changes between ECMAScript revisions +it should not break your existing code. You are encouraged to give it a try and report any bugs found. Please do not submit fixes though without discussing it first, as the code could be changed in the meantime. + +### How do I contribute? + +Before submitting a pull request please make sure that: + +- You followed ECMA standard as close as possible. If adding a new feature make sure you've read the specification, +do not just base it on a couple of examples that work fine. +- Your change does not have a significant negative impact on performance (unless it's a bugfix and it's unavoidable) +- It passes all relevant tc39 tests. + +Current Status +-------------- + + * There should be no breaking changes in the API, however it may be extended. + * Some of the AnnexB functionality is missing. + +Basic Example +------------- + +Run JavaScript and get the result value. + +```go +vm := sobek.New() +v, err := vm.RunString("2 + 2") +if err != nil { + panic(err) +} +if num := v.Export().(int64); num != 4 { + panic(num) +} +``` + +Passing Values to JS +-------------------- +Any Go value can be passed to JS using Runtime.ToValue() method. See the method's [documentation](https://pkg.go.dev/github.com/grafana/sobek#Runtime.ToValue) for more details. + +Exporting Values from JS +------------------------ +A JS value can be exported into its default Go representation using Value.Export() method. + +Alternatively it can be exported into a specific Go variable using [Runtime.ExportTo()](https://pkg.go.dev/github.com/grafana/sobek#Runtime.ExportTo) method. + +Within a single export operation the same Object will be represented by the same Go value (either the same map, slice or +a pointer to the same struct). This includes circular objects and makes it possible to export them. + +Calling JS functions from Go +---------------------------- +There are 2 approaches: + +- Using [AssertFunction()](https://pkg.go.dev/github.com/grafana/sobek#AssertFunction): +```go +const SCRIPT = ` +function sum(a, b) { + return +a + b; +} +` + +vm := sobek.New() +_, err := vm.RunString(SCRIPT) +if err != nil { + panic(err) +} +sum, ok := sobek.AssertFunction(vm.Get("sum")) +if !ok { + panic("Not a function") +} + +res, err := sum(sobek.Undefined(), vm.ToValue(40), vm.ToValue(2)) +if err != nil { + panic(err) +} +fmt.Println(res) +// Output: 42 +``` +- Using [Runtime.ExportTo()](https://pkg.go.dev/github.com/grafana/sobek#Runtime.ExportTo): +```go +const SCRIPT = ` +function sum(a, b) { + return +a + b; +} +` + +vm := sobek.New() +_, err := vm.RunString(SCRIPT) +if err != nil { + panic(err) +} + +var sum func(int, int) int +err = vm.ExportTo(vm.Get("sum"), &sum) +if err != nil { + panic(err) +} + +fmt.Println(sum(40, 2)) // note, _this_ value in the function will be undefined. +// Output: 42 +``` + +The first one is more low level and allows specifying _this_ value, whereas the second one makes the function look like +a normal Go function. + +Mapping struct field and method names +------------------------------------- +By default, the names are passed through as is which means they are capitalised. This does not match +the standard JavaScript naming convention, so if you need to make your JS code look more natural or if you are +dealing with a 3rd party library, you can use a [FieldNameMapper](https://pkg.go.dev/github.com/grafana/sobek#FieldNameMapper): + +```go +vm := sobek.New() +vm.SetFieldNameMapper(TagFieldNameMapper("json", true)) +type S struct { + Field int `json:"field"` +} +vm.Set("s", S{Field: 42}) +res, _ := vm.RunString(`s.field`) // without the mapper it would have been s.Field +fmt.Println(res.Export()) +// Output: 42 +``` + +There are two standard mappers: [TagFieldNameMapper](https://pkg.go.dev/github.com/grafana/sobek#TagFieldNameMapper) and +[UncapFieldNameMapper](https://pkg.go.dev/github.com/grafana/sobek#UncapFieldNameMapper), or you can use your own implementation. + +Native Constructors +------------------- + +In order to implement a constructor function in Go use `func (sobek.ConstructorCall) *sobek.Object`. +See [Runtime.ToValue()](https://pkg.go.dev/github.com/grafana/sobek#Runtime.ToValue) documentation for more details. + +Regular Expressions +------------------- + +Sobek uses the embedded Go regexp library where possible, otherwise it falls back to [regexp2](https://github.com/dlclark/regexp2). + +Exceptions +---------- + +Any exception thrown in JavaScript is returned as an error of type *Exception. It is possible to extract the value thrown +by using the Value() method: + +```go +vm := sobek.New() +_, err := vm.RunString(` + +throw("Test"); + +`) + +if jserr, ok := err.(*Exception); ok { + if jserr.Value().Export() != "Test" { + panic("wrong value") + } +} else { + panic("wrong type") +} +``` + +If a native Go function panics with a Value, it is thrown as a Javascript exception (and therefore can be caught): + +```go +var vm *Runtime + +func Test() { + panic(vm.ToValue("Error")) +} + +vm = sobek.New() +vm.Set("Test", Test) +_, err := vm.RunString(` + +try { + Test(); +} catch(e) { + if (e !== "Error") { + throw e; + } +} + +`) + +if err != nil { + panic(err) +} +``` + +Interrupting +------------ + +```go +func TestInterrupt(t *testing.T) { + const SCRIPT = ` + var i = 0; + for (;;) { + i++; + } + ` + + vm := sobek.New() + time.AfterFunc(200 * time.Millisecond, func() { + vm.Interrupt("halt") + }) + + _, err := vm.RunString(SCRIPT) + if err == nil { + t.Fatal("Err is nil") + } + // err is of type *InterruptError and its Value() method returns whatever has been passed to vm.Interrupt() +} +``` diff --git a/vendor/github.com/grafana/sobek/aliases.go b/vendor/github.com/grafana/sobek/aliases.go deleted file mode 100644 index 01a8772d8a1..00000000000 --- a/vendor/github.com/grafana/sobek/aliases.go +++ /dev/null @@ -1,130 +0,0 @@ -package sobek - -import ( - "github.com/dop251/goja" - "github.com/dop251/goja/ast" - "github.com/dop251/goja/parser" -) - -const ( - FLAG_NOT_SET Flag = iota - FLAG_FALSE - FLAG_TRUE -) - -func Null() Value { return goja.Null() } - -func IsInfinity(v Value) bool { return goja.IsInfinity(v) } - -func IsNaN(v Value) bool { return goja.IsNaN(v) } - -func IsNull(v Value) bool { return goja.IsNull(v) } - -func IsUndefined(v Value) bool { return goja.IsUndefined(v) } - -func Parse(name, src string, options ...parser.Option) (prg *ast.Program, err error) { - return goja.Parse(name, src, options...) -} - -func AssertFunction(v Value) (Callable, bool) { return goja.AssertFunction(v) } - -func AssertConstructor(v Value) (Constructor, bool) { return goja.AssertConstructor(v) } - -func Undefined() Value { return goja.Undefined() } - -func CompileAST(prg *ast.Program, strict bool) (*Program, error) { - return goja.CompileAST(prg, strict) -} - -func Compile(name, src string, strict bool) (*Program, error) { - return goja.Compile(name, src, strict) -} - -func MustCompile(name, src string, strict bool) *Program { - return goja.MustCompile(name, src, strict) -} - -func New() *Runtime { - return goja.New() -} - -type ArrayBuffer = goja.ArrayBuffer - -type ( - AsyncContextTracker = goja.AsyncContextTracker - Callable = goja.Callable -) - -type ( - CompilerError = goja.CompilerError - CompilerReferenceError = goja.CompilerReferenceError -) - -type CompilerSyntaxError = goja.CompilerSyntaxError - -type Constructor = goja.Constructor - -type ConstructorCall = goja.ConstructorCall - -type ( - DynamicArray = goja.DynamicArray - DynamicObject = goja.DynamicObject - Exception = goja.Exception -) - -type FieldNameMapper = goja.FieldNameMapper - -type ( - Flag = goja.Flag - FunctionCall = goja.FunctionCall -) - -type InterruptedError = goja.InterruptedError - -type ( - JsonEncodable = goja.JsonEncodable - Now = goja.Now - Object = goja.Object -) - -type Program = goja.Program - -type Promise = goja.Promise - -type ( - PromiseRejectionOperation = goja.PromiseRejectionOperation - PromiseRejectionTracker = goja.PromiseRejectionTracker - PromiseState = goja.PromiseState - PropertyDescriptor = goja.PropertyDescriptor -) - -const ( - PromiseRejectionReject PromiseRejectionOperation = iota - PromiseRejectionHandle -) - -const ( - PromiseStatePending PromiseState = iota - PromiseStateFulfilled - PromiseStateRejected -) - -type Proxy = goja.Proxy - -type ( - ProxyTrapConfig = goja.ProxyTrapConfig - RandSource = goja.RandSource - Runtime = goja.Runtime -) - -type StackFrame = goja.StackFrame - -type ( - StackOverflowError = goja.StackOverflowError - String = goja.String - StringBuilder = goja.StringBuilder - Symbol = goja.Symbol - Value = goja.Value -) - -func UncapFieldNameMapper() FieldNameMapper { return goja.UncapFieldNameMapper() } diff --git a/vendor/github.com/dop251/goja/array.go b/vendor/github.com/grafana/sobek/array.go similarity index 99% rename from vendor/github.com/dop251/goja/array.go rename to vendor/github.com/grafana/sobek/array.go index 7a67a47c16e..ef12dc558fb 100644 --- a/vendor/github.com/dop251/goja/array.go +++ b/vendor/github.com/grafana/sobek/array.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "fmt" @@ -7,7 +7,7 @@ import ( "reflect" "strconv" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type arrayIterObject struct { diff --git a/vendor/github.com/dop251/goja/array_sparse.go b/vendor/github.com/grafana/sobek/array_sparse.go similarity index 99% rename from vendor/github.com/dop251/goja/array_sparse.go rename to vendor/github.com/grafana/sobek/array_sparse.go index f99afd7e6dd..877d281976a 100644 --- a/vendor/github.com/dop251/goja/array_sparse.go +++ b/vendor/github.com/grafana/sobek/array_sparse.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "fmt" @@ -8,7 +8,7 @@ import ( "sort" "strconv" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type sparseArrayItem struct { diff --git a/vendor/github.com/dop251/goja/ast/README.markdown b/vendor/github.com/grafana/sobek/ast/README.markdown similarity index 99% rename from vendor/github.com/dop251/goja/ast/README.markdown rename to vendor/github.com/grafana/sobek/ast/README.markdown index aba088e261c..65aa0018e00 100644 --- a/vendor/github.com/dop251/goja/ast/README.markdown +++ b/vendor/github.com/grafana/sobek/ast/README.markdown @@ -1,6 +1,6 @@ # ast -- - import "github.com/dop251/goja/ast" + import "github.com/grafana/sobek/ast" Package ast declares types representing a JavaScript AST. diff --git a/vendor/github.com/dop251/goja/ast/node.go b/vendor/github.com/grafana/sobek/ast/node.go similarity index 99% rename from vendor/github.com/dop251/goja/ast/node.go rename to vendor/github.com/grafana/sobek/ast/node.go index 3bec89db493..0663ba8daea 100644 --- a/vendor/github.com/dop251/goja/ast/node.go +++ b/vendor/github.com/grafana/sobek/ast/node.go @@ -9,9 +9,9 @@ node types are concerned) and may change in the future. package ast import ( - "github.com/dop251/goja/file" - "github.com/dop251/goja/token" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/token" + "github.com/grafana/sobek/unistring" ) type PropertyKind string diff --git a/vendor/github.com/dop251/goja/builtin_array.go b/vendor/github.com/grafana/sobek/builtin_array.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_array.go rename to vendor/github.com/grafana/sobek/builtin_array.go index 6ba8802c282..7121bfa7c4a 100644 --- a/vendor/github.com/dop251/goja/builtin_array.go +++ b/vendor/github.com/grafana/sobek/builtin_array.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "math" diff --git a/vendor/github.com/dop251/goja/builtin_boolean.go b/vendor/github.com/grafana/sobek/builtin_boolean.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_boolean.go rename to vendor/github.com/grafana/sobek/builtin_boolean.go index 8476328511b..757f8ad7423 100644 --- a/vendor/github.com/dop251/goja/builtin_boolean.go +++ b/vendor/github.com/grafana/sobek/builtin_boolean.go @@ -1,4 +1,4 @@ -package goja +package sobek func (r *Runtime) booleanproto_toString(call FunctionCall) Value { var b bool diff --git a/vendor/github.com/dop251/goja/builtin_date.go b/vendor/github.com/grafana/sobek/builtin_date.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_date.go rename to vendor/github.com/grafana/sobek/builtin_date.go index 84a80ac02b2..b67e7f0e179 100644 --- a/vendor/github.com/dop251/goja/builtin_date.go +++ b/vendor/github.com/grafana/sobek/builtin_date.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "fmt" diff --git a/vendor/github.com/dop251/goja/builtin_error.go b/vendor/github.com/grafana/sobek/builtin_error.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_error.go rename to vendor/github.com/grafana/sobek/builtin_error.go index b07bf6a777e..99532542cae 100644 --- a/vendor/github.com/dop251/goja/builtin_error.go +++ b/vendor/github.com/grafana/sobek/builtin_error.go @@ -1,6 +1,6 @@ -package goja +package sobek -import "github.com/dop251/goja/unistring" +import "github.com/grafana/sobek/unistring" const propNameStack = "stack" diff --git a/vendor/github.com/dop251/goja/builtin_function.go b/vendor/github.com/grafana/sobek/builtin_function.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_function.go rename to vendor/github.com/grafana/sobek/builtin_function.go index 26a1287c836..64332f95324 100644 --- a/vendor/github.com/dop251/goja/builtin_function.go +++ b/vendor/github.com/grafana/sobek/builtin_function.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "math" diff --git a/vendor/github.com/dop251/goja/builtin_global.go b/vendor/github.com/grafana/sobek/builtin_global.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_global.go rename to vendor/github.com/grafana/sobek/builtin_global.go index 5ef4176b49d..d7ba9b457b5 100644 --- a/vendor/github.com/dop251/goja/builtin_global.go +++ b/vendor/github.com/grafana/sobek/builtin_global.go @@ -1,8 +1,8 @@ -package goja +package sobek import ( "errors" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" "io" "math" "regexp" diff --git a/vendor/github.com/dop251/goja/builtin_json.go b/vendor/github.com/grafana/sobek/builtin_json.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_json.go rename to vendor/github.com/grafana/sobek/builtin_json.go index e99771cf12e..57f7ccd798c 100644 --- a/vendor/github.com/dop251/goja/builtin_json.go +++ b/vendor/github.com/grafana/sobek/builtin_json.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "bytes" @@ -12,7 +12,7 @@ import ( "unicode/utf16" "unicode/utf8" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) const hex = "0123456789abcdef" diff --git a/vendor/github.com/dop251/goja/builtin_map.go b/vendor/github.com/grafana/sobek/builtin_map.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_map.go rename to vendor/github.com/grafana/sobek/builtin_map.go index 819d025fe10..c0c887fcc5d 100644 --- a/vendor/github.com/dop251/goja/builtin_map.go +++ b/vendor/github.com/grafana/sobek/builtin_map.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "reflect" diff --git a/vendor/github.com/dop251/goja/builtin_math.go b/vendor/github.com/grafana/sobek/builtin_math.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_math.go rename to vendor/github.com/grafana/sobek/builtin_math.go index 169ea18ca4b..a31d7c32e04 100644 --- a/vendor/github.com/dop251/goja/builtin_math.go +++ b/vendor/github.com/grafana/sobek/builtin_math.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "math" diff --git a/vendor/github.com/dop251/goja/builtin_number.go b/vendor/github.com/grafana/sobek/builtin_number.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_number.go rename to vendor/github.com/grafana/sobek/builtin_number.go index 43add4ffb3e..f7b2ee040d4 100644 --- a/vendor/github.com/dop251/goja/builtin_number.go +++ b/vendor/github.com/grafana/sobek/builtin_number.go @@ -1,10 +1,10 @@ -package goja +package sobek import ( "math" "sync" - "github.com/dop251/goja/ftoa" + "github.com/grafana/sobek/ftoa" ) func (r *Runtime) toNumber(v Value) Value { diff --git a/vendor/github.com/dop251/goja/builtin_object.go b/vendor/github.com/grafana/sobek/builtin_object.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_object.go rename to vendor/github.com/grafana/sobek/builtin_object.go index 6bf1ff80ae9..d7c5aa922ac 100644 --- a/vendor/github.com/dop251/goja/builtin_object.go +++ b/vendor/github.com/grafana/sobek/builtin_object.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "fmt" diff --git a/vendor/github.com/dop251/goja/builtin_promise.go b/vendor/github.com/grafana/sobek/builtin_promise.go similarity index 98% rename from vendor/github.com/dop251/goja/builtin_promise.go rename to vendor/github.com/grafana/sobek/builtin_promise.go index d51f27d17af..a4a1255a141 100644 --- a/vendor/github.com/dop251/goja/builtin_promise.go +++ b/vendor/github.com/grafana/sobek/builtin_promise.go @@ -1,7 +1,7 @@ -package goja +package sobek import ( - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" "reflect" ) @@ -605,18 +605,18 @@ func (r *Runtime) wrapPromiseReaction(fObj *Object) func(interface{}) { // NewPromise creates and returns a Promise and resolving functions for it. // // WARNING: The returned values are not goroutine-safe and must not be called in parallel with VM running. -// In order to make use of this method you need an event loop such as the one in goja_nodejs (https://github.com/dop251/goja_nodejs) +// In order to make use of this method you need an event loop such as the one in sobek_nodejs (https://github.com/grafana/sobek_nodejs) // where it can be used like this: // // loop := NewEventLoop() // loop.Start() // defer loop.Stop() -// loop.RunOnLoop(func(vm *goja.Runtime) { +// loop.RunOnLoop(func(vm *sobek.Runtime) { // p, resolve, _ := vm.NewPromise() // vm.Set("p", p) // go func() { // time.Sleep(500 * time.Millisecond) // or perform any other blocking operation -// loop.RunOnLoop(func(*goja.Runtime) { // resolve() must be called on the loop, cannot call it here +// loop.RunOnLoop(func(*sobek.Runtime) { // resolve() must be called on the loop, cannot call it here // resolve(result) // }) // }() diff --git a/vendor/github.com/dop251/goja/builtin_proxy.go b/vendor/github.com/grafana/sobek/builtin_proxy.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_proxy.go rename to vendor/github.com/grafana/sobek/builtin_proxy.go index f589930677e..4ec5ba01745 100644 --- a/vendor/github.com/dop251/goja/builtin_proxy.go +++ b/vendor/github.com/grafana/sobek/builtin_proxy.go @@ -1,7 +1,7 @@ -package goja +package sobek import ( - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type nativeProxyHandler struct { diff --git a/vendor/github.com/dop251/goja/builtin_reflect.go b/vendor/github.com/grafana/sobek/builtin_reflect.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_reflect.go rename to vendor/github.com/grafana/sobek/builtin_reflect.go index 17bb11a36d6..8ee0d7cf5a7 100644 --- a/vendor/github.com/dop251/goja/builtin_reflect.go +++ b/vendor/github.com/grafana/sobek/builtin_reflect.go @@ -1,4 +1,4 @@ -package goja +package sobek func (r *Runtime) builtin_reflect_apply(call FunctionCall) Value { return r.toCallable(call.Argument(0))(FunctionCall{ diff --git a/vendor/github.com/dop251/goja/builtin_regexp.go b/vendor/github.com/grafana/sobek/builtin_regexp.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_regexp.go rename to vendor/github.com/grafana/sobek/builtin_regexp.go index 89402820e99..a606da0ce0e 100644 --- a/vendor/github.com/dop251/goja/builtin_regexp.go +++ b/vendor/github.com/grafana/sobek/builtin_regexp.go @@ -1,8 +1,8 @@ -package goja +package sobek import ( "fmt" - "github.com/dop251/goja/parser" + "github.com/grafana/sobek/parser" "regexp" "strings" "unicode/utf16" diff --git a/vendor/github.com/dop251/goja/builtin_set.go b/vendor/github.com/grafana/sobek/builtin_set.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_set.go rename to vendor/github.com/grafana/sobek/builtin_set.go index eeedb887c7f..45d956f1150 100644 --- a/vendor/github.com/dop251/goja/builtin_set.go +++ b/vendor/github.com/grafana/sobek/builtin_set.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "fmt" diff --git a/vendor/github.com/dop251/goja/builtin_string.go b/vendor/github.com/grafana/sobek/builtin_string.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_string.go rename to vendor/github.com/grafana/sobek/builtin_string.go index b2a0e4ea816..2343ed236fb 100644 --- a/vendor/github.com/dop251/goja/builtin_string.go +++ b/vendor/github.com/grafana/sobek/builtin_string.go @@ -1,14 +1,14 @@ -package goja +package sobek import ( - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" "math" "strings" "sync" "unicode/utf16" "unicode/utf8" - "github.com/dop251/goja/parser" + "github.com/grafana/sobek/parser" "golang.org/x/text/collate" "golang.org/x/text/language" "golang.org/x/text/unicode/norm" diff --git a/vendor/github.com/dop251/goja/builtin_symbol.go b/vendor/github.com/grafana/sobek/builtin_symbol.go similarity index 98% rename from vendor/github.com/dop251/goja/builtin_symbol.go rename to vendor/github.com/grafana/sobek/builtin_symbol.go index 8231b7bfcb7..b0c5fc86721 100644 --- a/vendor/github.com/dop251/goja/builtin_symbol.go +++ b/vendor/github.com/grafana/sobek/builtin_symbol.go @@ -1,6 +1,6 @@ -package goja +package sobek -import "github.com/dop251/goja/unistring" +import "github.com/grafana/sobek/unistring" var ( SymHasInstance = newSymbol(asciiString("Symbol.hasInstance")) diff --git a/vendor/github.com/dop251/goja/builtin_typedarrays.go b/vendor/github.com/grafana/sobek/builtin_typedarrays.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_typedarrays.go rename to vendor/github.com/grafana/sobek/builtin_typedarrays.go index 1fd672c147b..7ad737fceb0 100644 --- a/vendor/github.com/dop251/goja/builtin_typedarrays.go +++ b/vendor/github.com/grafana/sobek/builtin_typedarrays.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "fmt" @@ -7,7 +7,7 @@ import ( "sync" "unsafe" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type typedArraySortCtx struct { diff --git a/vendor/github.com/dop251/goja/builtin_weakmap.go b/vendor/github.com/grafana/sobek/builtin_weakmap.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_weakmap.go rename to vendor/github.com/grafana/sobek/builtin_weakmap.go index 40fc717db13..24bfdd2a41e 100644 --- a/vendor/github.com/dop251/goja/builtin_weakmap.go +++ b/vendor/github.com/grafana/sobek/builtin_weakmap.go @@ -1,4 +1,4 @@ -package goja +package sobek type weakMap uint64 diff --git a/vendor/github.com/dop251/goja/builtin_weakset.go b/vendor/github.com/grafana/sobek/builtin_weakset.go similarity index 99% rename from vendor/github.com/dop251/goja/builtin_weakset.go rename to vendor/github.com/grafana/sobek/builtin_weakset.go index cd8183e5912..e1f842ef0b0 100644 --- a/vendor/github.com/dop251/goja/builtin_weakset.go +++ b/vendor/github.com/grafana/sobek/builtin_weakset.go @@ -1,4 +1,4 @@ -package goja +package sobek type weakSetObject struct { baseObject diff --git a/vendor/github.com/dop251/goja/compiler.go b/vendor/github.com/grafana/sobek/compiler.go similarity index 99% rename from vendor/github.com/dop251/goja/compiler.go rename to vendor/github.com/grafana/sobek/compiler.go index 2abd9ba528b..edebf8c6ce9 100644 --- a/vendor/github.com/dop251/goja/compiler.go +++ b/vendor/github.com/grafana/sobek/compiler.go @@ -1,13 +1,13 @@ -package goja +package sobek import ( "fmt" - "github.com/dop251/goja/token" + "github.com/grafana/sobek/token" "sort" - "github.com/dop251/goja/ast" - "github.com/dop251/goja/file" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/ast" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/unistring" ) type blockType int diff --git a/vendor/github.com/dop251/goja/compiler_expr.go b/vendor/github.com/grafana/sobek/compiler_expr.go similarity index 99% rename from vendor/github.com/dop251/goja/compiler_expr.go rename to vendor/github.com/grafana/sobek/compiler_expr.go index 477580aecf6..69d37153cd5 100644 --- a/vendor/github.com/dop251/goja/compiler_expr.go +++ b/vendor/github.com/grafana/sobek/compiler_expr.go @@ -1,10 +1,10 @@ -package goja +package sobek import ( - "github.com/dop251/goja/ast" - "github.com/dop251/goja/file" - "github.com/dop251/goja/token" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/ast" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/token" + "github.com/grafana/sobek/unistring" ) type compiledExpr interface { diff --git a/vendor/github.com/dop251/goja/compiler_stmt.go b/vendor/github.com/grafana/sobek/compiler_stmt.go similarity index 99% rename from vendor/github.com/dop251/goja/compiler_stmt.go rename to vendor/github.com/grafana/sobek/compiler_stmt.go index 2d3d83b95e9..f9599b7e329 100644 --- a/vendor/github.com/dop251/goja/compiler_stmt.go +++ b/vendor/github.com/grafana/sobek/compiler_stmt.go @@ -1,10 +1,10 @@ -package goja +package sobek import ( - "github.com/dop251/goja/ast" - "github.com/dop251/goja/file" - "github.com/dop251/goja/token" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/ast" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/token" + "github.com/grafana/sobek/unistring" ) func (c *compiler) compileStatement(v ast.Statement, needResult bool) { diff --git a/vendor/github.com/dop251/goja/date.go b/vendor/github.com/grafana/sobek/date.go similarity index 99% rename from vendor/github.com/dop251/goja/date.go rename to vendor/github.com/grafana/sobek/date.go index ee29a21e7de..d06841db705 100644 --- a/vendor/github.com/dop251/goja/date.go +++ b/vendor/github.com/grafana/sobek/date.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "math" diff --git a/vendor/github.com/dop251/goja/date_parser.go b/vendor/github.com/grafana/sobek/date_parser.go similarity index 99% rename from vendor/github.com/dop251/goja/date_parser.go rename to vendor/github.com/grafana/sobek/date_parser.go index f8360532929..a956426d3d7 100644 --- a/vendor/github.com/dop251/goja/date_parser.go +++ b/vendor/github.com/grafana/sobek/date_parser.go @@ -1,4 +1,4 @@ -package goja +package sobek // This is a slightly modified version of the standard Go parser to make it more compatible with ECMAScript 5.1 // Changes: diff --git a/vendor/github.com/dop251/goja/destruct.go b/vendor/github.com/grafana/sobek/destruct.go similarity index 99% rename from vendor/github.com/dop251/goja/destruct.go rename to vendor/github.com/grafana/sobek/destruct.go index 66792dc3f65..01e457ace25 100644 --- a/vendor/github.com/dop251/goja/destruct.go +++ b/vendor/github.com/grafana/sobek/destruct.go @@ -1,7 +1,7 @@ -package goja +package sobek import ( - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" "reflect" ) diff --git a/vendor/github.com/dop251/goja/extract_failed_tests.sh b/vendor/github.com/grafana/sobek/extract_failed_tests.sh similarity index 100% rename from vendor/github.com/dop251/goja/extract_failed_tests.sh rename to vendor/github.com/grafana/sobek/extract_failed_tests.sh diff --git a/vendor/github.com/dop251/goja/file/README.markdown b/vendor/github.com/grafana/sobek/file/README.markdown similarity index 97% rename from vendor/github.com/dop251/goja/file/README.markdown rename to vendor/github.com/grafana/sobek/file/README.markdown index e9228c2f5e3..f64210029df 100644 --- a/vendor/github.com/dop251/goja/file/README.markdown +++ b/vendor/github.com/grafana/sobek/file/README.markdown @@ -1,6 +1,6 @@ # file -- - import "github.com/dop251/goja/file" + import "github.com/grafana/sobek/file" Package file encapsulates the file abstractions used by the ast & parser. diff --git a/vendor/github.com/dop251/goja/file/file.go b/vendor/github.com/grafana/sobek/file/file.go similarity index 100% rename from vendor/github.com/dop251/goja/file/file.go rename to vendor/github.com/grafana/sobek/file/file.go diff --git a/vendor/github.com/dop251/goja/ftoa/LICENSE_LUCENE b/vendor/github.com/grafana/sobek/ftoa/LICENSE_LUCENE similarity index 100% rename from vendor/github.com/dop251/goja/ftoa/LICENSE_LUCENE rename to vendor/github.com/grafana/sobek/ftoa/LICENSE_LUCENE diff --git a/vendor/github.com/dop251/goja/ftoa/common.go b/vendor/github.com/grafana/sobek/ftoa/common.go similarity index 100% rename from vendor/github.com/dop251/goja/ftoa/common.go rename to vendor/github.com/grafana/sobek/ftoa/common.go diff --git a/vendor/github.com/dop251/goja/ftoa/ftoa.go b/vendor/github.com/grafana/sobek/ftoa/ftoa.go similarity index 100% rename from vendor/github.com/dop251/goja/ftoa/ftoa.go rename to vendor/github.com/grafana/sobek/ftoa/ftoa.go diff --git a/vendor/github.com/dop251/goja/ftoa/ftobasestr.go b/vendor/github.com/grafana/sobek/ftoa/ftobasestr.go similarity index 100% rename from vendor/github.com/dop251/goja/ftoa/ftobasestr.go rename to vendor/github.com/grafana/sobek/ftoa/ftobasestr.go diff --git a/vendor/github.com/dop251/goja/ftoa/ftostr.go b/vendor/github.com/grafana/sobek/ftoa/ftostr.go similarity index 98% rename from vendor/github.com/dop251/goja/ftoa/ftostr.go rename to vendor/github.com/grafana/sobek/ftoa/ftostr.go index a9d2d240943..d1d9c3f1d97 100644 --- a/vendor/github.com/dop251/goja/ftoa/ftostr.go +++ b/vendor/github.com/grafana/sobek/ftoa/ftostr.go @@ -4,7 +4,7 @@ import ( "math" "strconv" - "github.com/dop251/goja/ftoa/internal/fast" + "github.com/grafana/sobek/ftoa/internal/fast" ) type FToStrMode int diff --git a/vendor/github.com/dop251/goja/ftoa/internal/fast/LICENSE_V8 b/vendor/github.com/grafana/sobek/ftoa/internal/fast/LICENSE_V8 similarity index 100% rename from vendor/github.com/dop251/goja/ftoa/internal/fast/LICENSE_V8 rename to vendor/github.com/grafana/sobek/ftoa/internal/fast/LICENSE_V8 diff --git a/vendor/github.com/dop251/goja/ftoa/internal/fast/cachedpower.go b/vendor/github.com/grafana/sobek/ftoa/internal/fast/cachedpower.go similarity index 100% rename from vendor/github.com/dop251/goja/ftoa/internal/fast/cachedpower.go rename to vendor/github.com/grafana/sobek/ftoa/internal/fast/cachedpower.go diff --git a/vendor/github.com/dop251/goja/ftoa/internal/fast/common.go b/vendor/github.com/grafana/sobek/ftoa/internal/fast/common.go similarity index 100% rename from vendor/github.com/dop251/goja/ftoa/internal/fast/common.go rename to vendor/github.com/grafana/sobek/ftoa/internal/fast/common.go diff --git a/vendor/github.com/dop251/goja/ftoa/internal/fast/diyfp.go b/vendor/github.com/grafana/sobek/ftoa/internal/fast/diyfp.go similarity index 100% rename from vendor/github.com/dop251/goja/ftoa/internal/fast/diyfp.go rename to vendor/github.com/grafana/sobek/ftoa/internal/fast/diyfp.go diff --git a/vendor/github.com/dop251/goja/ftoa/internal/fast/dtoa.go b/vendor/github.com/grafana/sobek/ftoa/internal/fast/dtoa.go similarity index 100% rename from vendor/github.com/dop251/goja/ftoa/internal/fast/dtoa.go rename to vendor/github.com/grafana/sobek/ftoa/internal/fast/dtoa.go diff --git a/vendor/github.com/dop251/goja/func.go b/vendor/github.com/grafana/sobek/func.go similarity index 99% rename from vendor/github.com/dop251/goja/func.go rename to vendor/github.com/grafana/sobek/func.go index c0469569664..ef7c846a2dd 100644 --- a/vendor/github.com/dop251/goja/func.go +++ b/vendor/github.com/grafana/sobek/func.go @@ -1,10 +1,10 @@ -package goja +package sobek import ( "fmt" "reflect" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type resultType uint8 diff --git a/vendor/github.com/dop251/goja/ipow.go b/vendor/github.com/grafana/sobek/ipow.go similarity index 99% rename from vendor/github.com/dop251/goja/ipow.go rename to vendor/github.com/grafana/sobek/ipow.go index 5ee0d4db917..1d9ef0c3722 100644 --- a/vendor/github.com/dop251/goja/ipow.go +++ b/vendor/github.com/grafana/sobek/ipow.go @@ -1,4 +1,4 @@ -package goja +package sobek // inspired by https://gist.github.com/orlp/3551590 diff --git a/vendor/github.com/dop251/goja/map.go b/vendor/github.com/grafana/sobek/map.go similarity index 99% rename from vendor/github.com/dop251/goja/map.go rename to vendor/github.com/grafana/sobek/map.go index b092b0d0494..26dd400cf87 100644 --- a/vendor/github.com/dop251/goja/map.go +++ b/vendor/github.com/grafana/sobek/map.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "hash/maphash" diff --git a/vendor/github.com/dop251/goja/object.go b/vendor/github.com/grafana/sobek/object.go similarity index 99% rename from vendor/github.com/dop251/goja/object.go rename to vendor/github.com/grafana/sobek/object.go index 79bd67df429..906fe42e9ce 100644 --- a/vendor/github.com/dop251/goja/object.go +++ b/vendor/github.com/grafana/sobek/object.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "fmt" @@ -6,7 +6,7 @@ import ( "reflect" "sort" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) const ( diff --git a/vendor/github.com/dop251/goja/object_args.go b/vendor/github.com/grafana/sobek/object_args.go similarity index 98% rename from vendor/github.com/dop251/goja/object_args.go rename to vendor/github.com/grafana/sobek/object_args.go index eb41d01ce04..3ef097fd281 100644 --- a/vendor/github.com/dop251/goja/object_args.go +++ b/vendor/github.com/grafana/sobek/object_args.go @@ -1,6 +1,6 @@ -package goja +package sobek -import "github.com/dop251/goja/unistring" +import "github.com/grafana/sobek/unistring" type argumentsObject struct { baseObject diff --git a/vendor/github.com/dop251/goja/object_dynamic.go b/vendor/github.com/grafana/sobek/object_dynamic.go similarity index 99% rename from vendor/github.com/dop251/goja/object_dynamic.go rename to vendor/github.com/grafana/sobek/object_dynamic.go index b1e3161e944..a2ebc978485 100644 --- a/vendor/github.com/dop251/goja/object_dynamic.go +++ b/vendor/github.com/grafana/sobek/object_dynamic.go @@ -1,11 +1,11 @@ -package goja +package sobek import ( "fmt" "reflect" "strconv" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) /* diff --git a/vendor/github.com/dop251/goja/object_goarray_reflect.go b/vendor/github.com/grafana/sobek/object_goarray_reflect.go similarity index 99% rename from vendor/github.com/dop251/goja/object_goarray_reflect.go rename to vendor/github.com/grafana/sobek/object_goarray_reflect.go index e40364db9e9..05bb5d4179b 100644 --- a/vendor/github.com/dop251/goja/object_goarray_reflect.go +++ b/vendor/github.com/grafana/sobek/object_goarray_reflect.go @@ -1,10 +1,10 @@ -package goja +package sobek import ( "reflect" "strconv" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type objectGoArrayReflect struct { diff --git a/vendor/github.com/dop251/goja/object_gomap.go b/vendor/github.com/grafana/sobek/object_gomap.go similarity index 98% rename from vendor/github.com/dop251/goja/object_gomap.go rename to vendor/github.com/grafana/sobek/object_gomap.go index 82138c28aaf..d526403ca56 100644 --- a/vendor/github.com/dop251/goja/object_gomap.go +++ b/vendor/github.com/grafana/sobek/object_gomap.go @@ -1,9 +1,9 @@ -package goja +package sobek import ( "reflect" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type objectGoMapSimple struct { diff --git a/vendor/github.com/dop251/goja/object_gomap_reflect.go b/vendor/github.com/grafana/sobek/object_gomap_reflect.go similarity index 99% rename from vendor/github.com/dop251/goja/object_gomap_reflect.go rename to vendor/github.com/grafana/sobek/object_gomap_reflect.go index 531c165243e..bf8b41a6bf2 100644 --- a/vendor/github.com/dop251/goja/object_gomap_reflect.go +++ b/vendor/github.com/grafana/sobek/object_gomap_reflect.go @@ -1,9 +1,9 @@ -package goja +package sobek import ( "reflect" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type objectGoMapReflect struct { diff --git a/vendor/github.com/dop251/goja/object_goreflect.go b/vendor/github.com/grafana/sobek/object_goreflect.go similarity index 98% rename from vendor/github.com/dop251/goja/object_goreflect.go rename to vendor/github.com/grafana/sobek/object_goreflect.go index f8ca6d05a6f..143fc5cd20b 100644 --- a/vendor/github.com/dop251/goja/object_goreflect.go +++ b/vendor/github.com/grafana/sobek/object_goreflect.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "fmt" @@ -6,8 +6,8 @@ import ( "reflect" "strings" - "github.com/dop251/goja/parser" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/parser" + "github.com/grafana/sobek/unistring" ) // JsonEncodable allows custom JSON encoding by JSON.stringify() @@ -535,17 +535,14 @@ func (r *Runtime) buildFieldInfo(t reflect.Type, index []int, info *reflectField for i := 0; i < n; i++ { field := t.Field(i) name := field.Name - isExported := ast.IsExported(name) - - if !isExported && !field.Anonymous { + if !ast.IsExported(name) { continue } - if r.fieldNameMapper != nil { name = r.fieldNameMapper.FieldName(t, field) } - if name != "" && isExported { + if name != "" { if inf, exists := info.Fields[name]; !exists { info.Names = append(info.Names, name) } else { @@ -560,7 +557,7 @@ func (r *Runtime) buildFieldInfo(t reflect.Type, index []int, info *reflectField copy(idx, index) idx[len(idx)-1] = i - if name != "" && isExported { + if name != "" { info.Fields[name] = reflectFieldInfo{ Index: idx, Anonymous: field.Anonymous, diff --git a/vendor/github.com/dop251/goja/object_goslice.go b/vendor/github.com/grafana/sobek/object_goslice.go similarity index 99% rename from vendor/github.com/dop251/goja/object_goslice.go rename to vendor/github.com/grafana/sobek/object_goslice.go index 1a5220746d8..7f71dfdfb17 100644 --- a/vendor/github.com/dop251/goja/object_goslice.go +++ b/vendor/github.com/grafana/sobek/object_goslice.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "math" @@ -6,7 +6,7 @@ import ( "reflect" "strconv" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type objectGoSlice struct { diff --git a/vendor/github.com/dop251/goja/object_goslice_reflect.go b/vendor/github.com/grafana/sobek/object_goslice_reflect.go similarity index 97% rename from vendor/github.com/dop251/goja/object_goslice_reflect.go rename to vendor/github.com/grafana/sobek/object_goslice_reflect.go index 4c28d8cd00f..378322a4d2c 100644 --- a/vendor/github.com/dop251/goja/object_goslice_reflect.go +++ b/vendor/github.com/grafana/sobek/object_goslice_reflect.go @@ -1,11 +1,11 @@ -package goja +package sobek import ( "math" "math/bits" "reflect" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type objectGoSliceReflect struct { diff --git a/vendor/github.com/dop251/goja/object_template.go b/vendor/github.com/grafana/sobek/object_template.go similarity index 99% rename from vendor/github.com/dop251/goja/object_template.go rename to vendor/github.com/grafana/sobek/object_template.go index 6d42f9f9805..fa39133b084 100644 --- a/vendor/github.com/dop251/goja/object_template.go +++ b/vendor/github.com/grafana/sobek/object_template.go @@ -1,8 +1,8 @@ -package goja +package sobek import ( "fmt" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" "math" "reflect" "sort" diff --git a/vendor/github.com/dop251/goja/parser/README.markdown b/vendor/github.com/grafana/sobek/parser/README.markdown similarity index 97% rename from vendor/github.com/dop251/goja/parser/README.markdown rename to vendor/github.com/grafana/sobek/parser/README.markdown index ec1186d4638..3d19db26957 100644 --- a/vendor/github.com/dop251/goja/parser/README.markdown +++ b/vendor/github.com/grafana/sobek/parser/README.markdown @@ -1,11 +1,11 @@ # parser -- - import "github.com/dop251/goja/parser" + import "github.com/grafana/sobek/parser" Package parser implements a parser for JavaScript. Borrowed from https://github.com/robertkrimen/otto/tree/master/parser import ( - "github.com/dop251/goja/parser" + "github.com/grafana/sobek/parser" ) Parse and return an AST diff --git a/vendor/github.com/dop251/goja/parser/error.go b/vendor/github.com/grafana/sobek/parser/error.go similarity index 98% rename from vendor/github.com/dop251/goja/parser/error.go rename to vendor/github.com/grafana/sobek/parser/error.go index cf4d2c3810a..39d61fa7747 100644 --- a/vendor/github.com/dop251/goja/parser/error.go +++ b/vendor/github.com/grafana/sobek/parser/error.go @@ -4,8 +4,8 @@ import ( "fmt" "sort" - "github.com/dop251/goja/file" - "github.com/dop251/goja/token" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/token" ) const ( diff --git a/vendor/github.com/dop251/goja/parser/expression.go b/vendor/github.com/grafana/sobek/parser/expression.go similarity index 99% rename from vendor/github.com/dop251/goja/parser/expression.go rename to vendor/github.com/grafana/sobek/parser/expression.go index 305bed499fb..74d346a014c 100644 --- a/vendor/github.com/dop251/goja/parser/expression.go +++ b/vendor/github.com/grafana/sobek/parser/expression.go @@ -3,10 +3,10 @@ package parser import ( "strings" - "github.com/dop251/goja/ast" - "github.com/dop251/goja/file" - "github.com/dop251/goja/token" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/ast" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/token" + "github.com/grafana/sobek/unistring" ) func (self *_parser) parseIdentifier() *ast.Identifier { diff --git a/vendor/github.com/dop251/goja/parser/lexer.go b/vendor/github.com/grafana/sobek/parser/lexer.go similarity index 99% rename from vendor/github.com/dop251/goja/parser/lexer.go rename to vendor/github.com/grafana/sobek/parser/lexer.go index 68d56d20b1b..234d5b963bb 100644 --- a/vendor/github.com/dop251/goja/parser/lexer.go +++ b/vendor/github.com/grafana/sobek/parser/lexer.go @@ -11,9 +11,9 @@ import ( "golang.org/x/text/unicode/rangetable" - "github.com/dop251/goja/file" - "github.com/dop251/goja/token" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/token" + "github.com/grafana/sobek/unistring" ) var ( diff --git a/vendor/github.com/dop251/goja/parser/parser.go b/vendor/github.com/grafana/sobek/parser/parser.go similarity index 97% rename from vendor/github.com/dop251/goja/parser/parser.go rename to vendor/github.com/grafana/sobek/parser/parser.go index 24b380249f5..9adfe3ab877 100644 --- a/vendor/github.com/dop251/goja/parser/parser.go +++ b/vendor/github.com/grafana/sobek/parser/parser.go @@ -2,7 +2,7 @@ Package parser implements a parser for JavaScript. import ( - "github.com/dop251/goja/parser" + "github.com/grafana/sobek/parser" ) Parse and return an AST @@ -38,10 +38,10 @@ import ( "io" "os" - "github.com/dop251/goja/ast" - "github.com/dop251/goja/file" - "github.com/dop251/goja/token" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/ast" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/token" + "github.com/grafana/sobek/unistring" ) // A Mode value is a set of flags (or 0). They control optional parser functionality. diff --git a/vendor/github.com/dop251/goja/parser/regexp.go b/vendor/github.com/grafana/sobek/parser/regexp.go similarity index 100% rename from vendor/github.com/dop251/goja/parser/regexp.go rename to vendor/github.com/grafana/sobek/parser/regexp.go diff --git a/vendor/github.com/dop251/goja/parser/scope.go b/vendor/github.com/grafana/sobek/parser/scope.go similarity index 93% rename from vendor/github.com/dop251/goja/parser/scope.go rename to vendor/github.com/grafana/sobek/parser/scope.go index 5e28ef46756..f9936dafbfe 100644 --- a/vendor/github.com/dop251/goja/parser/scope.go +++ b/vendor/github.com/grafana/sobek/parser/scope.go @@ -1,8 +1,8 @@ package parser import ( - "github.com/dop251/goja/ast" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/ast" + "github.com/grafana/sobek/unistring" ) type _scope struct { diff --git a/vendor/github.com/dop251/goja/parser/statement.go b/vendor/github.com/grafana/sobek/parser/statement.go similarity index 99% rename from vendor/github.com/dop251/goja/parser/statement.go rename to vendor/github.com/grafana/sobek/parser/statement.go index 8ec5cdeb770..03e1de46632 100644 --- a/vendor/github.com/dop251/goja/parser/statement.go +++ b/vendor/github.com/grafana/sobek/parser/statement.go @@ -6,10 +6,10 @@ import ( "os" "strings" - "github.com/dop251/goja/ast" - "github.com/dop251/goja/file" - "github.com/dop251/goja/token" "github.com/go-sourcemap/sourcemap" + "github.com/grafana/sobek/ast" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/token" ) func (self *_parser) parseBlockStatement() *ast.BlockStatement { diff --git a/vendor/github.com/dop251/goja/profiler.go b/vendor/github.com/grafana/sobek/profiler.go similarity index 99% rename from vendor/github.com/dop251/goja/profiler.go rename to vendor/github.com/grafana/sobek/profiler.go index 3d21ad1d95e..01a33b14c96 100644 --- a/vendor/github.com/dop251/goja/profiler.go +++ b/vendor/github.com/grafana/sobek/profiler.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "errors" diff --git a/vendor/github.com/dop251/goja/proxy.go b/vendor/github.com/grafana/sobek/proxy.go similarity index 99% rename from vendor/github.com/dop251/goja/proxy.go rename to vendor/github.com/grafana/sobek/proxy.go index e9bd8c96752..0662cde9d29 100644 --- a/vendor/github.com/dop251/goja/proxy.go +++ b/vendor/github.com/grafana/sobek/proxy.go @@ -1,10 +1,10 @@ -package goja +package sobek import ( "fmt" "reflect" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) // Proxy is a Go wrapper around ECMAScript Proxy. Calling Runtime.ToValue() on it diff --git a/vendor/github.com/dop251/goja/regexp.go b/vendor/github.com/grafana/sobek/regexp.go similarity index 99% rename from vendor/github.com/dop251/goja/regexp.go rename to vendor/github.com/grafana/sobek/regexp.go index 1c3e7e06dad..bdc15a1cb97 100644 --- a/vendor/github.com/dop251/goja/regexp.go +++ b/vendor/github.com/grafana/sobek/regexp.go @@ -1,9 +1,9 @@ -package goja +package sobek import ( "fmt" "github.com/dlclark/regexp2" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" "io" "regexp" "sort" diff --git a/vendor/github.com/dop251/goja/runtime.go b/vendor/github.com/grafana/sobek/runtime.go similarity index 99% rename from vendor/github.com/dop251/goja/runtime.go rename to vendor/github.com/grafana/sobek/runtime.go index e9a500da5a2..27404f594e0 100644 --- a/vendor/github.com/dop251/goja/runtime.go +++ b/vendor/github.com/grafana/sobek/runtime.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "bytes" @@ -16,10 +16,10 @@ import ( "golang.org/x/text/collate" - js_ast "github.com/dop251/goja/ast" - "github.com/dop251/goja/file" - "github.com/dop251/goja/parser" - "github.com/dop251/goja/unistring" + js_ast "github.com/grafana/sobek/ast" + "github.com/grafana/sobek/file" + "github.com/grafana/sobek/parser" + "github.com/grafana/sobek/unistring" ) const ( @@ -386,13 +386,11 @@ func (e *Exception) String() string { } func (e *Exception) Error() string { - if e == nil { + if e == nil || e.val == nil { return "" } var b bytes.Buffer - if e.val != nil { - b.WriteString(e.val.String()) - } + b.WriteString(e.val.String()) e.writeShortStack(&b) return b.String() } @@ -413,10 +411,6 @@ func (e *Exception) Unwrap() error { return nil } -func (e *Exception) Stack() []StackFrame { - return e.stack -} - func (r *Runtime) createIterProto(val *Object) objectImpl { o := newBaseObjectObj(val, r.global.ObjectPrototype, classObject) @@ -1619,7 +1613,7 @@ func(FunctionCall, *Runtime) Value is treated as above, except the *Runtime is a func(ConstructorCall) *Object is treated as a native constructor, allowing to use it with the new operator: - func MyObject(call goja.ConstructorCall) *goja.Object { + func MyObject(call sobek.ConstructorCall) *sobek.Object { // call.This contains the newly created object as per http://www.ecma-international.org/ecma-262/5.1/index.html#sec-13.2.2 // call.Arguments contain arguments passed to the function @@ -1629,7 +1623,7 @@ operator: // If return value is a non-nil *Object, it will be used instead of call.This // This way it is possible to return a Go struct or a map converted - // into goja.Value using ToValue(), however in this case + // into sobek.Value using ToValue(), however in this case // instanceof will not work as expected, unless you set the prototype: // // instance := &myCustomStruct{} diff --git a/vendor/github.com/dop251/goja/staticcheck.conf b/vendor/github.com/grafana/sobek/staticcheck.conf similarity index 100% rename from vendor/github.com/dop251/goja/staticcheck.conf rename to vendor/github.com/grafana/sobek/staticcheck.conf diff --git a/vendor/github.com/dop251/goja/string.go b/vendor/github.com/grafana/sobek/string.go similarity index 99% rename from vendor/github.com/dop251/goja/string.go rename to vendor/github.com/grafana/sobek/string.go index 632f1e3b547..833bc3aa448 100644 --- a/vendor/github.com/dop251/goja/string.go +++ b/vendor/github.com/grafana/sobek/string.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "io" @@ -6,7 +6,7 @@ import ( "strings" "unicode/utf8" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) const ( diff --git a/vendor/github.com/dop251/goja/string_ascii.go b/vendor/github.com/grafana/sobek/string_ascii.go similarity index 99% rename from vendor/github.com/dop251/goja/string_ascii.go rename to vendor/github.com/grafana/sobek/string_ascii.go index 5ff21bf7b79..df622f41c3a 100644 --- a/vendor/github.com/dop251/goja/string_ascii.go +++ b/vendor/github.com/grafana/sobek/string_ascii.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "hash/maphash" @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type asciiString string diff --git a/vendor/github.com/dop251/goja/string_imported.go b/vendor/github.com/grafana/sobek/string_imported.go similarity index 98% rename from vendor/github.com/dop251/goja/string_imported.go rename to vendor/github.com/grafana/sobek/string_imported.go index 1c6cae88d09..e61cb77c41d 100644 --- a/vendor/github.com/dop251/goja/string_imported.go +++ b/vendor/github.com/grafana/sobek/string_imported.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "hash/maphash" @@ -9,8 +9,8 @@ import ( "unicode/utf16" "unicode/utf8" - "github.com/dop251/goja/parser" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/parser" + "github.com/grafana/sobek/unistring" "golang.org/x/text/cases" "golang.org/x/text/language" diff --git a/vendor/github.com/dop251/goja/string_unicode.go b/vendor/github.com/grafana/sobek/string_unicode.go similarity index 99% rename from vendor/github.com/dop251/goja/string_unicode.go rename to vendor/github.com/grafana/sobek/string_unicode.go index 49e363fe8f9..b755978cc62 100644 --- a/vendor/github.com/dop251/goja/string_unicode.go +++ b/vendor/github.com/grafana/sobek/string_unicode.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "errors" @@ -10,8 +10,8 @@ import ( "unicode/utf16" "unicode/utf8" - "github.com/dop251/goja/parser" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/parser" + "github.com/grafana/sobek/unistring" "golang.org/x/text/cases" "golang.org/x/text/language" ) diff --git a/vendor/github.com/dop251/goja/token/README.markdown b/vendor/github.com/grafana/sobek/token/README.markdown similarity index 98% rename from vendor/github.com/dop251/goja/token/README.markdown rename to vendor/github.com/grafana/sobek/token/README.markdown index 66dd2abde71..7b643660c13 100644 --- a/vendor/github.com/dop251/goja/token/README.markdown +++ b/vendor/github.com/grafana/sobek/token/README.markdown @@ -1,6 +1,6 @@ # token -- - import "github.com/dop251/goja/token" + import "github.com/grafana/sobek/token" Package token defines constants representing the lexical tokens of JavaScript (ECMA5). diff --git a/vendor/github.com/dop251/goja/token/token.go b/vendor/github.com/grafana/sobek/token/token.go similarity index 100% rename from vendor/github.com/dop251/goja/token/token.go rename to vendor/github.com/grafana/sobek/token/token.go diff --git a/vendor/github.com/dop251/goja/token/token_const.go b/vendor/github.com/grafana/sobek/token/token_const.go similarity index 100% rename from vendor/github.com/dop251/goja/token/token_const.go rename to vendor/github.com/grafana/sobek/token/token_const.go diff --git a/vendor/github.com/dop251/goja/token/tokenfmt b/vendor/github.com/grafana/sobek/token/tokenfmt similarity index 100% rename from vendor/github.com/dop251/goja/token/tokenfmt rename to vendor/github.com/grafana/sobek/token/tokenfmt diff --git a/vendor/github.com/dop251/goja/typedarrays.go b/vendor/github.com/grafana/sobek/typedarrays.go similarity index 99% rename from vendor/github.com/dop251/goja/typedarrays.go rename to vendor/github.com/grafana/sobek/typedarrays.go index 9af03503dbb..cfe19bc66d3 100644 --- a/vendor/github.com/dop251/goja/typedarrays.go +++ b/vendor/github.com/grafana/sobek/typedarrays.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "math" @@ -6,7 +6,7 @@ import ( "strconv" "unsafe" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) type byteOrder bool diff --git a/vendor/github.com/dop251/goja/unistring/string.go b/vendor/github.com/grafana/sobek/unistring/string.go similarity index 100% rename from vendor/github.com/dop251/goja/unistring/string.go rename to vendor/github.com/grafana/sobek/unistring/string.go diff --git a/vendor/github.com/dop251/goja/value.go b/vendor/github.com/grafana/sobek/value.go similarity index 99% rename from vendor/github.com/dop251/goja/value.go rename to vendor/github.com/grafana/sobek/value.go index aeb96762c8f..9faabefbf96 100644 --- a/vendor/github.com/dop251/goja/value.go +++ b/vendor/github.com/grafana/sobek/value.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "fmt" @@ -8,8 +8,8 @@ import ( "strconv" "unsafe" - "github.com/dop251/goja/ftoa" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/ftoa" + "github.com/grafana/sobek/unistring" ) var ( diff --git a/vendor/github.com/dop251/goja/vm.go b/vendor/github.com/grafana/sobek/vm.go similarity index 99% rename from vendor/github.com/dop251/goja/vm.go rename to vendor/github.com/grafana/sobek/vm.go index 30b79331628..8fa60e4c8a3 100644 --- a/vendor/github.com/dop251/goja/vm.go +++ b/vendor/github.com/grafana/sobek/vm.go @@ -1,4 +1,4 @@ -package goja +package sobek import ( "fmt" @@ -9,7 +9,7 @@ import ( "sync/atomic" "time" - "github.com/dop251/goja/unistring" + "github.com/grafana/sobek/unistring" ) const ( diff --git a/vendor/modules.txt b/vendor/modules.txt index 8ac8bdb447b..dccde99b177 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -105,16 +105,6 @@ github.com/dgryski/go-rendezvous ## explicit; go 1.13 github.com/dlclark/regexp2 github.com/dlclark/regexp2/syntax -# github.com/dop251/goja v0.0.0-20240610225006-393f6d42497b -## explicit; go 1.20 -github.com/dop251/goja -github.com/dop251/goja/ast -github.com/dop251/goja/file -github.com/dop251/goja/ftoa -github.com/dop251/goja/ftoa/internal/fast -github.com/dop251/goja/parser -github.com/dop251/goja/token -github.com/dop251/goja/unistring # github.com/evanw/esbuild v0.21.2 ## explicit; go 1.13 github.com/evanw/esbuild/internal/api_helpers @@ -173,9 +163,16 @@ github.com/google/uuid # github.com/gorilla/websocket v1.5.1 ## explicit; go 1.20 github.com/gorilla/websocket -# github.com/grafana/sobek v0.0.0-20240613124309-cb36746e8fee +# github.com/grafana/sobek v0.0.0-20240611084759-1a77bdaf1a4a ## explicit; go 1.20 github.com/grafana/sobek +github.com/grafana/sobek/ast +github.com/grafana/sobek/file +github.com/grafana/sobek/ftoa +github.com/grafana/sobek/ftoa/internal/fast +github.com/grafana/sobek/parser +github.com/grafana/sobek/token +github.com/grafana/sobek/unistring # github.com/grafana/xk6-browser v1.6.0 ## explicit; go 1.20 github.com/grafana/xk6-browser/browser