mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibWeb: Make DOMException GC-allocated
This commit is contained in:
parent
0e47754ac8
commit
497ead37bc
58 changed files with 307 additions and 278 deletions
|
@ -51,11 +51,11 @@ DOM::ExceptionOr<JS::NonnullGCPtr<WebSocket>> WebSocket::create_with_global_obje
|
|||
{
|
||||
AK::URL url_record(url);
|
||||
if (!url_record.is_valid())
|
||||
return DOM::SyntaxError::create("Invalid URL");
|
||||
return DOM::SyntaxError::create(window, "Invalid URL");
|
||||
if (!url_record.protocol().is_one_of("ws", "wss"))
|
||||
return DOM::SyntaxError::create("Invalid protocol");
|
||||
return DOM::SyntaxError::create(window, "Invalid protocol");
|
||||
if (!url_record.fragment().is_empty())
|
||||
return DOM::SyntaxError::create("Presence of URL fragment is invalid");
|
||||
return DOM::SyntaxError::create(window, "Presence of URL fragment is invalid");
|
||||
// 5. If `protocols` is a string, set `protocols` to a sequence consisting of just that string
|
||||
// 6. If any of the values in `protocols` occur more than once or otherwise fail to match the requirements, throw SyntaxError
|
||||
return JS::NonnullGCPtr(*window.heap().allocate<WebSocket>(window.realm(), window.impl(), url_record));
|
||||
|
@ -137,13 +137,13 @@ DOM::ExceptionOr<void> WebSocket::close(Optional<u16> code, Optional<String> rea
|
|||
{
|
||||
// 1. If code is present, but is neither an integer equal to 1000 nor an integer in the range 3000 to 4999, inclusive, throw an "InvalidAccessError" DOMException.
|
||||
if (code.has_value() && *code != 1000 && (*code < 3000 || *code > 4099))
|
||||
return DOM::InvalidAccessError::create("The close error code is invalid");
|
||||
return DOM::InvalidAccessError::create(global_object(), "The close error code is invalid");
|
||||
// 2. If reason is present, then run these substeps:
|
||||
if (reason.has_value()) {
|
||||
// 1. Let reasonBytes be the result of encoding reason.
|
||||
// 2. If reasonBytes is longer than 123 bytes, then throw a "SyntaxError" DOMException.
|
||||
if (reason->bytes().size() > 123)
|
||||
return DOM::SyntaxError::create("The close reason is longer than 123 bytes");
|
||||
return DOM::SyntaxError::create(global_object(), "The close reason is longer than 123 bytes");
|
||||
}
|
||||
// 3. Run the first matching steps from the following list:
|
||||
auto state = ready_state();
|
||||
|
@ -164,7 +164,7 @@ DOM::ExceptionOr<void> WebSocket::send(String const& data)
|
|||
{
|
||||
auto state = ready_state();
|
||||
if (state == WebSocket::ReadyState::Connecting)
|
||||
return DOM::InvalidStateError::create("Websocket is still CONNECTING");
|
||||
return DOM::InvalidStateError::create(global_object(), "Websocket is still CONNECTING");
|
||||
if (state == WebSocket::ReadyState::Open) {
|
||||
m_websocket->send(data);
|
||||
// TODO : If the data cannot be sent, e.g. because it would need to be buffered but the buffer is full, the user agent must flag the WebSocket as full and then close the WebSocket connection.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue