Title: [290995] trunk
Revision
290995
Author
[email protected]
Date
2022-03-08 09:03:09 -0800 (Tue, 08 Mar 2022)

Log Message

WebSocket.send() should synchronously update bufferedAmount
https://bugs.webkit.org/show_bug.cgi?id=235707

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/websockets/Send-binary-65K-arraybuffer.any.worker-expected.txt:
* web-platform-tests/websockets/Send-binary-arraybuffer.any.worker-expected.txt:
* web-platform-tests/websockets/Send-data.any.worker-expected.txt:
* web-platform-tests/websockets/Send-paired-surrogates.any.worker-expected.txt:
* web-platform-tests/websockets/Send-unicode-data.any.worker-expected.txt:
* web-platform-tests/websockets/bufferedAmount-unchanged-by-sync-xhr.any.worker-expected.txt:
* web-platform-tests/websockets/interfaces/WebSocket/close/close-basic-expected.txt:
* web-platform-tests/websockets/interfaces/WebSocket/close/close-connecting-expected.txt:

Source/WebCore:

This matches the behavior of Chrome and Firefox and is covered by web platform tests.

* Modules/websockets/ThreadableWebSocketChannel.h:
* Modules/websockets/WebSocket.cpp:
(WebCore::WebSocket::send):
* Modules/websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::send):
(WebCore::WebSocketChannel::enqueueTextFrame):
* Modules/websockets/WebSocketChannel.h:
* Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
(WebCore::WorkerThreadableWebSocketChannel::send):
(WebCore::WorkerThreadableWebSocketChannel::Peer::send):
(WebCore::WorkerThreadableWebSocketChannel::Bridge::send):
* Modules/websockets/WorkerThreadableWebSocketChannel.h:

Source/WebKit:

* WebProcess/Network/WebSocketChannel.cpp:
(WebKit::WebSocketChannel::send):
* WebProcess/Network/WebSocketChannel.h:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,19 @@
+2022-03-08  Alex Christensen  <[email protected]>
+
+        WebSocket.send() should synchronously update bufferedAmount
+        https://bugs.webkit.org/show_bug.cgi?id=235707
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/websockets/Send-binary-65K-arraybuffer.any.worker-expected.txt:
+        * web-platform-tests/websockets/Send-binary-arraybuffer.any.worker-expected.txt:
+        * web-platform-tests/websockets/Send-data.any.worker-expected.txt:
+        * web-platform-tests/websockets/Send-paired-surrogates.any.worker-expected.txt:
+        * web-platform-tests/websockets/Send-unicode-data.any.worker-expected.txt:
+        * web-platform-tests/websockets/bufferedAmount-unchanged-by-sync-xhr.any.worker-expected.txt:
+        * web-platform-tests/websockets/interfaces/WebSocket/close/close-basic-expected.txt:
+        * web-platform-tests/websockets/interfaces/WebSocket/close/close-connecting-expected.txt:
+
 2022-03-08  Chris Dumez  <[email protected]>
 
         Resync web-platform-tests/beacon from upstream

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL Send 65K data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 65000
+PASS Send 65K data on a WebSocket - Connection should be closed
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed assert_equals: expected 0 but got 65000
+PASS Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any.worker-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any.worker-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any.worker-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed assert_equals: expected 0 but got 65000
+PASS Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL Send binary data on a WebSocket - ArrayBuffer - Connection should be closed assert_equals: expected 0 but got 15
+PASS Send binary data on a WebSocket - ArrayBuffer - Connection should be closed
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any.worker-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any.worker-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any.worker-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL Send binary data on a WebSocket - ArrayBuffer - Connection should be closed assert_equals: expected 0 but got 15
+PASS Send binary data on a WebSocket - ArrayBuffer - Connection should be closed
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL Send data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 15
+PASS Send data on a WebSocket - Connection should be closed
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-data.any.worker-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-data.any.worker-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-data.any.worker-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL Send data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 15
+PASS Send data on a WebSocket - Connection should be closed
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL Send paired surrogates data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 4
+PASS Send paired surrogates data on a WebSocket - Connection should be closed
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any.worker-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any.worker-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any.worker-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL Send paired surrogates data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 4
+PASS Send paired surrogates data on a WebSocket - Connection should be closed
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-unicode-data.any.worker-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-unicode-data.any.worker-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/Send-unicode-data.any.worker-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL Send unicode data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 12
+PASS Send unicode data on a WebSocket - Connection should be closed
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/bufferedAmount-unchanged-by-sync-xhr.any.worker-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/bufferedAmount-unchanged-by-sync-xhr.any.worker-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/bufferedAmount-unchanged-by-sync-xhr.any.worker-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL bufferedAmount should not be updated during a sync XHR assert_equals: expected 5 but got 0
+PASS bufferedAmount should not be updated during a sync XHR
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-arraybuffer-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-arraybuffer-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-arraybuffer-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL WebSockets: bufferedAmount for ArrayBuffer assert_equals: expected 10 but got 0
+PASS WebSockets: bufferedAmount for ArrayBuffer
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-blob-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-blob-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-blob-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL WebSockets: bufferedAmount for blob assert_equals: expected 10 but got 0
+PASS WebSockets: bufferedAmount for blob
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL WebSockets: bufferedAmount after send()ing assert_equals: bufferedAmount after sent "x" expected 1 but got 0
+PASS WebSockets: bufferedAmount after send()ing
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-large-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-large-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-large-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL WebSockets: bufferedAmount for 65K data assert_equals: expected 0 but got 65000
+PASS WebSockets: bufferedAmount for 65K data
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-unicode-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-unicode-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-unicode-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL WebSockets: bufferedAmount for unicode data assert_equals: expected 0 but got 12
+PASS WebSockets: bufferedAmount for unicode data
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/close/close-basic-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/close/close-basic-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/close/close-basic-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL WebSockets: close() assert_equals: expected 2 but got 3
+PASS WebSockets: close()
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/close/close-connecting-expected.txt (290994 => 290995)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/close/close-connecting-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/close/close-connecting-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,3 @@
 
