mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:52:43 +00:00 
			
		
		
		
	 5e1499d104
			
		
	
	
		5e1499d104
		
	
	
	
	
		
			
			This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).
This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
		
	
			
		
			
				
	
	
		
			93 lines
		
	
	
	
		
			3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			93 lines
		
	
	
	
		
			3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibJS/Heap/Heap.h>
 | |
| #include <LibJS/Runtime/Realm.h>
 | |
| #include <LibWeb/Bindings/Intrinsics.h>
 | |
| #include <LibWeb/Bindings/NavigationDestinationPrototype.h>
 | |
| #include <LibWeb/HTML/NavigationDestination.h>
 | |
| #include <LibWeb/HTML/NavigationHistoryEntry.h>
 | |
| 
 | |
| namespace Web::HTML {
 | |
| 
 | |
| JS_DEFINE_ALLOCATOR(NavigationDestination);
 | |
| 
 | |
| JS::NonnullGCPtr<NavigationDestination> NavigationDestination::create(JS::Realm& realm)
 | |
| {
 | |
|     return realm.heap().allocate<NavigationDestination>(realm, realm);
 | |
| }
 | |
| 
 | |
| NavigationDestination::NavigationDestination(JS::Realm& realm)
 | |
|     : Bindings::PlatformObject(realm)
 | |
| {
 | |
| }
 | |
| 
 | |
| NavigationDestination::~NavigationDestination() = default;
 | |
| 
 | |
| void NavigationDestination::initialize(JS::Realm& realm)
 | |
| {
 | |
|     Base::initialize(realm);
 | |
|     set_prototype(&Bindings::ensure_web_prototype<Bindings::NavigationDestinationPrototype>(realm, "NavigationDestination"_fly_string));
 | |
| }
 | |
| 
 | |
| void NavigationDestination::visit_edges(JS::Cell::Visitor& visitor)
 | |
| {
 | |
|     Base::visit_edges(visitor);
 | |
|     visitor.visit(m_entry);
 | |
| }
 | |
| 
 | |
| // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-url
 | |
| WebIDL::ExceptionOr<String> NavigationDestination::url() const
 | |
| {
 | |
|     // The url getter steps are to return this's URL, serialized.
 | |
|     return TRY_OR_THROW_OOM(vm(), String::from_byte_string(m_url.serialize()));
 | |
| }
 | |
| 
 | |
| // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-key
 | |
| String NavigationDestination::key() const
 | |
| {
 | |
|     // The key getter steps are:
 | |
| 
 | |
|     // 1. If this's entry is null, then return the empty string.
 | |
|     // 2. Return this's entry's key.
 | |
|     return (m_entry == nullptr) ? String {} : m_entry->key();
 | |
| }
 | |
| 
 | |
| // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-id
 | |
| String NavigationDestination::id() const
 | |
| {
 | |
|     // The id getter steps are:
 | |
| 
 | |
|     // 1. If this's entry is null, then return the empty string.
 | |
|     // 2. Return this's entry's ID.
 | |
|     return (m_entry == nullptr) ? String {} : m_entry->id();
 | |
| }
 | |
| 
 | |
| // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-index
 | |
| i64 NavigationDestination::index() const
 | |
| {
 | |
|     // The index getter steps are:
 | |
| 
 | |
|     // 1. If this's entry is null, then return -1.
 | |
|     // 2. Return this's entry's index.
 | |
|     return (m_entry == nullptr) ? -1 : m_entry->index();
 | |
| }
 | |
| 
 | |
| // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-samedocument
 | |
| bool NavigationDestination::same_document() const
 | |
| {
 | |
|     // The sameDocument getter steps are to return this's is same document.
 | |
|     return m_is_same_document;
 | |
| }
 | |
| 
 | |
| // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-getstate
 | |
| WebIDL::ExceptionOr<JS::Value> NavigationDestination::get_state()
 | |
| {
 | |
|     // The getState() method steps are to return StructuredDeserialize(this's state).
 | |
|     return structured_deserialize(vm(), m_state, realm(), {});
 | |
| }
 | |
| 
 | |
| }
 |