Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make certain readyState is actually a number when returned #80

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions websockets/websockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ func defineWebsocket(rt *sobek.Runtime, w *webSocket) {
must(rt, w.obj.DefineDataProperty(
"url", rt.ToValue(w.url.String()), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE))
must(rt, w.obj.DefineAccessorProperty( // this needs to be with an accessor as we change the value
"readyState", rt.ToValue(func() ReadyState {
return w.readyState
"readyState", rt.ToValue(func() sobek.Value {
return rt.ToValue((uint)(w.readyState))
}), nil, sobek.FLAG_FALSE, sobek.FLAG_TRUE))
must(rt, w.obj.DefineAccessorProperty(
"bufferedAmount", rt.ToValue(func() sobek.Value { return rt.ToValue(w.bufferedAmount) }), nil,
Expand Down
23 changes: 23 additions & 0 deletions websockets/websockets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1527,3 +1527,26 @@ func testArrayBufferViewSupport(t *testing.T, viewName string) {
logs := hook.Drain()
require.Len(t, logs, 0)
}

func TestReadyStateSwitch(t *testing.T) {
t.Parallel()
ts := newTestState(t)
logger, hook := testutils.NewLoggerWithHook(t, logrus.WarnLevel)
ts.runtime.VU.StateField.Logger = logger
_, err := ts.runtime.RunOnEventLoop(ts.tb.Replacer.Replace(`
var ws = new WebSocket("WSBIN_URL/ws-echo")
try {
switch (ws.readyState) {
case 0:
break;
default:
throw "ws.readyState doesn't get correct value in switch"
}
} finally {
ws.close()
}
`))
require.NoError(t, err)
logs := hook.Drain()
require.Len(t, logs, 0)
}