-FAIL WebSockets: close() when connecting assert_equals: expected 2 but got 3
+PASS WebSockets: close() when connecting
 

Deleted: trunk/LayoutTests/platform/ios-14-wk2/http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-14-wk2/http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-14-wk2/http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,53 +0,0 @@
-Web Socket bufferedAmount after closed
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-Connected.
-Closed.
-PASS ws.readyState is 3
-PASS ws.bufferedAmount is 0
-Testing send(string)...
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 27
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 6
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 7
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 131
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 134
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65543
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65550
-Testing send(ArrayBuffer)...
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 6
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 7
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 131
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 134
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65543
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65550
-Testing send(Blob)...
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 6
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 7
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 131
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 134
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65543
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65550
-PASS successfullyParsed is true
-
-TEST COMPLETE
-

Deleted: trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send 65K data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 65000
-

Deleted: trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed assert_equals: expected 0 but got 65000
-

Deleted: trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send binary data on a WebSocket - ArrayBuffer - Connection should be closed assert_equals: expected 0 but got 15
-

Deleted: trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 15
-

Deleted: trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-14-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send paired surrogates data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 4
-

Deleted: trunk/LayoutTests/platform/ios-wk2/http/tests/websocket/tests/hybi/bufferedAmount-after-close-in-busy-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-wk2/http/tests/websocket/tests/hybi/bufferedAmount-after-close-in-busy-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-wk2/http/tests/websocket/tests/hybi/bufferedAmount-after-close-in-busy-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,54 +0,0 @@
-Web Socket bufferedAmount after closed in busy
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-Connected.
-PASS bufferedAmountBeforeClose + closeFrameSize >= bufferedAmountAfterClose is true
-Closed.
-PASS ws.readyState is 3
-PASS ws.bufferedAmount <= bufferedAmountAfterClose is true
-Testing send(string)...
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 27
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 6
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 7
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 131
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 134
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65543
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65550
-Testing send(ArrayBuffer)...
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 6
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 7
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 131
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 134
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65543
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65550
-Testing send(Blob)...
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 6
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 7
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 131
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 134
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65543
-PASS ws.send(messageToSend) is undefined.
-PASS bufferedAmountDifference is 65550
-PASS successfullyParsed is true
-
-TEST COMPLETE
-

