Explorar el Código

LibWeb/HTML: Make WorkerLocation methods infallible

We stopped worrying about tiny OOMs a while ago.
Sam Atkins hace 7 meses
padre
commit
3ce81512dd
Se han modificado 2 ficheros con 20 adiciones y 27 borrados
  1. 13 20
      Libraries/LibWeb/HTML/WorkerLocation.cpp
  2. 7 7
      Libraries/LibWeb/HTML/WorkerLocation.h

+ 13 - 20
Libraries/LibWeb/HTML/WorkerLocation.cpp

@@ -14,11 +14,10 @@ namespace Web::HTML {
 GC_DEFINE_ALLOCATOR(WorkerLocation);
 
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-href
-WebIDL::ExceptionOr<String> WorkerLocation::href() const
+String WorkerLocation::href() const
 {
-    auto& vm = realm().vm();
     // The href getter steps are to return this's WorkerGlobalScope object's url, serialized.
-    return TRY_OR_THROW_OOM(vm, String::from_byte_string(m_global_scope->url().serialize()));
+    return MUST(String::from_byte_string(m_global_scope->url().serialize()));
 }
 
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-origin
@@ -29,18 +28,15 @@ String WorkerLocation::origin() const
 }
 
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-protocol
-WebIDL::ExceptionOr<String> WorkerLocation::protocol() const
+String WorkerLocation::protocol() const
 {
-    auto& vm = realm().vm();
     // The protocol getter steps are to return this's WorkerGlobalScope object's url's scheme, followed by ":".
-    return TRY_OR_THROW_OOM(vm, String::formatted("{}:", m_global_scope->url().scheme()));
+    return MUST(String::formatted("{}:", m_global_scope->url().scheme()));
 }
 
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-host
-WebIDL::ExceptionOr<String> WorkerLocation::host() const
+String WorkerLocation::host() const
 {
-    auto& vm = realm().vm();
-
     // The host getter steps are:
     // 1. Let url be this's WorkerGlobalScope object's url.
     auto const& url = m_global_scope->url();
@@ -54,11 +50,11 @@ WebIDL::ExceptionOr<String> WorkerLocation::host() const
         return url.serialized_host();
 
     // 4. Return url's host, serialized, followed by ":" and url's port, serialized.
-    return TRY_OR_THROW_OOM(vm, String::formatted("{}:{}", url.serialized_host(), url.port().value()));
+    return MUST(String::formatted("{}:{}", url.serialized_host(), url.port().value()));
 }
 
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-hostname
-WebIDL::ExceptionOr<String> WorkerLocation::hostname() const
+String WorkerLocation::hostname() const
 {
     // The hostname getter steps are:
     // 1. Let host be this's WorkerGlobalScope object's url's host.
@@ -73,7 +69,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::hostname() const
 }
 
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-port
-WebIDL::ExceptionOr<String> WorkerLocation::port() const
+String WorkerLocation::port() const
 {
     // The port getter steps are:
     // 1. Let port be this's WorkerGlobalScope object's url's port.
@@ -82,6 +78,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::port() const
     // 2. If port is null, return the empty string.
     if (!port.has_value())
         return String {};
+
     // 3. Return port, serialized.
     return String::number(port.value());
 }
@@ -94,10 +91,8 @@ String WorkerLocation::pathname() const
 }
 
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-search
-WebIDL::ExceptionOr<String> WorkerLocation::search() const
+String WorkerLocation::search() const
 {
-    auto& vm = realm().vm();
-
     // The search getter steps are:
     // 1. Let query be this's WorkerGlobalScope object's url's query.
     auto const& query = m_global_scope->url().query();
@@ -107,14 +102,12 @@ WebIDL::ExceptionOr<String> WorkerLocation::search() const
         return String {};
 
     // 3. Return "?", followed by query.
-    return TRY_OR_THROW_OOM(vm, String::formatted("?{}", *query));
+    return MUST(String::formatted("?{}", *query));
 }
 
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-hash
-WebIDL::ExceptionOr<String> WorkerLocation::hash() const
+String WorkerLocation::hash() const
 {
-    auto& vm = realm().vm();
-
     // The hash getter steps are:
     // 1. Let fragment be this's WorkerGlobalScope object's url's fragment.
     auto const& fragment = m_global_scope->url().fragment();
@@ -124,7 +117,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::hash() const
         return String {};
 
     // 3. Return "#", followed by fragment.
-    return TRY_OR_THROW_OOM(vm, String::formatted("#{}", *fragment));
+    return MUST(String::formatted("#{}", *fragment));
 }
 
 WorkerLocation::WorkerLocation(WorkerGlobalScope& global_scope)

+ 7 - 7
Libraries/LibWeb/HTML/WorkerLocation.h

@@ -18,15 +18,15 @@ class WorkerLocation : public Bindings::PlatformObject {
 public:
     virtual ~WorkerLocation() override;
 
-    WebIDL::ExceptionOr<String> href() const;
+    String href() const;
     String origin() const;
-    WebIDL::ExceptionOr<String> protocol() const;
-    WebIDL::ExceptionOr<String> host() const;
-    WebIDL::ExceptionOr<String> hostname() const;
-    WebIDL::ExceptionOr<String> port() const;
+    String protocol() const;
+    String host() const;
+    String hostname() const;
+    String port() const;
     String pathname() const;
-    WebIDL::ExceptionOr<String> search() const;
-    WebIDL::ExceptionOr<String> hash() const;
+    String search() const;
+    String hash() const;
 
 private:
     explicit WorkerLocation(WorkerGlobalScope&);