diff --git a/Dependencies.md b/Dependencies.md index 3fb8a7f1087..7c4e704b2f6 100644 --- a/Dependencies.md +++ b/Dependencies.md @@ -18,7 +18,7 @@ Through the rest of the development cycle dependencies shouldn't be updated unle The last part predominantly goes for `golang.org/x/*` and particularly `golang.org/x/net` which usually have updates through the development of Go itself. -[Goja](https://github.com/dop251/goja) has special considerations as it's heavily used and bug fixes there or new features usually have high impact on k6. Which means that we usually try to update it whenever something new lands there. +[Sobek](https://github.com/grafana/sobek) has special considerations as it's heavily used and bug fixes there or new features usually have high impact on k6. Which means that we usually try to update it whenever something new lands there. As the stability of any k6 release is pretty essential, this should be done only when adequate testing can be done, and in general, the changelog for each dependency should be consulted on what has changed. @@ -55,10 +55,10 @@ You can use the command `modtools check --direct-only` provided you, to update i Commit dependencies one by one with a message like `Update from vX.Y.Z to vX.Y.Z` and a relevant changelog for k6. Sometimes that means "nothing of relevance for k6", sometimes it means a list of bug fixes or new features. It's preferable to make multiple PRs - in most cases you can split them in three: -- update for goja - which usually needs to happen. +- update for Sobek - which usually needs to happen. - update for `golang.org/x/*` - also again happen literally every release - everything else - this in general doesn't include more than 5-6 small updates. Further splitting is recommended if PRs become too big. -When updating goja it's recommended to run the tc39 tests in `js/tc39`. And if needed, update the breaking ones as explained in an [Introduction to a k6's TC39 testing](./js/tc39/README.md). +When updating Sobek it's recommended to run the tc39 tests in `js/tc39`. And if needed, update the breaking ones as explained in an [Introduction to a k6's TC39 testing](./js/tc39/README.md). diff --git a/cmd/runtime_options.go b/cmd/runtime_options.go index 61e67cfdf0c..a636b2825fe 100644 --- a/cmd/runtime_options.go +++ b/cmd/runtime_options.go @@ -24,7 +24,7 @@ func runtimeOptionFlagSet(includeSysEnv bool) *pflag.FlagSet { flags.Bool("include-system-env-vars", includeSysEnv, "pass the real system environment variables to the runtime") flags.String("compatibility-mode", "extended", `JavaScript compiler compatibility mode, "extended" or "base" or "experimental_enhanced" -base: pure goja - Golang JS VM supporting ES5.1+ +base: pure Sobek - Golang JS VM supporting ES5.1+ extended: base + Babel with parts of ES2015 preset slower to compile in case the script uses syntax unsupported by base experimental_enhanced: esbuild-based transpiling for TypeScript and ES6+ support 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/common/bridge.go b/js/common/bridge.go index 5535ed161fd..6ac794b07e7 100644 --- a/js/common/bridge.go +++ b/js/common/bridge.go @@ -71,11 +71,11 @@ func MethodName(_ reflect.Type, m reflect.Method) string { type FieldNameMapper struct{} // FieldName is part of the sobek.FieldNameMapper interface -// https://godoc.org/github.com/dop251/goja#FieldNameMapper +// https://godoc.org/github.com/grafana/sobek#FieldNameMapper func (FieldNameMapper) FieldName(t reflect.Type, f reflect.StructField) string { return FieldName(t, f) } // MethodName is part of the sobek.FieldNameMapper interface -// https://godoc.org/github.com/dop251/goja#FieldNameMapper +// https://godoc.org/github.com/grafana/sobek#FieldNameMapper func (FieldNameMapper) MethodName(t reflect.Type, m reflect.Method) string { return MethodName(t, m) } diff --git a/js/common/interrupt_error.go b/js/common/interrupt_error.go index 0ed89f3239d..08ce051ade9 100644 --- a/js/common/interrupt_error.go +++ b/js/common/interrupt_error.go @@ -6,11 +6,11 @@ import ( "github.com/grafana/sobek" ) -// UnwrapGojaInterruptedError returns the internal error handled by sobek. +// UnwrapGojaInterruptedError returns the internal error handled by Sobek. func UnwrapGojaInterruptedError(err error) error { - var gojaErr *sobek.InterruptedError - if errors.As(err, &gojaErr) { - if e, ok := gojaErr.Value().(error); ok { + var sobekErr *sobek.InterruptedError + if errors.As(err, &sobekErr) { + if e, ok := sobekErr.Value().(error); ok { return e } } diff --git a/js/common/randsource.go b/js/common/randsource.go index 141e547071a..37ef398faa6 100644 --- a/js/common/randsource.go +++ b/js/common/randsource.go @@ -9,8 +9,8 @@ import ( "github.com/grafana/sobek" ) -// NewRandSource is copied from goja's source code: -// https://github.com/dop251/goja/blob/master/goja/main.go#L44 +// NewRandSource is copied from Sobek's source code: +// https://github.com/grafana/sobek/blob/master/sobek/main.go#L44 // The returned RandSource is NOT safe for concurrent use: // https://golang.org/pkg/math/rand/#NewSource func NewRandSource() sobek.RandSource { diff --git a/js/common/util.go b/js/common/util.go index 94e8cff0387..b1b1a46137f 100644 --- a/js/common/util.go +++ b/js/common/util.go @@ -17,7 +17,7 @@ func Throw(rt *sobek.Runtime, err error) { panic(rt.NewGoError(err)) // this catches the stack unlike rt.ToValue } -// GetReader tries to return an io.Reader value from an exported goja value. +// GetReader tries to return an io.Reader value from an exported Sobek value. func GetReader(data interface{}) (io.Reader, error) { switch r := data.(type) { case string: diff --git a/js/compiler/compiler.go b/js/compiler/compiler.go index 27860a5cb9b..1fed51109a4 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" @@ -30,26 +30,26 @@ var ( // "presets": []string{"latest"}, "plugins": []interface{}{ // es2015 https://github.com/babel/babel/blob/v6.26.0/packages/babel-preset-es2015/src/index.js - // in goja + // in Sobek // []interface{}{"transform-es2015-template-literals", map[string]interface{}{"loose": false, "spec": false}}, - // "transform-es2015-literals", // in goja - // "transform-es2015-function-name", // in goja - // []interface{}{"transform-es2015-arrow-functions", map[string]interface{}{"spec": false}}, // in goja - // "transform-es2015-block-scoped-functions", // in goja - // []interface{}{"transform-es2015-classes", map[string]interface{}{"loose": false}}, // in goja - // "transform-es2015-object-super", // in goja - // "transform-es2015-shorthand-properties", // in goja - // "transform-es2015-duplicate-keys", // in goja - // []interface{}{"transform-es2015-computed-properties", map[string]interface{}{"loose": false}}, // in goja - // "transform-es2015-for-of", // in goja - // "transform-es2015-sticky-regex", // in goja - // "transform-es2015-unicode-regex", // in goja - // "check-es2015-constants", // in goja - // []interface{}{"transform-es2015-spread", map[string]interface{}{"loose": false}}, // in goja - // "transform-es2015-parameters", // in goja - // []interface{}{"transform-es2015-destructuring", map[string]interface{}{"loose": false}}, // in goja - // "transform-es2015-block-scoping", // in goja - // "transform-es2015-typeof-symbol", // in goja + // "transform-es2015-literals", // in Sobek + // "transform-es2015-function-name", // in Sobek + // []interface{}{"transform-es2015-arrow-functions", map[string]interface{}{"spec": false}}, // in Sobek + // "transform-es2015-block-scoped-functions", // in Sobek + // []interface{}{"transform-es2015-classes", map[string]interface{}{"loose": false}}, // in Sobek + // "transform-es2015-object-super", // in Sobek + // "transform-es2015-shorthand-properties", // in Sobek + // "transform-es2015-duplicate-keys", // in Sobek + // []interface{}{"transform-es2015-computed-properties", map[string]interface{}{"loose": false}}, // in Sobek + // "transform-es2015-for-of", // in Sobek + // "transform-es2015-sticky-regex", // in Sobek + // "transform-es2015-unicode-regex", // in Sobek + // "check-es2015-constants", // in Sobek + // []interface{}{"transform-es2015-spread", map[string]interface{}{"loose": false}}, // in Sobek + // "transform-es2015-parameters", // in Sobek + // []interface{}{"transform-es2015-destructuring", map[string]interface{}{"loose": false}}, // in Sobek + // "transform-es2015-block-scoping", // in Sobek + // "transform-es2015-typeof-symbol", // in Sobek // all the other module plugins are just dropped []interface{}{"transform-es2015-modules-commonjs", map[string]interface{}{"loose": false}}, // "transform-regenerator", // Doesn't really work unless regeneratorRuntime is also added @@ -58,7 +58,7 @@ var ( // "transform-exponentiation-operator", // es2017 https://github.com/babel/babel/blob/v6.26.0/packages/babel-preset-es2017/src/index.js - // "syntax-trailing-function-commas", // in goja + // "syntax-trailing-function-commas", // in Sobek // "transform-async-to-generator", // Doesn't really work unless regeneratorRuntime is also added }, "ast": false, @@ -172,12 +172,12 @@ type compilationState struct { } // Compile the program in the given CompatibilityMode, wrapping it between pre and post code -// TODO isESM will be used once goja support ESM modules natively +// TODO isESM will be used once Sobek support ESM modules natively func (c *Compiler) Compile(src, filename string, isESM bool) (*sobek.Program, string, error) { return c.compileImpl(src, filename, !isESM, c.Options.CompatibilityMode, nil) } -// sourceMapLoader is to be used with goja's WithSourceMapLoader +// sourceMapLoader is to be used with Sobek's WithSourceMapLoader // it not only gets the file from disk in the simple case, but also returns it if the map was generated from babel // additioanlly it fixes off by one error in commonjs dependencies due to having to wrap them in a function. func (c *compilationState) sourceMapLoader(path string) ([]byte, error) { @@ -406,7 +406,7 @@ func (b *babel) transformImpl( return code, nil, nil } - // this is to make goja try to load a sourcemap. + // this is to make Sobek try to load a sourcemap. // it is a special url as it should never leak outside of this code // additionally the alternative support from babel is to embed *the whole* sourcemap at the end code += "\n//# sourceMappingURL=" + sourceMapURLFromBabel 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/eventloop/eventloop.go b/js/eventloop/eventloop.go index 09a11cf60e5..038326c80ba 100644 --- a/js/eventloop/eventloop.go +++ b/js/eventloop/eventloop.go @@ -108,7 +108,7 @@ func (e *EventLoop) wakeup() { // This ensures that the actual work happens asynchronously, while the Promise // is immediately returned and the main thread resumes execution. It also // ensures that the Promise resolution happens safely back on the main thread -// once the async work is done, as required by goja and all other JS runtimes. +// once the async work is done, as required by Sobek and all other JS runtimes. // // TODO: rename to ReservePendingCallback or something more appropriate? func (e *EventLoop) RegisterCallback() (enqueueCallback func(func() error)) { @@ -132,7 +132,7 @@ func (e *EventLoop) RegisterCallback() (enqueueCallback func(func() error)) { } func (e *EventLoop) promiseRejectionTracker(p *sobek.Promise, op sobek.PromiseRejectionOperation) { - // No locking necessary here as the goja runtime will call this synchronously + // No locking necessary here as the Sobek runtime will call this synchronously // Read Notes on https://tc39.es/ecma262/#sec-host-promise-rejection-tracker if op == sobek.PromiseRejectionReject { e.pendingPromiseRejections[p] = struct{}{} diff --git a/js/modules/k6/data/data.go b/js/modules/k6/data/data.go index 9e5ad78fa8b..a67f1a9c7ba 100644 --- a/js/modules/k6/data/data.go +++ b/js/modules/k6/data/data.go @@ -111,11 +111,11 @@ func (s *sharedArrays) get(rt *sobek.Runtime, name string, call sobek.Callable) } func getShareArrayFromCall(rt *sobek.Runtime, call sobek.Callable) sharedArray { - gojaValue, err := call(sobek.Undefined()) + sobekValue, err := call(sobek.Undefined()) if err != nil { common.Throw(rt, err) } - obj := gojaValue.ToObject(rt) + obj := sobekValue.ToObject(rt) if obj.ClassName() != "Array" { common.Throw(rt, errors.New("only arrays can be made into SharedArray")) // TODO better error } diff --git a/js/modules/k6/execution/execution.go b/js/modules/k6/execution/execution.go index 6393b1d9c2f..236c177e73b 100644 --- a/js/modules/k6/execution/execution.go +++ b/js/modules/k6/execution/execution.go @@ -353,7 +353,7 @@ func (o *tagsDynamicObject) Get(key string) sobek.Value { } // Set a property value for the key. It returns true if succeed. String, Boolean -// and Number types are implicitly converted to the goja's relative string +// and Number types are implicitly converted to the Sobek's relative string // representation. An exception is raised in case a denied type is provided. func (o *tagsDynamicObject) Set(key string, val sobek.Value) bool { o.state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { @@ -410,7 +410,7 @@ func (o *metadataDynamicObject) Get(key string) sobek.Value { } // Set a property value for the key. It returns true if successful. String, Boolean -// and Number types are implicitly converted to the goja's relative string +// and Number types are implicitly converted to the Sobek's relative string // representation. An exception is raised in case a denied type is provided. func (o *metadataDynamicObject) Set(key string, val sobek.Value) bool { o.state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { diff --git a/js/modules/k6/experimental/streams/goja.go b/js/modules/k6/experimental/streams/goja.go index e9b3a04e75a..c194b6119c0 100644 --- a/js/modules/k6/experimental/streams/goja.go +++ b/js/modules/k6/experimental/streams/goja.go @@ -59,7 +59,7 @@ func promiseThen( return newPromise, nil } -// isNumber returns true if the given goja value holds a number +// isNumber returns true if the given sobek.Value holds a number func isNumber(value sobek.Value) bool { _, isFloat := value.Export().(float64) _, isInt := value.Export().(int64) diff --git a/js/modules/k6/experimental/streams/tests/checkout.sh b/js/modules/k6/experimental/streams/tests/checkout.sh index df42ab66ff5..8d753c457be 100755 --- a/js/modules/k6/experimental/streams/tests/checkout.sh +++ b/js/modules/k6/experimental/streams/tests/checkout.sh @@ -13,7 +13,7 @@ git sparse-checkout set resources streams git fetch origin --depth=1 "${sha}" git checkout ${sha} -# Apply custom patches needed to run the tests in k6/goja +# Apply custom patches needed to run the tests in k6/Sobek for patch in ../*.patch do git apply "$patch" diff --git a/js/modules/k6/grpc/client.go b/js/modules/k6/grpc/client.go index 2ff52484dc6..fdcd80048d0 100644 --- a/js/modules/k6/grpc/client.go +++ b/js/modules/k6/grpc/client.go @@ -385,7 +385,7 @@ func (c *Client) Close() error { return err } -// MethodInfo holds information on any parsed method descriptors that can be used by the goja VM +// MethodInfo holds information on any parsed method descriptors that can be used by the Sobek VM type MethodInfo struct { Package string Service string diff --git a/js/modules/k6/grpc/listeners.go b/js/modules/k6/grpc/listeners.go index c1bd336e42a..00ebb3b63fc 100644 --- a/js/modules/k6/grpc/listeners.go +++ b/js/modules/k6/grpc/listeners.go @@ -26,7 +26,7 @@ type eventListener struct { eventType string // this return sobek.value *and* error in order to return error on exception instead of panic - // https://pkg.go.dev/github.com/dop251/goja#hdr-Functions + // https://pkg.go.dev/github.com/grafana/sobek#hdr-Functions list []func(sobek.Value) (sobek.Value, error) } diff --git a/js/modules/k6/grpc/params_test.go b/js/modules/k6/grpc/params_test.go index 62929a98054..ef0c20c14ca 100644 --- a/js/modules/k6/grpc/params_test.go +++ b/js/modules/k6/grpc/params_test.go @@ -142,7 +142,7 @@ func TestCallParamsTimeOutParse(t *testing.T) { // newParamsTestRuntime creates a new test runtime // that could be used to test the params // it also moves to the VU context and creates the params -// goja value that could be used in the tests +// Sobek value that could be used in the tests func newParamsTestRuntime(t *testing.T, paramsJSON string) (*modulestest.Runtime, sobek.Value) { t.Helper() diff --git a/js/modules/k6/html/html.go b/js/modules/k6/html/html.go index 4630c1db065..8d2c3c2dbc2 100644 --- a/js/modules/k6/html/html.go +++ b/js/modules/k6/html/html.go @@ -79,9 +79,9 @@ func (s Selection) emptySelection() Selection { return s.Eq(s.Size()) } -func (s Selection) buildMatcher(v sobek.Value, gojaFn sobek.Callable) func(int, *goquery.Selection) bool { +func (s Selection) buildMatcher(v sobek.Value, sobekFn sobek.Callable) func(int, *goquery.Selection) bool { return func(idx int, sel *goquery.Selection) bool { - fnRes, fnErr := gojaFn(v, s.rt.ToValue(idx), s.rt.ToValue(sel)) + fnRes, fnErr := sobekFn(v, s.rt.ToValue(idx), s.rt.ToValue(sel)) if fnErr != nil { common.Throw(s.rt, fnErr) } @@ -181,12 +181,12 @@ func (s Selection) Has(arg interface{}) Selection { } func (s Selection) Not(v sobek.Value) Selection { - gojaFn, isFn := sobek.AssertFunction(v) + sobekFn, isFn := sobek.AssertFunction(v) if !isFn { return s.varargFnCall(v, s.sel.Not, s.sel.NotSelection, s.sel.NotNodes) } - return Selection{s.rt, s.sel.NotFunction(s.buildMatcher(v, gojaFn)), s.URL} + return Selection{s.rt, s.sel.NotFunction(s.buildMatcher(v, sobekFn)), s.URL} } func (s Selection) Next(def ...string) Selection { @@ -357,13 +357,13 @@ func (s Selection) Children(def ...string) Selection { } func (s Selection) Each(v sobek.Value) Selection { - gojaFn, isFn := sobek.AssertFunction(v) + sobekFn, isFn := sobek.AssertFunction(v) if !isFn { common.Throw(s.rt, errors.New("the argument to each() must be a function")) } fn := func(idx int, _ *goquery.Selection) { - if _, err := gojaFn(v, s.rt.ToValue(idx), selToElement(Selection{s.rt, s.sel.Eq(idx), s.URL})); err != nil { + if _, err := sobekFn(v, s.rt.ToValue(idx), selToElement(Selection{s.rt, s.sel.Eq(idx), s.URL})); err != nil { common.Throw(s.rt, fmt.Errorf("the function passed to each() failed: %w", err)) } } @@ -380,12 +380,12 @@ func (s Selection) Filter(v sobek.Value) Selection { return Selection{s.rt, s.sel.FilterSelection(val.sel), s.URL} } - gojaFn, isFn := sobek.AssertFunction(v) + sobekFn, isFn := sobek.AssertFunction(v) if !isFn { common.Throw(s.rt, errors.New("the argument to filter() must be a function, a selector or a selection")) } - return Selection{s.rt, s.sel.FilterFunction(s.buildMatcher(v, gojaFn)), s.URL} + return Selection{s.rt, s.sel.FilterFunction(s.buildMatcher(v, sobekFn)), s.URL} } func (s Selection) Is(v sobek.Value) bool { @@ -397,18 +397,18 @@ func (s Selection) Is(v sobek.Value) bool { return s.sel.IsSelection(val.sel) default: - gojaFn, isFn := sobek.AssertFunction(v) + sobekFn, isFn := sobek.AssertFunction(v) if !isFn { common.Throw(s.rt, errors.New("the argument to is() must be a function, a selector or a selection")) } - return s.sel.IsFunction(s.buildMatcher(v, gojaFn)) + return s.sel.IsFunction(s.buildMatcher(v, sobekFn)) } } // Map implements ES5 Array.prototype.map func (s Selection) Map(v sobek.Value) []sobek.Value { - gojaFn, isFn := sobek.AssertFunction(v) + sobekFn, isFn := sobek.AssertFunction(v) if !isFn { common.Throw(s.rt, errors.New("the argument to map() must be a function")) } @@ -417,7 +417,7 @@ func (s Selection) Map(v sobek.Value) []sobek.Value { s.sel.Each(func(idx int, sel *goquery.Selection) { selection := &Selection{sel: sel, URL: s.URL, rt: s.rt} - if fnRes, fnErr := gojaFn(v, s.rt.ToValue(idx), s.rt.ToValue(selection)); fnErr == nil { + if fnRes, fnErr := sobekFn(v, s.rt.ToValue(idx), s.rt.ToValue(selection)); fnErr == nil { values = append(values, fnRes) } }) diff --git a/js/modules/k6/http/cookiejar.go b/js/modules/k6/http/cookiejar.go index 4a68fbb2e87..3c41b4d7ed4 100644 --- a/js/modules/k6/http/cookiejar.go +++ b/js/modules/k6/http/cookiejar.go @@ -20,7 +20,7 @@ var ErrJarForbiddenInInitContext = common.NewInitContextError("Making cookie jar // CookieJar is cookiejar.Jar wrapper to be used in js scripts type CookieJar struct { moduleInstance *ModuleInstance - // js is to make it not be accessible from inside goja/js, the json is + // js is to make it not be accessible from inside Sobek/js, the json is // for when it is returned from setup(). Jar *cookiejar.Jar `js:"-" json:"-"` } diff --git a/js/modules/k6/http/response.go b/js/modules/k6/http/response.go index 38d291c872e..0cc04b51de6 100644 --- a/js/modules/k6/http/response.go +++ b/js/modules/k6/http/response.go @@ -16,7 +16,7 @@ import ( "go.k6.io/k6/lib/netext/httpext" ) -// Response is a representation of an HTTP response to be returned to the goja VM +// Response is a representation of an HTTP response to be returned to the Sobek VM type Response struct { *httpext.Response `js:"-"` client *Client @@ -61,7 +61,7 @@ func (res *Response) HTML(selector ...string) html.Selection { return sel } -// JSON parses the body of a response as JSON and returns it to the goja VM. +// JSON parses the body of a response as JSON and returns it to the Sobek VM. func (res *Response) JSON(selector ...string) sobek.Value { rt := res.client.moduleInstance.vu.Runtime() diff --git a/js/modules/k6/timers/timers.go b/js/modules/k6/timers/timers.go index 0c1879b90ae..a96fe11852a 100644 --- a/js/modules/k6/timers/timers.go +++ b/js/modules/k6/timers/timers.go @@ -64,7 +64,7 @@ func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance { func (e *Timers) Exports() modules.Exports { return modules.Exports{ Named: map[string]interface{}{ - // TODO the usage of `ToValue` here is so that goja doesn't do it automatically later + // TODO the usage of `ToValue` here is so that Sobek doesn't do it automatically later // which will effectively create new instance each time it is accessed. "setTimeout": e.vu.Runtime().ToValue(e.setTimeout), "clearTimeout": e.vu.Runtime().ToValue(e.clearTimeout), diff --git a/js/modules/require_impl.go b/js/modules/require_impl.go index f7236195c03..a641b71c7c8 100644 --- a/js/modules/require_impl.go +++ b/js/modules/require_impl.go @@ -43,7 +43,7 @@ func (r *LegacyRequireImpl) Require(specifier string) (*sobek.Object, error) { // // With native ESM this won't even be possible as `require` might not be called - instead an import // might be used in which case we won't be able to be doing this hack. In that case we either will - // need some goja specific helper or to use stack traces as goja_nodejs does. + // need some Sobek specific helper or to use stack traces. currentPWD := r.currentlyRequiredModule if specifier != "k6" && !strings.HasPrefix(specifier, "k6/") { defer func() { diff --git a/js/promises/promises.go b/js/promises/promises.go index 89cc463a444..0c8e23f4a7d 100644 --- a/js/promises/promises.go +++ b/js/promises/promises.go @@ -8,7 +8,7 @@ import ( // New can be used to create promises that will be dispatched to k6's event loop. // -// Calling the function will create a goja promise and return its `resolve` and `reject` callbacks, wrapped +// Calling the function will create a Sobek promise and return its `resolve` and `reject` callbacks, wrapped // in such a way that it will block the k6 JavaScript runtime's event loop from exiting before they are // called, even if the promise isn't resolved by the time the current script ends executing. // diff --git a/js/runner.go b/js/runner.go index 64c116094b7..29deb508ea1 100644 --- a/js/runner.go +++ b/js/runner.go @@ -566,12 +566,12 @@ func (r *Runner) runPart( } //nolint:gochecknoglobals -var gojaPromiseType = reflect.TypeOf((*sobek.Promise)(nil)) +var sobekPromiseType = reflect.TypeOf((*sobek.Promise)(nil)) // unPromisify gets the result of v if it is a promise, otherwise returns v func unPromisify(v sobek.Value) sobek.Value { if !common.IsNullish(v) { - if v.ExportType() == gojaPromiseType { + if v.ExportType() == sobekPromiseType { p, ok := v.Export().(*sobek.Promise) if !ok { panic("Something that was promise did not export to a promise; this shouldn't happen") @@ -757,7 +757,7 @@ func (u *ActiveVU) RunOnce() error { u.incrIteration() if err := u.Runtime.Set("__ITER", u.iteration); err != nil { - panic(fmt.Errorf("error setting __ITER in goja runtime: %w", err)) + panic(fmt.Errorf("error setting __ITER in Sobek runtime: %w", err)) } ctx, cancel := context.WithCancel(u.RunContext) diff --git a/js/tc39/README.md b/js/tc39/README.md index cc1dbc21979..0a7f1b26d5a 100644 --- a/js/tc39/README.md +++ b/js/tc39/README.md @@ -1,6 +1,6 @@ # Introduction to a k6's TC39 testing -The point of this module is to test k6 goja+babel and k6 goja+esbuild combo against the tc39 test suite. +The point of this module is to test k6 Sobek+babel and k6 Sobek+esbuild combo against the tc39 test suite. Ways to use it: 1. run ./checkout.sh to checkout the last commit sha of [test262](https://github.com/tc39/test262) @@ -8,13 +8,13 @@ Ways to use it: 2. Run `go test &> out.log` The full list of failing tests, and the error, is in `breaking_test_errors-*.json`. All errors list there with the corresponding error will *not* be counted as errors - this is what the test expects, those specific errors. -Due to changes to goja it is not uncommon for the error to change, or there to be now a new error on previously passing test, or (hopefully) a test that was not passing but now is. +Due to changes to soben it is not uncommon for the error to change, or there to be now a new error on previously passing test, or (hopefully) a test that was not passing but now is. In all of those cases `breaking_test_errors-*.json` needs to be updated. Run the test with `-update` flag to update: `go test -update` NOTE: some text editors/IDEs will try to parse files ending in `json` as JSON, which given the size of `breaking_test_errors-*.json` might be a problem when it's not actually a JSON (before the edit). So it might be a better idea to name it something different if editing by hand and fix it later. -This is a modified version of [the code in the goja -repo](https://github.com/dop251/goja/blob/master/tc39_test.go) +This is a modified version of [the code in the original goja +repo](https://github.com/dop251/goja/blob/master/tc39_test.go) that Sobek was forked from. ## Reasons for recording breaking_test_errors.json diff --git a/js/tc39/tc39_test.go b/js/tc39/tc39_test.go index 4f334da9667..140b3ef9ed3 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" @@ -60,7 +60,7 @@ var ( "top-level-await", // not supported at all "String.prototype.replaceAll", // not supported at all, Stage 4 since 2020 - // from goja + // from Sobek "Symbol.asyncIterator", "regexp-named-groups", "regexp-dotall", diff --git a/lib/netext/grpcext/conn.go b/lib/netext/grpcext/conn.go index 89fdcba763f..91a5d51f0d9 100644 --- a/lib/netext/grpcext/conn.go +++ b/lib/netext/grpcext/conn.go @@ -151,7 +151,7 @@ func (c *Conn) Invoke( sterr := status.Convert(err) response.Status = sterr.Code() - // (rogchap) when you access a JSON property in goja, you are actually accessing the underling + // (rogchap) when you access a JSON property in Sobek, you are actually accessing the underling // Go type (struct, map, slice etc); because these are dynamic messages the Unmarshaled JSON does // not map back to a "real" field or value (as a normal Go type would). If we don't marshal and then // unmarshal back to a map, you will get "undefined" when accessing JSON properties, even when diff --git a/lib/netext/httpext/compression.go b/lib/netext/httpext/compression.go index 6716fb4ad5e..2268659efca 100644 --- a/lib/netext/httpext/compression.go +++ b/lib/netext/httpext/compression.go @@ -182,7 +182,7 @@ func readResponseBody( // Copy the data to a new slice before we return the buffer to the pool, // because buf.Bytes() points to the underlying buffer byte slice. // The ArrayBuffer wrapping will be done in the js/modules/k6/http - // package to avoid a reverse dependency, since it depends on goja. + // package to avoid a reverse dependency, since it depends on Sobek. binData := make([]byte, buf.Len()) copy(binData, buf.Bytes()) result = binData diff --git a/lib/runtime_options.go b/lib/runtime_options.go index d7f95b0bebd..cda7ccc7727 100644 --- a/lib/runtime_options.go +++ b/lib/runtime_options.go @@ -15,13 +15,13 @@ type CompatibilityMode uint8 const ( // CompatibilityModeExtended achieves ES6+ compatibility with Babel CompatibilityModeExtended CompatibilityMode = iota + 1 - // CompatibilityModeBase is standard goja ES5.1+ + // CompatibilityModeBase is standard Sobek ES5.1+ CompatibilityModeBase // CompatibilityModeExperimentalEnhanced achieves TypeScript and ES6+ compatibility with esbuild CompatibilityModeExperimentalEnhanced ) -// RuntimeOptions are settings passed onto the goja JS runtime +// RuntimeOptions are settings passed onto the Sobek JS runtime type RuntimeOptions struct { TestType null.String `json:"-"` 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