Deleted: trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-PASS Send 65K data on a WebSocket - Connection should be closed
-

Deleted: trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-PASS Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed
-

Deleted: trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-PASS Send binary data on a WebSocket - ArrayBuffer - Connection should be closed
-

Deleted: trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-PASS Send data on a WebSocket - Connection should be closed
-

Deleted: trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-PASS Send paired surrogates data on a WebSocket - Connection should be closed
-

Added: trunk/LayoutTests/platform/mac-bigsur/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt (0 => 290995)


--- trunk/LayoutTests/platform/mac-bigsur/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac-bigsur/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -0,0 +1,3 @@
+
+FAIL WebSockets: bufferedAmount after send()ing assert_true: bufferedAmount after received "x" expected true got false
+

Deleted: trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send 65K data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 65000
-

Deleted: trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed assert_equals: expected 0 but got 65000
-

Deleted: trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send binary data on a WebSocket - ArrayBuffer - Connection should be closed assert_equals: expected 0 but got 15
-

Deleted: trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 15
-

Deleted: trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-bigsur-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send paired surrogates data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 4
-

Added: trunk/LayoutTests/platform/mac-catalina/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt (0 => 290995)


--- trunk/LayoutTests/platform/mac-catalina/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac-catalina/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -0,0 +1,3 @@
+
+FAIL WebSockets: bufferedAmount after send()ing assert_true: bufferedAmount after received "x" expected true got false
+

Deleted: trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send 65K data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 65000
-

Deleted: trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed assert_equals: expected 0 but got 65000
-

Deleted: trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send binary data on a WebSocket - ArrayBuffer - Connection should be closed assert_equals: expected 0 but got 15
-

Deleted: trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 15
-

Deleted: trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-catalina-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-FAIL Send paired surrogates data on a WebSocket - Connection should be closed assert_equals: expected 0 but got 4
-

Added: trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt (0 => 290995)


--- trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -0,0 +1,3 @@
+
+FAIL WebSockets: bufferedAmount after send()ing assert_true: bufferedAmount after received "x" expected true got false
+

Deleted: trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-65K-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-PASS Send 65K data on a WebSocket - Connection should be closed
-

Deleted: trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-65K-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-PASS Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed
-

Deleted: trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-binary-arraybuffer.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-PASS Send binary data on a WebSocket - ArrayBuffer - Connection should be closed
-

Deleted: trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-data.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-PASS Send data on a WebSocket - Connection should be closed
-

Deleted: trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt (290994 => 290995)


--- trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/websockets/Send-paired-surrogates.any-expected.txt	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +0,0 @@
-
-PASS Send paired surrogates data on a WebSocket - Connection should be closed
-

Modified: trunk/Source/WebCore/ChangeLog (290994 => 290995)


--- trunk/Source/WebCore/ChangeLog	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/Source/WebCore/ChangeLog	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,3 +1,25 @@
+2022-03-08  Alex Christensen  <[email protected]>
+
+        WebSocket.send() should synchronously update bufferedAmount
+        https://bugs.webkit.org/show_bug.cgi?id=235707
+
+        Reviewed by Chris Dumez.
+
+        This matches the behavior of Chrome and Firefox and is covered by web platform tests.
+
+        * Modules/websockets/ThreadableWebSocketChannel.h:
+        * Modules/websockets/WebSocket.cpp:
+        (WebCore::WebSocket::send):
+        * Modules/websockets/WebSocketChannel.cpp:
+        (WebCore::WebSocketChannel::send):
+        (WebCore::WebSocketChannel::enqueueTextFrame):
+        * Modules/websockets/WebSocketChannel.h:
+        * Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
+        (WebCore::WorkerThreadableWebSocketChannel::send):
+        (WebCore::WorkerThreadableWebSocketChannel::Peer::send):
+        (WebCore::WorkerThreadableWebSocketChannel::Bridge::send):
+        * Modules/websockets/WorkerThreadableWebSocketChannel.h:
+
 2022-03-08  Kate Cheney  <[email protected]>
 
         REGRESSION (r290853): CrashTracer: com.apple.WebKit.WebContent.Development at com.apple.WebCore: WebCore::FrameLoader::clear

