Skip to content

Commit

Permalink
Goja -> Sobek
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Jun 18, 2024
1 parent 9d05ddf commit fdf906a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions docs/sources/next/extensions/create/javascript-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Our main `Compare` struct should implement the [`modules.Instance`](https://pkg.
to access the [`modules.VU`](https://pkg.go.dev/go.k6.io/k6/js/modules#VU) to inspect internal k6 objects such as:

- [`lib.State`](https://pkg.go.dev/go.k6.io/k6/lib#State), the VU state with values like the VU ID and iteration number
- [`goja.Runtime`](https://pkg.go.dev/github.com/dop251/goja#Runtime), the JavaScript runtime used by the VU
- [`sobek.Runtime`](https://pkg.go.dev/github.com/grafana/sobek#Runtime), the JavaScript runtime used by the VU
- a global `context.Context` containing objects like the [`lib.ExecutionState`](https://pkg.go.dev/go.k6.io/k6/lib#ExecutionState)

Additionally, there should be a root module implementation of the [`modules.Module`](https://pkg.go.dev/go.k6.io/k6/js/modules#Module)
Expand Down Expand Up @@ -276,10 +276,10 @@ runtime state:
```go
// InternalState holds basic metadata from the runtime state.
type InternalState struct {
ActiveVUs int64 `js:"activeVUs"`
ActiveVUs int64 `js:"activeVUs"`
Iteration int64
VUID uint64 `js:"vuID"`
VUIDFromRuntime goja.Value `js:"vuIDFromRuntime"`
VUID uint64 `js:"vuID"`
VUIDFromRuntime sobek.Value `js:"vuIDFromRuntime"`
}

// GetInternalState interrogates the current virtual user for state information.
Expand Down
12 changes: 6 additions & 6 deletions docs/sources/next/extensions/explanations/go-js-bridge.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: About the Go-to-JS bridge
description: Technical details about how JavaScript works in the goja engine.
description: Technical details about how JavaScript works in the sobek engine.
weight: 02
---

# About the Go-to-JS bridge

All k6 and xk6 binaries have an embedded JavaScript engine, [goja](https://github.com/dop251/goja),
All k6 and xk6 binaries have an embedded JavaScript engine, [sobek](https://github.com/grafana/sobek),
which your test scripts run on.

You will deepen your conceptual knowledge of how your k6 extension works if you understand the _bridge_ between Go internals and the JavaScript runtime.
Expand All @@ -28,14 +28,14 @@ The bridge has a few features we should highlight:

The JavaScript runtime transparently converts Go types like `int64` to their JS equivalent.
For complex types where this is impossible, your script might fail with a `TypeError`, requiring you to explicitly convert
your object to a [`goja.Object`](https://pkg.go.dev/github.com/dop251/goja#Object) or [`goja.Value`](https://pkg.go.dev/github.com/dop251/goja#Value).
your object to a [`sobek.Object`](https://pkg.go.dev/github.com/grafana/sobek#Object) or [`sobek.Value`](https://pkg.go.dev/github.com/grafana/sobek#Value).

```go
func (*Compare) XComparator(call goja.ConstructorCall, rt *goja.Runtime) *goja.Object {
func (*Compare) XComparator(call sobek.ConstructorCall, rt *sobek.Runtime) *sobek.Object {
return rt.ToValue(&Compare{}).ToObject(rt)
}
```

The preceding snippet also demonstrates the _native constructors_ feature from goja, where methods can become JS constructors.
The preceding snippet also demonstrates the _native constructors_ feature from sobek, where methods can become JS constructors.
Methods with this signature can create `Comparator` instances in JS with `new compare.Comparator()`.
While this is more idiomatic to JS, it still has the benefit of receiving the `goja.Runtime`.
While this is more idiomatic to JS, it still has the benefit of receiving the `sobek.Runtime`.
6 changes: 3 additions & 3 deletions docs/sources/next/misc/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If a certain term in these docs confuses you, consult this list for a definition
- [Endurance testing](#endurance-testing)
- [Environment variables](#environment-variables)
- [Execution segment](#execution-segment)
- [Goja](#goja)
- [Sobek](#sobek)
- [Graceful stop](#graceful-stop)
- [Happy path](#happy-path)
- [HTTP archive](#http-archive)
Expand Down Expand Up @@ -104,9 +104,9 @@ User-definable values which may be utilized by the operating system and other pr

A partition, or fractional portion, of an overall [test run](#test-run).<br/><br/>[The execution-segment options](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/k6-options/reference#execution-segment)

## Goja
## Sobek

A JavaScript engine written in Go. k6 binaries are embedded with Goja, enabling test scripting in JavaScript.<br/><br/>[Goja repository](https://github.com/dop251/goja)
A JavaScript engine written in Go. k6 binaries are embedded with Sobek, enabling test scripting in JavaScript.<br/><br/>[Sobek repository](https://github.com/grafana/sobek) fork of [goja](https://github.com/dop251/goja).

## Graceful stop

Expand Down
2 changes: 1 addition & 1 deletion docs/sources/next/using-k6/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default function () {
}
```

How do k6 extensions (Go-to-JS modules) work? For enhanced performance, the k6 engine is written in Go and embeds a JavaScript VM ([goja](https://github.com/dop251/goja)) to execute JavaScript test code. That allows you to build your modules in Go code and import them as JavaScript as usual.
How do k6 extensions (Go-to-JS modules) work? For enhanced performance, the k6 engine is written in Go and embeds a JavaScript VM ([sobek](https://github.com/grafana/sobek)) to execute JavaScript test code. That allows you to build your modules in Go code and import them as JavaScript as usual.

To learn more about using or creating k6 extensions, refer to the [Extension documentation](https://grafana.com/docs/k6/<K6_VERSION>/extensions).

Expand Down

0 comments on commit fdf906a

Please sign in to comment.