Modified: trunk/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.h (290994 => 290995)


--- trunk/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.h	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.h	2022-03-08 17:03:09 UTC (rev 290995)
@@ -72,7 +72,7 @@
     virtual String extensions() = 0; // Will be available after didConnect() callback is invoked.
 
     enum SendResult { SendSuccess, SendFail };
-    virtual SendResult send(const String& message) = 0;
+    virtual SendResult send(CString&&) = 0;
     virtual SendResult send(const JSC::ArrayBuffer&, unsigned byteOffset, unsigned byteLength) = 0;
     virtual SendResult send(Blob&) = 0;
 

Modified: trunk/Source/WebCore/Modules/websockets/WebSocket.cpp (290994 => 290995)


--- trunk/Source/WebCore/Modules/websockets/WebSocket.cpp	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/Source/WebCore/Modules/websockets/WebSocket.cpp	2022-03-08 17:03:09 UTC (rev 290995)
@@ -343,15 +343,18 @@
     LOG(Network, "WebSocket %p send() Sending String '%s'", this, message.utf8().data());
     if (m_state == CONNECTING)
         return Exception { InvalidStateError };
+    auto utf8 = message.utf8(StrictConversionReplacingUnpairedSurrogatesWithFFFD);
     // No exception is raised if the connection was once established but has subsequently been closed.
     if (m_state == CLOSING || m_state == CLOSED) {
-        size_t payloadSize = message.utf8().length();
+        size_t payloadSize = utf8.length();
         m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payloadSize);
         m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFramingOverhead(payloadSize));
         return { };
     }
+    // FIXME: WebSocketChannel also has a m_bufferedAmount. Remove that one. This one is the correct one accessed by JS.
+    m_bufferedAmount = saturateAdd(m_bufferedAmount, utf8.length());
     ASSERT(m_channel);
-    m_channel->send(message);
+    m_channel->send(WTFMove(utf8));
     return { };
 }
 
@@ -366,6 +369,7 @@
         m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFramingOverhead(payloadSize));
         return { };
     }
+    m_bufferedAmount = saturateAdd(m_bufferedAmount, binaryData.byteLength());
     ASSERT(m_channel);
     m_channel->send(binaryData, 0, binaryData.byteLength());
     return { };
@@ -383,6 +387,7 @@
         m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFramingOverhead(payloadSize));
         return { };
     }
+    m_bufferedAmount = saturateAdd(m_bufferedAmount, arrayBufferView.byteLength());
     ASSERT(m_channel);
     m_channel->send(*arrayBufferView.unsharedBuffer(), arrayBufferView.byteOffset(), arrayBufferView.byteLength());
     return { };
@@ -399,6 +404,7 @@
         m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFramingOverhead(payloadSize));
         return { };
     }
+    m_bufferedAmount = saturateAdd(m_bufferedAmount, binaryData.size());
     ASSERT(m_channel);
     m_channel->send(binaryData);
     return { };

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp (290994 => 290995)


--- trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp	2022-03-08 17:03:09 UTC (rev 290995)
@@ -142,14 +142,13 @@
     return extensions;
 }
 
-ThreadableWebSocketChannel::SendResult WebSocketChannel::send(const String& message)
+ThreadableWebSocketChannel::SendResult WebSocketChannel::send(CString&& message)
 {
     if (m_outgoingFrameQueueStatus != OutgoingFrameQueueOpen)
         return ThreadableWebSocketChannel::SendSuccess;
 
-    LOG(Network, "WebSocketChannel %p send() Sending String '%s'", this, message.utf8().data());
-    CString utf8 = message.utf8(StrictConversionReplacingUnpairedSurrogatesWithFFFD);
-    enqueueTextFrame(utf8);
+    LOG(Network, "WebSocketChannel %p send() Sending String '%s'", this, message.data());
+    enqueueTextFrame(WTFMove(message));
     processOutgoingFrameQueue();
     // According to WebSocket API specification, WebSocket.send() should return void instead
     // of boolean. However, our implementation still returns boolean due to compatibility
@@ -719,13 +718,13 @@
     return true;
 }
 
-void WebSocketChannel::enqueueTextFrame(const CString& string)
+void WebSocketChannel::enqueueTextFrame(CString&& string)
 {
     ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen);
     auto frame = makeUnique<QueuedFrame>();
     frame->opCode = WebSocketFrame::OpCodeText;
     frame->frameType = QueuedFrameTypeString;
-    frame->stringData = string;
+    frame->stringData = WTFMove(string);
     m_outgoingFrameQueue.append(WTFMove(frame));
 }
 

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketChannel.h (290994 => 290995)


--- trunk/Source/WebCore/Modules/websockets/WebSocketChannel.h	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketChannel.h	2022-03-08 17:03:09 UTC (rev 290995)
@@ -74,7 +74,7 @@
     ConnectStatus connect(const URL&, const String& protocol) final;
     String subprotocol() final;
     String extensions() final;
-    ThreadableWebSocketChannel::SendResult send(const String& message) final;
+    ThreadableWebSocketChannel::SendResult send(CString&&) final;
     ThreadableWebSocketChannel::SendResult send(const JSC::ArrayBuffer&, unsigned byteOffset, unsigned byteLength) final;
     ThreadableWebSocketChannel::SendResult send(Blob&) final;
     unsigned bufferedAmount() const final;
@@ -167,7 +167,7 @@
         Vector<uint8_t> vectorData;
         RefPtr<Blob> blobData;
     };
-    void enqueueTextFrame(const CString&);
+    void enqueueTextFrame(CString&&);
     void enqueueRawFrame(WebSocketFrame::OpCode, const uint8_t* data, size_t dataLength);
     void enqueueBlobFrame(WebSocketFrame::OpCode, Blob&);
 

Modified: trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp (290994 => 290995)


--- trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp	2022-03-08 17:03:09 UTC (rev 290995)
@@ -84,11 +84,11 @@
     return m_workerClientWrapper->extensions();
 }
 
-ThreadableWebSocketChannel::SendResult WorkerThreadableWebSocketChannel::send(const String& message)
+ThreadableWebSocketChannel::SendResult WorkerThreadableWebSocketChannel::send(CString&& message)
 {
     if (!m_bridge)
         return ThreadableWebSocketChannel::SendFail;
-    return m_bridge->send(message);
+    return m_bridge->send(WTFMove(message));
 }
 
 ThreadableWebSocketChannel::SendResult WorkerThreadableWebSocketChannel::send(const ArrayBuffer& binaryData, unsigned byteOffset, unsigned byteLength)
@@ -168,13 +168,13 @@
     return m_mainWebSocketChannel->connect(url, protocol);
 }
 
-void WorkerThreadableWebSocketChannel::Peer::send(const String& message)
+void WorkerThreadableWebSocketChannel::Peer::send(CString&& message)
 {
     ASSERT(isMainThread());
     if (!m_mainWebSocketChannel)
         return;
 
-    ThreadableWebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel->send(message);
+    ThreadableWebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel->send(WTFMove(message));
     m_loaderProxy.postTaskForModeToWorkerOrWorkletGlobalScope([workerClientWrapper = m_workerClientWrapper, sendRequestResult](ScriptExecutionContext&) mutable {
         workerClientWrapper->setSendRequestResult(sendRequestResult);
     }, m_taskMode);
@@ -424,18 +424,18 @@
     });
 }
 
-ThreadableWebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(const String& message)
+ThreadableWebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(CString&& message)
 {
     if (!m_peer)
         return ThreadableWebSocketChannel::SendFail;
     setMethodNotCompleted();
 
-    m_loaderProxy.postTaskToLoader([peer = m_peer, message = message.isolatedCopy()](ScriptExecutionContext& context) {
+    m_loaderProxy.postTaskToLoader([peer = m_peer, message = WTFMove(message)](ScriptExecutionContext& context) mutable {
         ASSERT(isMainThread());
         ASSERT_UNUSED(context, context.isDocument());
         ASSERT(peer);
 
-        peer->send(message);
+        peer->send(WTFMove(message));
     });
 
     Ref<Bridge> protectedThis(*this);

Modified: trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.h (290994 => 290995)


--- trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.h	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.h	2022-03-08 17:03:09 UTC (rev 290995)
@@ -58,7 +58,7 @@
     ConnectStatus connect(const URL&, const String& protocol) final;
     String subprotocol() final;
     String extensions() final;
-    ThreadableWebSocketChannel::SendResult send(const String& message) final;
+    ThreadableWebSocketChannel::SendResult send(CString&&) final;
     ThreadableWebSocketChannel::SendResult send(const JSC::ArrayBuffer&, unsigned byteOffset, unsigned byteLength) final;
     ThreadableWebSocketChannel::SendResult send(Blob&) final;
     unsigned bufferedAmount() const final;
@@ -77,7 +77,7 @@
         ~Peer();
 
         ConnectStatus connect(const URL&, const String& protocol);
-        void send(const String& message);
+        void send(CString&&);
         void send(const JSC::ArrayBuffer&);
         void send(Blob&);
         void bufferedAmount();
@@ -121,7 +121,7 @@
         ~Bridge();
         void initialize();
         void connect(const URL&, const String& protocol);
-        ThreadableWebSocketChannel::SendResult send(const String& message);
+        ThreadableWebSocketChannel::SendResult send(CString&&);
         ThreadableWebSocketChannel::SendResult send(const JSC::ArrayBuffer&, unsigned byteOffset, unsigned byteLength);
         ThreadableWebSocketChannel::SendResult send(Blob&);
         unsigned bufferedAmount();

Modified: trunk/Source/WebKit/ChangeLog (290994 => 290995)


--- trunk/Source/WebKit/ChangeLog	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/Source/WebKit/ChangeLog	2022-03-08 17:03:09 UTC (rev 290995)
@@ -1,5 +1,16 @@
 2022-03-08  Alex Christensen  <[email protected]>
 
+        WebSocket.send() should synchronously update bufferedAmount
+        https://bugs.webkit.org/show_bug.cgi?id=235707
+
+        Reviewed by Chris Dumez.
+
+        * WebProcess/Network/WebSocketChannel.cpp:
+        (WebKit::WebSocketChannel::send):
+        * WebProcess/Network/WebSocketChannel.h:
+
+2022-03-08  Alex Christensen  <[email protected]>
+
         Remove unneeded Async keywords in messages.in files after r290903
         https://bugs.webkit.org/show_bug.cgi?id=237574
 

Modified: trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.cpp (290994 => 290995)


--- trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.cpp	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.cpp	2022-03-08 17:03:09 UTC (rev 290995)
@@ -159,13 +159,12 @@
     sendWithAsyncReply(WTFMove(message), WTFMove(completionHandler));
 }
 
-WebSocketChannel::SendResult WebSocketChannel::send(const String& message)
+WebSocketChannel::SendResult WebSocketChannel::send(CString&& message)
 {
-    auto utf8 = message.utf8(StrictConversionReplacingUnpairedSurrogatesWithFFFD);
-    if (!increaseBufferedAmount(utf8.length()))
+    if (!increaseBufferedAmount(message.length()))
         return SendFail;
 
-    m_messageQueue.enqueue(WTFMove(utf8));
+    m_messageQueue.enqueue(WTFMove(message));
     return SendSuccess;
 }
 

Modified: trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.h (290994 => 290995)


--- trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.h	2022-03-08 16:56:07 UTC (rev 290994)
+++ trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.h	2022-03-08 17:03:09 UTC (rev 290995)
@@ -65,7 +65,7 @@
     ConnectStatus connect(const URL&, const String& protocol) final;
     String subprotocol() final;
     String extensions() final;
-    SendResult send(const String& message) final;
+    SendResult send(CString&&) final;
     SendResult send(const JSC::ArrayBuffer&, unsigned byteOffset, unsigned byteLength) final;
     SendResult send(WebCore::Blob&) final;
     unsigned bufferedAmount() const final;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to